Skip to content

Commit

Permalink
feat(Iterable Node): Add support for EDC and USDC selection (#10908)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joffcom authored Sep 28, 2024
1 parent 0ff0f1a commit 0ca9c07
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
40 changes: 39 additions & 1 deletion packages/nodes-base/credentials/IterableApi.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 IterableApi implements ICredentialType {
name = 'iterableApi';
Expand All @@ -15,5 +20,38 @@ export class IterableApi implements ICredentialType {
typeOptions: { password: true },
default: '',
},
{
displayName: 'Region',
name: 'region',
type: 'options',
options: [
{
name: 'EDC',
value: 'https://api.eu.iterable.com',
},
{
name: 'USDC',
value: 'https://api.iterable.com',
},
],
default: 'https://api.iterable.com',
},
];

authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
Api_Key: '={{$credentials.apiKey}}',
},
},
};

test: ICredentialTestRequest = {
request: {
baseURL: '={{$credentials?.region}}',
url: '/api/webhooks',
method: 'GET',
},
};
}
11 changes: 4 additions & 7 deletions packages/nodes-base/nodes/Iterable/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type {
IDataObject,
IExecuteFunctions,
IHttpRequestMethods,
IHttpRequestOptions,
ILoadOptionsFunctions,
IRequestOptions,
JsonObject,
} from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
Expand All @@ -12,23 +12,21 @@ export async function iterableApiRequest(
this: IExecuteFunctions | ILoadOptionsFunctions,
method: IHttpRequestMethods,
resource: string,

body: any = {},
qs: IDataObject = {},
uri?: string,
headers: IDataObject = {},
): Promise<any> {
const credentials = await this.getCredentials('iterableApi');

const options: IRequestOptions = {
const options: IHttpRequestOptions = {
headers: {
'Content-Type': 'application/json',
Api_Key: credentials.apiKey,
},
method,
body,
qs,
uri: uri || `https://api.iterable.com/api${resource}`,
url: uri || `${credentials.region}/api${resource}`,
json: true,
};
try {
Expand All @@ -38,8 +36,7 @@ export async function iterableApiRequest(
if (Object.keys(body as IDataObject).length === 0) {
delete options.body;
}
//@ts-ignore
return await this.helpers.request.call(this, options);
return await this.helpers.httpRequestWithAuthentication.call(this, 'iterableApi', options);
} catch (error) {
throw new NodeApiError(this.getNode(), error as JsonObject);
}
Expand Down

0 comments on commit 0ca9c07

Please sign in to comment.