Skip to content

Commit

Permalink
feat(Copper Node): Update credential to support HTTP Request node (n8…
Browse files Browse the repository at this point in the history
  • Loading branch information
jvdweerthof authored Jul 3, 2024
1 parent 403e19b commit e6ad5a7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
25 changes: 24 additions & 1 deletion packages/nodes-base/credentials/CopperApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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',
},
};
}
13 changes: 4 additions & 9 deletions packages/nodes-base/nodes/Copper/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
IHookFunctions,
IHttpRequestMethods,
ILoadOptionsFunctions,
IRequestOptions,
IHttpRequestOptions,
IWebhookFunctions,
JsonObject,
} from 'n8n-workflow';
Expand Down Expand Up @@ -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,
};

Expand All @@ -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);
}
Expand Down

0 comments on commit e6ad5a7

Please sign in to comment.