From 0c759dc548c058372fde5d117ea34489f7a6a2d9 Mon Sep 17 00:00:00 2001 From: Bram Kn Date: Thu, 1 Dec 2022 18:42:33 +0100 Subject: [PATCH] feat(Postmark Trigger Node): Update credentials so they can be used with the HTTP Request Node (#4790) --- .../credentials/PostmarkApi.credentials.ts | 22 ++++++++++++++++++- .../nodes/Postmark/GenericFunctions.ts | 5 +---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/nodes-base/credentials/PostmarkApi.credentials.ts b/packages/nodes-base/credentials/PostmarkApi.credentials.ts index 4becf59f31..aaf969fa67 100644 --- a/packages/nodes-base/credentials/PostmarkApi.credentials.ts +++ b/packages/nodes-base/credentials/PostmarkApi.credentials.ts @@ -1,4 +1,9 @@ -import { ICredentialType, INodeProperties } from 'n8n-workflow'; +import { + IAuthenticateGeneric, + ICredentialTestRequest, + ICredentialType, + INodeProperties, +} from 'n8n-workflow'; export class PostmarkApi implements ICredentialType { name = 'postmarkApi'; @@ -12,4 +17,19 @@ export class PostmarkApi implements ICredentialType { default: '', }, ]; + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + headers: { + 'X-Postmark-Server-Token': '={{$credentials.serverToken}}', + }, + }, + }; + test: ICredentialTestRequest = { + request: { + baseURL: 'https://api.postmarkapp.com', + url: '/server', + method: 'GET', + }, + }; } diff --git a/packages/nodes-base/nodes/Postmark/GenericFunctions.ts b/packages/nodes-base/nodes/Postmark/GenericFunctions.ts index a243ef4d27..a45ceeb979 100644 --- a/packages/nodes-base/nodes/Postmark/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Postmark/GenericFunctions.ts @@ -13,13 +13,10 @@ export async function postmarkApiRequest( option: IDataObject = {}, // tslint:disable-next-line:no-any ): Promise { - const credentials = await this.getCredentials('postmarkApi'); - let options: OptionsWithUri = { headers: { 'Content-Type': 'application/json', Accept: 'application/json', - 'X-Postmark-Server-Token': credentials.serverToken, }, method, body, @@ -32,7 +29,7 @@ export async function postmarkApiRequest( options = Object.assign({}, options, option); try { - return await this.helpers.request!(options); + return await this.helpers.requestWithAuthentication.call(this, 'postmarkApi', options); } catch (error) { throw new NodeApiError(this.getNode(), error); }