2023-01-27 03:22:44 -08:00
|
|
|
import type {
|
2022-11-09 02:26:13 -08:00
|
|
|
ICredentialDataDecryptedObject,
|
2022-07-10 03:32:19 -07:00
|
|
|
ICredentialTestRequest,
|
2021-05-20 14:31:23 -07:00
|
|
|
ICredentialType,
|
2022-11-09 02:26:13 -08:00
|
|
|
IHttpRequestOptions,
|
2021-06-12 09:39:55 -07:00
|
|
|
INodeProperties,
|
2021-05-20 14:31:23 -07:00
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
export class NotionApi implements ICredentialType {
|
|
|
|
name = 'notionApi';
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2021-05-20 14:31:23 -07:00
|
|
|
displayName = 'Notion API';
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2021-05-20 14:31:23 -07:00
|
|
|
documentationUrl = 'notion';
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2021-06-12 09:39:55 -07:00
|
|
|
properties: INodeProperties[] = [
|
2021-05-20 14:31:23 -07:00
|
|
|
{
|
|
|
|
displayName: 'API Key',
|
|
|
|
name: 'apiKey',
|
2021-06-12 09:39:55 -07:00
|
|
|
type: 'string',
|
2022-11-01 09:41:45 -07:00
|
|
|
typeOptions: { password: true },
|
2021-05-20 14:31:23 -07:00
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
];
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2022-07-10 03:32:19 -07:00
|
|
|
test: ICredentialTestRequest = {
|
|
|
|
request: {
|
|
|
|
baseURL: 'https://api.notion.com/v1',
|
|
|
|
url: '/users',
|
|
|
|
},
|
|
|
|
};
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2022-11-09 02:26:13 -08:00
|
|
|
async authenticate(
|
|
|
|
credentials: ICredentialDataDecryptedObject,
|
|
|
|
requestOptions: IHttpRequestOptions,
|
|
|
|
): Promise<IHttpRequestOptions> {
|
|
|
|
requestOptions.headers = {
|
|
|
|
...requestOptions.headers,
|
|
|
|
Authorization: `Bearer ${credentials.apiKey} `,
|
|
|
|
};
|
|
|
|
|
|
|
|
// if version it's not set, set it to last one
|
|
|
|
// version is only set when the request is made from
|
|
|
|
// the notion node, or was set explicitly in the http node
|
|
|
|
if (!requestOptions.headers['Notion-Version']) {
|
|
|
|
requestOptions.headers = {
|
|
|
|
...requestOptions.headers,
|
|
|
|
'Notion-Version': '2022-02-22',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return requestOptions;
|
|
|
|
}
|
2021-05-20 14:31:23 -07:00
|
|
|
}
|