mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-16 09:34:07 -08:00
d7459a7145
⚡ fix
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
import {
|
|
ICredentialDataDecryptedObject,
|
|
ICredentialTestRequest,
|
|
ICredentialType,
|
|
IHttpRequestOptions,
|
|
INodeProperties,
|
|
} from 'n8n-workflow';
|
|
|
|
export class NotionApi implements ICredentialType {
|
|
name = 'notionApi';
|
|
displayName = 'Notion API';
|
|
documentationUrl = 'notion';
|
|
properties: INodeProperties[] = [
|
|
{
|
|
displayName: 'API Key',
|
|
name: 'apiKey',
|
|
type: 'string',
|
|
typeOptions: { password: true },
|
|
default: '',
|
|
},
|
|
];
|
|
test: ICredentialTestRequest = {
|
|
request: {
|
|
baseURL: 'https://api.notion.com/v1',
|
|
url: '/users',
|
|
},
|
|
};
|
|
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;
|
|
}
|
|
}
|