feat(Postmark Trigger Node): Update credentials so they can be used with the HTTP Request Node (#4790)

This commit is contained in:
Bram Kn 2022-12-01 18:42:33 +01:00 committed by GitHub
parent 23aa0353b6
commit 0c759dc548
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 5 deletions

View file

@ -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',
},
};
}

View file

@ -13,13 +13,10 @@ export async function postmarkApiRequest(
option: IDataObject = {},
// tslint:disable-next-line:no-any
): Promise<any> {
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);
}