mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 06:34:05 -08:00
feat(Copper Node): Update credential to support HTTP Request node (#9837)
This commit is contained in:
parent
403e19b3e3
commit
e6ad5a7193
|
@ -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 {
|
export class CopperApi implements ICredentialType {
|
||||||
name = 'copperApi';
|
name = 'copperApi';
|
||||||
|
@ -25,4 +30,22 @@ export class CopperApi implements ICredentialType {
|
||||||
default: '',
|
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',
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import type {
|
||||||
IHookFunctions,
|
IHookFunctions,
|
||||||
IHttpRequestMethods,
|
IHttpRequestMethods,
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
IRequestOptions,
|
IHttpRequestOptions,
|
||||||
IWebhookFunctions,
|
IWebhookFunctions,
|
||||||
JsonObject,
|
JsonObject,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
@ -35,19 +35,14 @@ export async function copperApiRequest(
|
||||||
uri = '',
|
uri = '',
|
||||||
option: IDataObject = {},
|
option: IDataObject = {},
|
||||||
) {
|
) {
|
||||||
const credentials = (await this.getCredentials('copperApi')) as { apiKey: string; email: string };
|
let options: IHttpRequestOptions = {
|
||||||
|
|
||||||
let options: IRequestOptions = {
|
|
||||||
headers: {
|
headers: {
|
||||||
'X-PW-AccessToken': credentials.apiKey,
|
|
||||||
'X-PW-Application': 'developer_api',
|
|
||||||
'X-PW-UserEmail': credentials.email,
|
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
method,
|
method,
|
||||||
qs,
|
qs,
|
||||||
body,
|
body,
|
||||||
uri: uri || `https://api.prosperworks.com/developer_api/v1${resource}`,
|
url: uri || `https://api.copper.com/developer_api/v1${resource}`,
|
||||||
json: true,
|
json: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -62,7 +57,7 @@ export async function copperApiRequest(
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await this.helpers.request(options);
|
return await this.helpers.requestWithAuthentication.call(this, 'copperApi', options);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue