mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
feat(Customer.io Node): Add support for tracking API region selection (#3378)
* support for customer.io tracking api endpoint region selection If your account is based in our EU region use the EU endpoints (track-eu.customer.io) for US (other than EU) tracking endpoints (track.customer.io). * Changed name to keep constistency with other nodes * Switched to credentials injection * Add throwing error when unknow way of authenticating * Fixed url for http request * Add hint to region field about being omited with http node * Fix bug for credentials working with http node * Improve IF by deduplicating code Co-authored-by: h4ux <alon@h4ux.com> Co-authored-by: Omar Ajoue <krynble@gmail.com>
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
||||
} from 'request';
|
||||
|
||||
import {
|
||||
IDataObject, NodeApiError, NodeOperationError,
|
||||
IDataObject, IHttpRequestMethods, IHttpRequestOptions, NodeApiError, NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
@@ -18,34 +18,28 @@ import {
|
||||
|
||||
export async function customerIoApiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: object, baseApi?: string, query?: IDataObject): Promise<any> { // tslint:disable-line:no-any
|
||||
const credentials = await this.getCredentials('customerIoApi');
|
||||
|
||||
query = query || {};
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
const options: IHttpRequestOptions = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method,
|
||||
method: method as IHttpRequestMethods,
|
||||
body,
|
||||
uri: '',
|
||||
url: '',
|
||||
json: true,
|
||||
};
|
||||
|
||||
if (baseApi === 'tracking') {
|
||||
options.uri = `https://track.customer.io/api/v1${endpoint}`;
|
||||
const basicAuthKey = Buffer.from(`${credentials.trackingSiteId}:${credentials.trackingApiKey}`).toString('base64');
|
||||
Object.assign(options.headers, { 'Authorization': `Basic ${basicAuthKey}` });
|
||||
const region = credentials.region;
|
||||
options.url = `https://${region}/api/v1${endpoint}`;
|
||||
} else if (baseApi === 'api') {
|
||||
options.uri = `https://api.customer.io/v1/api${endpoint}`;
|
||||
const basicAuthKey = Buffer.from(`${credentials.trackingSiteId}:${credentials.trackingApiKey}`).toString('base64');
|
||||
Object.assign(options.headers, { 'Authorization': `Basic ${basicAuthKey}` });
|
||||
options.url = `https://api.customer.io/v1/api${endpoint}`;
|
||||
} else if (baseApi === 'beta') {
|
||||
options.uri = `https://beta-api.customer.io/v1/api${endpoint}`;
|
||||
Object.assign(options.headers, { 'Authorization': `Bearer ${credentials.appApiKey as string}` });
|
||||
options.url = `https://beta-api.customer.io/v1/api${endpoint}`;
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.helpers.request!(options);
|
||||
return await this.helpers.requestWithAuthentication.call(this, 'customerIoApi' ,options );
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user