From e6ad5a71935a5f82168bf300246ccb3535648b0b Mon Sep 17 00:00:00 2001 From: Jochem Date: Wed, 3 Jul 2024 09:59:44 +0200 Subject: [PATCH] feat(Copper Node): Update credential to support HTTP Request node (#9837) --- .../credentials/CopperApi.credentials.ts | 25 ++++++++++++++++++- .../nodes/Copper/GenericFunctions.ts | 13 +++------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/packages/nodes-base/credentials/CopperApi.credentials.ts b/packages/nodes-base/credentials/CopperApi.credentials.ts index e08af72169b09..1cfe5aa1709b6 100644 --- a/packages/nodes-base/credentials/CopperApi.credentials.ts +++ b/packages/nodes-base/credentials/CopperApi.credentials.ts @@ -1,4 +1,9 @@ -import type { ICredentialType, INodeProperties } from 'n8n-workflow'; +import type { + IAuthenticateGeneric, + ICredentialTestRequest, + ICredentialType, + INodeProperties, +} from 'n8n-workflow'; export class CopperApi implements ICredentialType { name = 'copperApi'; @@ -25,4 +30,22 @@ export class CopperApi implements ICredentialType { default: '', }, ]; + + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + headers: { + 'X-PW-AccessToken': '={{$credentials.apiKey}}', + 'X-PW-Application': 'developer_api', + 'X-PW-UserEmail': '={{$credentials.email}}', + }, + }, + }; + + test: ICredentialTestRequest = { + request: { + baseURL: 'https://api.copper.com/developer_api/v1/', + url: 'users/me', + }, + }; } diff --git a/packages/nodes-base/nodes/Copper/GenericFunctions.ts b/packages/nodes-base/nodes/Copper/GenericFunctions.ts index 2ffd1ca7cf675..3137471c2e3e3 100644 --- a/packages/nodes-base/nodes/Copper/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Copper/GenericFunctions.ts @@ -7,7 +7,7 @@ import type { IHookFunctions, IHttpRequestMethods, ILoadOptionsFunctions, - IRequestOptions, + IHttpRequestOptions, IWebhookFunctions, JsonObject, } from 'n8n-workflow'; @@ -35,19 +35,14 @@ export async function copperApiRequest( uri = '', option: IDataObject = {}, ) { - const credentials = (await this.getCredentials('copperApi')) as { apiKey: string; email: string }; - - let options: IRequestOptions = { + let options: IHttpRequestOptions = { headers: { - 'X-PW-AccessToken': credentials.apiKey, - 'X-PW-Application': 'developer_api', - 'X-PW-UserEmail': credentials.email, 'Content-Type': 'application/json', }, method, qs, body, - uri: uri || `https://api.prosperworks.com/developer_api/v1${resource}`, + url: uri || `https://api.copper.com/developer_api/v1${resource}`, json: true, }; @@ -62,7 +57,7 @@ export async function copperApiRequest( } try { - return await this.helpers.request(options); + return await this.helpers.requestWithAuthentication.call(this, 'copperApi', options); } catch (error) { throw new NodeApiError(this.getNode(), error as JsonObject); }