2019-08-20 23:45:03 -07:00
|
|
|
import {
|
|
|
|
IExecuteFunctions,
|
|
|
|
IHookFunctions,
|
|
|
|
} from 'n8n-core';
|
|
|
|
|
|
|
|
import {
|
2021-04-16 09:33:36 -07:00
|
|
|
IDataObject, ILoadOptionsFunctions, INodeProperties, NodeApiError, NodeOperationError,
|
2019-08-20 23:45:03 -07:00
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
import { OptionsWithUri } from 'request';
|
|
|
|
|
2019-11-02 15:11:55 -07:00
|
|
|
export interface IProduct {
|
|
|
|
fields: {
|
|
|
|
item?: object[];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-08-20 23:45:03 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Make an API request to ActiveCampaign
|
|
|
|
*
|
|
|
|
* @param {IHookFunctions} this
|
|
|
|
* @param {string} method
|
|
|
|
* @param {string} url
|
|
|
|
* @param {object} body
|
|
|
|
* @returns {Promise<any>}
|
|
|
|
*/
|
2020-01-14 08:13:17 -08:00
|
|
|
export async function activeCampaignApiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: IDataObject, query?: IDataObject, dataKey?: string): Promise<any> { // tslint:disable-line:no-any
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('activeCampaignApi');
|
2019-08-20 23:45:03 -07:00
|
|
|
|
|
|
|
if (query === undefined) {
|
|
|
|
query = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
const options: OptionsWithUri = {
|
2019-09-11 12:56:45 -07:00
|
|
|
headers: {
|
|
|
|
},
|
2019-08-20 23:45:03 -07:00
|
|
|
method,
|
|
|
|
qs: query,
|
|
|
|
uri: `${credentials.apiUrl}${endpoint}`,
|
2020-10-22 06:46:03 -07:00
|
|
|
json: true,
|
2019-08-20 23:45:03 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
if (Object.keys(body).length !== 0) {
|
2019-09-11 12:56:45 -07:00
|
|
|
options.body = body;
|
2019-08-20 23:45:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
feat: Add more credentials tests (#3668)
* ✨ Add injection to notion,
Add test to notion in cred
* 🔥 Remove unuse method
* 🎨 Move testing from node file to cred file
* ✨ Add injection and testing in facebook graph
* Add cred injec with testing
* Add Cred injection and cred test
* Add cred injection, and cred testing for typeform, fix issue in clickup
* Add cred injection, move testing inside creds
* Add cred injection and cred testing to SendGrid
* Add cred injection and cred testing to woocommerce
* Add cred injection, add cred test to gitlab
* 🔥 Fix duplicated imports in Mautic cred
* 🔥 removed unused credentials testing in node
* Add cred injection, cred testing, handles slash trailing for Grafana node
* Add cred injection, cred testing to shopify
* Add cred injection , add cred testing to stripe
* changed cred injection, add testing to cred for mattermost
* add cred injection and testing for dropbox
* Add cred injection, cred testing to webflow
* ✨ Add cred injection and cred test to nocodb
* ✨ Add cred injection, cred testing to mailchimp
* 🐛 fix a bug In credentials testing
* ✨ Add cred injection, cred testing to sms77
* ✨ Add cred injection, cred testing to ActiveCampaign
* Add cred injection, cred testing to TheHive
* ✨ Add cred injection, add cred testing to ApiTemplateio
* ✨ Add cred injection, add cred testing for zoom
* ✨ Add cred injection, cred testing to rocketchat
* ✨ Add cred injection, add cred test to getResponse
* 🔥 Remove useless authentcate creds and testing from facebookGraphApp
* 🔥 Remove useless imports in FacebookGrappApp credentials file
* 🔥 Removed useless imports and if statement
* 🐛 Add version to header when testing cred
Co-authored-by: Omar Ajoue <krynble@gmail.com>
Co-authored-by: Jan Oberhauser <janober@users.noreply.github.com>
2022-07-15 07:20:41 -07:00
|
|
|
const responseData = await this.helpers.requestWithAuthentication.call(this, 'activeCampaignApi',options);
|
2019-08-20 23:45:03 -07:00
|
|
|
|
2019-09-11 12:56:45 -07:00
|
|
|
if (responseData.success === false) {
|
2021-04-16 09:33:36 -07:00
|
|
|
throw new NodeApiError(this.getNode(), responseData);
|
2019-08-20 23:45:03 -07:00
|
|
|
}
|
|
|
|
|
2019-09-11 12:56:45 -07:00
|
|
|
if (dataKey === undefined) {
|
2019-08-20 23:45:03 -07:00
|
|
|
return responseData;
|
2019-09-11 12:56:45 -07:00
|
|
|
} else {
|
|
|
|
return responseData[dataKey] as IDataObject;
|
2019-08-20 23:45:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} catch (error) {
|
2021-04-16 09:33:36 -07:00
|
|
|
throw new NodeApiError(this.getNode(), error);
|
2019-08-20 23:45:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make an API request to paginated ActiveCampaign endpoint
|
|
|
|
* and return all results
|
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {(IHookFunctions | IExecuteFunctions)} this
|
|
|
|
* @param {string} method
|
|
|
|
* @param {string} endpoint
|
|
|
|
* @param {IDataObject} body
|
|
|
|
* @param {IDataObject} [query]
|
|
|
|
* @returns {Promise<any>}
|
|
|
|
*/
|
2020-01-14 08:13:17 -08:00
|
|
|
export async function activeCampaignApiRequestAllItems(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: IDataObject, query?: IDataObject, dataKey?: string): Promise<any> { // tslint:disable-line:no-any
|
2019-08-20 23:45:03 -07:00
|
|
|
|
|
|
|
if (query === undefined) {
|
|
|
|
query = {};
|
|
|
|
}
|
|
|
|
query.limit = 100;
|
|
|
|
query.offset = 0;
|
|
|
|
|
|
|
|
const returnData: IDataObject[] = [];
|
|
|
|
|
|
|
|
let responseData;
|
|
|
|
|
|
|
|
let itemsReceived = 0;
|
|
|
|
do {
|
2019-09-11 12:56:45 -07:00
|
|
|
responseData = await activeCampaignApiRequest.call(this, method, endpoint, body, query);
|
|
|
|
|
|
|
|
if (dataKey === undefined) {
|
|
|
|
returnData.push.apply(returnData, responseData);
|
2019-11-03 12:49:49 -08:00
|
|
|
if (returnData !== undefined) {
|
2019-11-03 08:58:46 -08:00
|
|
|
itemsReceived += returnData.length;
|
|
|
|
}
|
2019-09-11 12:56:45 -07:00
|
|
|
} else {
|
|
|
|
returnData.push.apply(returnData, responseData[dataKey]);
|
2019-11-03 12:49:49 -08:00
|
|
|
if (responseData[dataKey] !== undefined) {
|
2019-11-03 08:58:46 -08:00
|
|
|
itemsReceived += responseData[dataKey].length;
|
|
|
|
}
|
2019-09-11 12:56:45 -07:00
|
|
|
}
|
2019-08-20 23:45:03 -07:00
|
|
|
|
|
|
|
query.offset = itemsReceived;
|
|
|
|
} while (
|
|
|
|
responseData.meta !== undefined &&
|
|
|
|
responseData.meta.total !== undefined &&
|
|
|
|
responseData.meta.total > itemsReceived
|
|
|
|
);
|
|
|
|
|
|
|
|
return returnData;
|
|
|
|
}
|
2020-09-18 00:42:01 -07:00
|
|
|
|
2020-09-18 00:42:46 -07:00
|
|
|
export function activeCampaignDefaultGetAllProperties(resource: string, operation: string): INodeProperties[] {
|
2020-09-18 00:42:01 -07:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
displayName: 'Return All',
|
2020-09-18 00:42:46 -07:00
|
|
|
name: 'returnAll',
|
2020-09-18 00:42:01 -07:00
|
|
|
type: 'boolean',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
operation: [
|
|
|
|
operation,
|
|
|
|
],
|
|
|
|
resource: [
|
|
|
|
resource,
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
default: false,
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'Whether to return all results or only up to a given limit',
|
2020-09-18 00:42:01 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Limit',
|
2020-09-18 00:42:46 -07:00
|
|
|
name: 'limit',
|
2020-09-18 00:42:01 -07:00
|
|
|
type: 'number',
|
|
|
|
displayOptions: {
|
2020-09-18 00:42:46 -07:00
|
|
|
show: {
|
|
|
|
operation: [
|
|
|
|
operation,
|
|
|
|
],
|
|
|
|
resource: [
|
|
|
|
resource,
|
|
|
|
],
|
|
|
|
returnAll: [
|
|
|
|
false,
|
|
|
|
],
|
|
|
|
},
|
2020-09-18 00:42:01 -07:00
|
|
|
},
|
2020-09-18 00:42:46 -07:00
|
|
|
typeOptions: {
|
|
|
|
minValue: 1,
|
|
|
|
maxValue: 500,
|
|
|
|
},
|
|
|
|
default: 100,
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'Max number of results to return',
|
2020-09-18 00:42:01 -07:00
|
|
|
},
|
|
|
|
{
|
2022-05-20 14:47:24 -07:00
|
|
|
displayName: 'Simplify',
|
2020-09-18 00:42:01 -07:00
|
|
|
name: 'simple',
|
|
|
|
type: 'boolean',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
operation: [
|
|
|
|
operation,
|
|
|
|
],
|
|
|
|
resource: [
|
|
|
|
resource,
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
default: true,
|
2022-05-20 14:47:24 -07:00
|
|
|
description: 'Whether to return a simplified version of the response instead of the raw data',
|
2020-09-18 00:42:01 -07:00
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|