mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
⚡ Mailchimp improvements
This commit is contained in:
@@ -1,13 +1,19 @@
|
|||||||
import { OptionsWithUri } from 'request';
|
import {
|
||||||
|
OptionsWithUri,
|
||||||
|
} from 'request';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
|
IExecuteSingleFunctions,
|
||||||
IHookFunctions,
|
IHookFunctions,
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
IExecuteSingleFunctions
|
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
|
|
||||||
export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, endpoint: string, method: string, body: any = {}, headers?: object): Promise<any> { // tslint:disable-line:no-any
|
import {
|
||||||
|
IDataObject,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, endpoint: string, method: string, body: any = {}, qs: IDataObject = {} ,headers?: object): Promise<any> { // tslint:disable-line:no-any
|
||||||
const credentials = this.getCredentials('mailchimpApi');
|
const credentials = this.getCredentials('mailchimpApi');
|
||||||
|
|
||||||
if (credentials === undefined) {
|
if (credentials === undefined) {
|
||||||
@@ -27,6 +33,7 @@ export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctio
|
|||||||
const options: OptionsWithUri = {
|
const options: OptionsWithUri = {
|
||||||
headers: headerWithAuthentication,
|
headers: headerWithAuthentication,
|
||||||
method,
|
method,
|
||||||
|
qs,
|
||||||
uri: `https://${datacenter}.${host}${endpoint}`,
|
uri: `https://${datacenter}.${host}${endpoint}`,
|
||||||
json: true,
|
json: true,
|
||||||
};
|
};
|
||||||
@@ -34,17 +41,34 @@ export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctio
|
|||||||
if (Object.keys(body).length !== 0) {
|
if (Object.keys(body).length !== 0) {
|
||||||
options.body = body;
|
options.body = body;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await this.helpers.request!(options);
|
return await this.helpers.request!(options);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMessage = error.response.body.message || error.response.body.Message;
|
if (error.response.body && error.response.body.detail) {
|
||||||
|
throw new Error(`Mailchimp Error: response [${error.statusCode}]: ${error.response.body.detail}`);
|
||||||
|
}
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (errorMessage !== undefined) {
|
export async function mailchimpApiRequestAllItems(this: IExecuteFunctions | ILoadOptionsFunctions, endpoint: string, method: string, propertyName: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||||
throw errorMessage;
|
|
||||||
}
|
const returnData: IDataObject[] = [];
|
||||||
throw error.response.body;
|
|
||||||
}
|
let responseData;
|
||||||
|
|
||||||
|
query.offset = 0;
|
||||||
|
query.count = 500;
|
||||||
|
|
||||||
|
do {
|
||||||
|
responseData = await mailchimpApiRequest.call(this, endpoint, method, body, query);
|
||||||
|
returnData.push.apply(returnData, responseData[propertyName]);
|
||||||
|
query.offset += query.count;
|
||||||
|
} while (
|
||||||
|
responseData[propertyName] && responseData[propertyName].length !== 0
|
||||||
|
);
|
||||||
|
|
||||||
|
return returnData;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any
|
export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user