mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
⚡ Add full continue-on-fail support to all nodes (#1996)
* Update Compression node * Update Crypto node * Update DateTime node * Update EditImage node * Update EmailSend node * Update ExecuteWorkflow node * Update FTP node * Update Function node * Update FunctionItem node * Update ExecuteCommand node * Update OpenWeatherMap node * Update ReadBinaryFile node * Update ReadPdf node * Update RssFeedRead node & add URL validation * Update SpreadsheetFile node * Update Switch node * Update WriteBinaryFile node * Update Xml node * Update ActiveCampaign node * Update Airtable node * Update ApiTemplateIo node * Update Asana node * Update AwsLambda node * Update AwsSns node * Update AwsComprehend node * Update AwsRekognition node * Update AwsS3 node * Fix Error item * Update AwsSes node * Update AwsSqs node * Update Amqp node * Update Bitly node * Update Box node * Update Brandfetch node * Update CircleCi node * Update Clearbit node * Update ClickUp node * Update Cockpit node * Update CoinGecko node * Update Contentful node * Update ConvertKit node * Update Cortex node * Update CustomerIo node * Update DeepL node * Update Demio node * Update Disqus node * Update Drift node * Update Dropbox node * Update GetResponse node * Refactor & Update Ghost node * Update Github node * Update Gitlab node * Update GoogleAnalytics node * Update GoogleBooks node * Update GoogleCalendar node * Update GoogleDrive node * Update Gmail node * Update GoogleSheets node * Update GoogleSlides node * Update GoogleTasks node * Update Gotify node * Update GraphQL node * Update HackerNews node * Update Harvest node * Update HtmlExtract node * Update Hubspot node * Update Hunter node * Update Intercom node * Update Kafka node * Refactor & update Line node * Update LinkedIn node * Update Mailchimp node * Update Mandrill node * Update Matrix node * Update Mautic node * Update Medium node * Update MessageBird node * Update Mindee node * Update Mocean node * Update MondayCom node * Update MicrosoftExcel node * Update MicrosoftOneDrive node * Update MicrosoftOutlook node * Update Affinity node * Update Chargebee node * Update Discourse node * Update Freshdesk node * Update YouTube node * Update InvoiceNinja node * Update MailerLite node * Update Mailgun node * Update Mailjet node * Update Mattermost node * Update Nasa node * Update NextCloud node * Update OpenThesaurus node * Update Orbit node * Update PagerDuty node * Update PayPal node * Update Peekalink node * Update Phantombuster node * Update PostHog node * Update ProfitWell node * Refactor & Update Pushbullet node * Update QuickBooks node * Update Raindrop node * Update Reddit node * Update Rocketchat node * Update S3 node * Update Salesforce node * Update SendGrid node * Update SentryIo node * Update Shopify node * Update Signl4 node * Update Slack node * Update Spontit node * Update Spotify node * Update Storyblok node * Refactor & Update Strapi node * Refactor & Update Strava node * Update Taiga node * Refactor & update Tapfiliate node * Update Telegram node * Update TheHive node * Update Todoist node * Update TravisCi node * Update Trello node * Update Twilio node * Update Twist node * Update Twitter node * Update Uplead node * Update UProc node * Update Vero node * Update Webflow node * Update Wekan node * Update Wordpress node * Update Xero node * Update Yourls node * Update Zendesk node * Update ZohoCrm node * Refactor & Update Zoom node * Update Zulip node * Update Clockify node * Update MongoDb node * Update MySql node * Update MicrosoftTeams node * Update Stackby node * Refactor Discourse node * Support corner-case in Github node update * Support corner-case in Gitlab node update * Refactor & Update GoogleContacts node * Refactor Mindee node * Update Coda node * Lint fixes * Update Beeminder node * Update Google Firebase RealtimeDatabase node * Update HelpScout node * Update Mailcheck node * Update Paddle node * Update Pipedrive node * Update Pushover node * Update Segment node * Refactor & Update Vonage node * Added new conditions to warnings on execute batch cmd * Added keep only properties flag * Fixed code for keep only props * Added dependencies for image editing Co-authored-by: dali <servfrdali@yahoo.fr>
This commit is contained in:
@@ -1862,215 +1862,64 @@ export class Mailchimp implements INodeType {
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
if (resource === 'listGroup') {
|
||||
//https://mailchimp.com/developer/reference/lists/interest-categories/#get_/lists/-list_id-/interest-categories/-interest_category_id-
|
||||
if (operation === 'getAll') {
|
||||
const listId = this.getNodeParameter('list', i) as string;
|
||||
const categoryId = this.getNodeParameter('groupCategory', i) as string;
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
try {
|
||||
if (resource === 'listGroup') {
|
||||
//https://mailchimp.com/developer/reference/lists/interest-categories/#get_/lists/-list_id-/interest-categories/-interest_category_id-
|
||||
if (operation === 'getAll') {
|
||||
const listId = this.getNodeParameter('list', i) as string;
|
||||
const categoryId = this.getNodeParameter('groupCategory', i) as string;
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
|
||||
if (returnAll === true) {
|
||||
responseData = await mailchimpApiRequestAllItems.call(this, `/lists/${listId}/interest-categories/${categoryId}/interests`, 'GET', 'interests', {}, qs);
|
||||
} else {
|
||||
qs.count = this.getNodeParameter('limit', i) as number;
|
||||
responseData = await mailchimpApiRequest.call(this, `/lists/${listId}/interest-categories/${categoryId}/interests`, 'GET', {}, qs);
|
||||
responseData = responseData.interests;
|
||||
if (returnAll === true) {
|
||||
responseData = await mailchimpApiRequestAllItems.call(this, `/lists/${listId}/interest-categories/${categoryId}/interests`, 'GET', 'interests', {}, qs);
|
||||
} else {
|
||||
qs.count = this.getNodeParameter('limit', i) as number;
|
||||
responseData = await mailchimpApiRequest.call(this, `/lists/${listId}/interest-categories/${categoryId}/interests`, 'GET', {}, qs);
|
||||
responseData = responseData.interests;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (resource === 'member') {
|
||||
//https://mailchimp.com/developer/reference/lists/list-members/#post_/lists/-list_id-/members
|
||||
if (operation === 'create') {
|
||||
const listId = this.getNodeParameter('list', i) as string;
|
||||
const email = this.getNodeParameter('email', i) as string;
|
||||
const status = this.getNodeParameter('status', i) as Status;
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
const jsonActive = this.getNodeParameter('jsonParameters', i) as IDataObject;
|
||||
if (resource === 'member') {
|
||||
//https://mailchimp.com/developer/reference/lists/list-members/#post_/lists/-list_id-/members
|
||||
if (operation === 'create') {
|
||||
const listId = this.getNodeParameter('list', i) as string;
|
||||
const email = this.getNodeParameter('email', i) as string;
|
||||
const status = this.getNodeParameter('status', i) as Status;
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
const jsonActive = this.getNodeParameter('jsonParameters', i) as IDataObject;
|
||||
|
||||
const body: ICreateMemberBody = {
|
||||
listId,
|
||||
email_address: email,
|
||||
status,
|
||||
};
|
||||
if (options.emailType) {
|
||||
body.email_type = options.emailType as string;
|
||||
}
|
||||
if (options.language) {
|
||||
body.language = options.language as string;
|
||||
}
|
||||
if (options.vip) {
|
||||
body.vip = options.vip as boolean;
|
||||
}
|
||||
if (options.ipSignup) {
|
||||
body.ip_signup = options.ipSignup as string;
|
||||
}
|
||||
if (options.ipOptIn) {
|
||||
body.ip_opt = options.ipOptIn as string;
|
||||
}
|
||||
if (options.timestampOpt) {
|
||||
body.timestamp_opt = moment(options.timestampOpt as string).format('YYYY-MM-DD HH:MM:SS') as string;
|
||||
}
|
||||
if (options.timestampSignup) {
|
||||
body.timestamp_signup = moment(options.timestampSignup as string).format('YYYY-MM-DD HH:MM:SS') as string;
|
||||
}
|
||||
if (options.tags) {
|
||||
// @ts-ignore
|
||||
body.tags = options.tags.split(',') as string[];
|
||||
}
|
||||
if (!jsonActive) {
|
||||
const locationValues = (this.getNodeParameter('locationFieldsUi', i) as IDataObject).locationFieldsValues as IDataObject;
|
||||
if (locationValues) {
|
||||
const location: ILocation = {};
|
||||
for (const key of Object.keys(locationValues)) {
|
||||
if (key === 'latitude') {
|
||||
location.latitude = parseFloat(locationValues[key] as string) as number;
|
||||
} else if (key === 'longitude') {
|
||||
location.longitude = parseFloat(locationValues[key] as string) as number;
|
||||
}
|
||||
}
|
||||
body.location = location;
|
||||
const body: ICreateMemberBody = {
|
||||
listId,
|
||||
email_address: email,
|
||||
status,
|
||||
};
|
||||
if (options.emailType) {
|
||||
body.email_type = options.emailType as string;
|
||||
}
|
||||
const mergeFieldsValues = (this.getNodeParameter('mergeFieldsUi', i) as IDataObject).mergeFieldsValues as IDataObject[];
|
||||
if (mergeFieldsValues) {
|
||||
const mergeFields = {};
|
||||
for (let i = 0; i < mergeFieldsValues.length; i++) {
|
||||
// @ts-ignore
|
||||
mergeFields[mergeFieldsValues[i].name] = mergeFieldsValues[i].value;
|
||||
}
|
||||
body.merge_fields = mergeFields;
|
||||
if (options.language) {
|
||||
body.language = options.language as string;
|
||||
}
|
||||
|
||||
const groupsValues = (this.getNodeParameter('groupsUi', i) as IDataObject).groupsValues as IDataObject[];
|
||||
if (groupsValues) {
|
||||
const groups = {};
|
||||
for (let i = 0; i < groupsValues.length; i++) {
|
||||
// @ts-ignore
|
||||
groups[groupsValues[i].categoryFieldId] = groupsValues[i].value;
|
||||
}
|
||||
body.interests = groups;
|
||||
if (options.vip) {
|
||||
body.vip = options.vip as boolean;
|
||||
}
|
||||
} else {
|
||||
const locationJson = validateJSON(this.getNodeParameter('locationJson', i) as string);
|
||||
const mergeFieldsJson = validateJSON(this.getNodeParameter('mergeFieldsJson', i) as string);
|
||||
const groupJson = validateJSON(this.getNodeParameter('groupJson', i) as string);
|
||||
if (locationJson) {
|
||||
body.location = locationJson;
|
||||
if (options.ipSignup) {
|
||||
body.ip_signup = options.ipSignup as string;
|
||||
}
|
||||
if (mergeFieldsJson) {
|
||||
body.merge_fields = mergeFieldsJson;
|
||||
if (options.ipOptIn) {
|
||||
body.ip_opt = options.ipOptIn as string;
|
||||
}
|
||||
if (groupJson) {
|
||||
body.interests = groupJson;
|
||||
if (options.timestampOpt) {
|
||||
body.timestamp_opt = moment(options.timestampOpt as string).format('YYYY-MM-DD HH:MM:SS') as string;
|
||||
}
|
||||
}
|
||||
responseData = await mailchimpApiRequest.call(this, `/lists/${listId}/members`, 'POST', body);
|
||||
}
|
||||
//https://mailchimp.com/developer/reference/lists/list-members/
|
||||
if (operation === 'delete') {
|
||||
|
||||
const listId = this.getNodeParameter('list', i) as string;
|
||||
const email = this.getNodeParameter('email', i) as string;
|
||||
|
||||
responseData = await mailchimpApiRequest.call(this, `/lists/${listId}/members/${email}/actions/delete-permanent`, 'POST');
|
||||
responseData = { success: true };
|
||||
}
|
||||
//https://mailchimp.com/developer/reference/lists/list-members/#get_/lists/-list_id-/members/-subscriber_hash-
|
||||
if (operation === 'get') {
|
||||
|
||||
const listId = this.getNodeParameter('list', i) as string;
|
||||
const email = this.getNodeParameter('email', i) as string;
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
|
||||
if (options.fields) {
|
||||
qs.fields = options.fields as string;
|
||||
}
|
||||
|
||||
if (options.excludeFields) {
|
||||
qs.exclude_fields = options.excludeFields as string;
|
||||
}
|
||||
|
||||
responseData = await mailchimpApiRequest.call(this, `/lists/${listId}/members/${email}`, 'GET', {}, qs);
|
||||
}
|
||||
//https://mailchimp.com/developer/reference/lists/list-members/#get_/lists/-list_id-/members
|
||||
if (operation === 'getAll') {
|
||||
const listId = this.getNodeParameter('list', i) as string;
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
|
||||
if (options.beforeLastChanged) {
|
||||
qs.before_last_changed = options.beforeLastChanged as string;
|
||||
}
|
||||
if (options.beforeTimestampOpt) {
|
||||
qs.before_timestamp_opt = options.beforeTimestampOpt as string;
|
||||
}
|
||||
// TODO
|
||||
//figure why for some reason when either fields or exclude_fields is set the endpoint returns nothing
|
||||
// interestingly it works perfect when retriving just one member
|
||||
|
||||
// if (options.fields) {
|
||||
// qs.fields = options.fields as string;
|
||||
// }
|
||||
// if (options.excludeFields) {
|
||||
// qs.exclude_fields = options.excludeFields as string;
|
||||
// }
|
||||
if (options.emailType) {
|
||||
qs.email_type = options.emailType as string;
|
||||
}
|
||||
if (options.status) {
|
||||
qs.status = options.status as string;
|
||||
}
|
||||
if (options.sinceLastChanged) {
|
||||
qs.since_last_changed = options.sinceLastChanged as string;
|
||||
}
|
||||
if (returnAll === true) {
|
||||
responseData = await mailchimpApiRequestAllItems.call(this, `/lists/${listId}/members`, 'GET', 'members', {}, qs);
|
||||
} else {
|
||||
qs.count = this.getNodeParameter('limit', i) as number;
|
||||
responseData = await mailchimpApiRequest.call(this, `/lists/${listId}/members`, 'GET', {}, qs);
|
||||
responseData = responseData.members;
|
||||
}
|
||||
}
|
||||
//https://mailchimp.com/developer/reference/lists/list-members/#put_/lists/-list_id-/members/-subscriber_hash-
|
||||
if (operation === 'update') {
|
||||
|
||||
const listId = this.getNodeParameter('list', i) as string;
|
||||
const email = this.getNodeParameter('email', i) as string;
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||
const jsonActive = this.getNodeParameter('jsonParameters', i) as IDataObject;
|
||||
const body: ICreateMemberBody = {
|
||||
listId,
|
||||
email_address: email,
|
||||
};
|
||||
if (updateFields.skipMergeValidation) {
|
||||
qs.skip_merge_validation = updateFields.skipMergeValidation as boolean;
|
||||
}
|
||||
if (updateFields.status) {
|
||||
body.status = updateFields.status as Status;
|
||||
}
|
||||
if (updateFields.emailType) {
|
||||
body.email_type = updateFields.emailType as string;
|
||||
}
|
||||
if (updateFields.language) {
|
||||
body.language = updateFields.language as string;
|
||||
}
|
||||
if (updateFields.vip) {
|
||||
body.vip = updateFields.vip as boolean;
|
||||
}
|
||||
if (updateFields.ipSignup) {
|
||||
body.ip_signup = updateFields.ipSignup as string;
|
||||
}
|
||||
if (updateFields.ipOptIn) {
|
||||
body.ip_opt = updateFields.ipOptIn as string;
|
||||
}
|
||||
if (updateFields.timestampOpt) {
|
||||
body.timestamp_opt = moment(updateFields.timestampOpt as string).format('YYYY-MM-DD HH:MM:SS') as string;
|
||||
}
|
||||
if (updateFields.timestampSignup) {
|
||||
body.timestamp_signup = moment(updateFields.timestampSignup as string).format('YYYY-MM-DD HH:MM:SS') as string;
|
||||
}
|
||||
if (!jsonActive) {
|
||||
if (updateFields.locationFieldsUi) {
|
||||
const locationValues = (updateFields.locationFieldsUi as IDataObject).locationFieldsValues as IDataObject;
|
||||
if (options.timestampSignup) {
|
||||
body.timestamp_signup = moment(options.timestampSignup as string).format('YYYY-MM-DD HH:MM:SS') as string;
|
||||
}
|
||||
if (options.tags) {
|
||||
// @ts-ignore
|
||||
body.tags = options.tags.split(',') as string[];
|
||||
}
|
||||
if (!jsonActive) {
|
||||
const locationValues = (this.getNodeParameter('locationFieldsUi', i) as IDataObject).locationFieldsValues as IDataObject;
|
||||
if (locationValues) {
|
||||
const location: ILocation = {};
|
||||
for (const key of Object.keys(locationValues)) {
|
||||
@@ -2082,9 +1931,7 @@ export class Mailchimp implements INodeType {
|
||||
}
|
||||
body.location = location;
|
||||
}
|
||||
}
|
||||
if (updateFields.mergeFieldsUi) {
|
||||
const mergeFieldsValues = (updateFields.mergeFieldsUi as IDataObject).mergeFieldsValues as IDataObject[];
|
||||
const mergeFieldsValues = (this.getNodeParameter('mergeFieldsUi', i) as IDataObject).mergeFieldsValues as IDataObject[];
|
||||
if (mergeFieldsValues) {
|
||||
const mergeFields = {};
|
||||
for (let i = 0; i < mergeFieldsValues.length; i++) {
|
||||
@@ -2093,9 +1940,8 @@ export class Mailchimp implements INodeType {
|
||||
}
|
||||
body.merge_fields = mergeFields;
|
||||
}
|
||||
}
|
||||
if (updateFields.groupsUi) {
|
||||
const groupsValues = (updateFields.groupsUi as IDataObject).groupsValues as IDataObject[];
|
||||
|
||||
const groupsValues = (this.getNodeParameter('groupsUi', i) as IDataObject).groupsValues as IDataObject[];
|
||||
if (groupsValues) {
|
||||
const groups = {};
|
||||
for (let i = 0; i < groupsValues.length; i++) {
|
||||
@@ -2104,168 +1950,330 @@ export class Mailchimp implements INodeType {
|
||||
}
|
||||
body.interests = groups;
|
||||
}
|
||||
} else {
|
||||
const locationJson = validateJSON(this.getNodeParameter('locationJson', i) as string);
|
||||
const mergeFieldsJson = validateJSON(this.getNodeParameter('mergeFieldsJson', i) as string);
|
||||
const groupJson = validateJSON(this.getNodeParameter('groupJson', i) as string);
|
||||
if (locationJson) {
|
||||
body.location = locationJson;
|
||||
}
|
||||
if (mergeFieldsJson) {
|
||||
body.merge_fields = mergeFieldsJson;
|
||||
}
|
||||
if (groupJson) {
|
||||
body.interests = groupJson;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const locationJson = validateJSON(this.getNodeParameter('locationJson', i) as string);
|
||||
const mergeFieldsJson = validateJSON(this.getNodeParameter('mergeFieldsJson', i) as string);
|
||||
const groupJson = validateJSON(this.getNodeParameter('groupJson', i) as string);
|
||||
responseData = await mailchimpApiRequest.call(this, `/lists/${listId}/members`, 'POST', body);
|
||||
}
|
||||
//https://mailchimp.com/developer/reference/lists/list-members/
|
||||
if (operation === 'delete') {
|
||||
|
||||
if (locationJson) {
|
||||
body.location = locationJson;
|
||||
const listId = this.getNodeParameter('list', i) as string;
|
||||
const email = this.getNodeParameter('email', i) as string;
|
||||
|
||||
responseData = await mailchimpApiRequest.call(this, `/lists/${listId}/members/${email}/actions/delete-permanent`, 'POST');
|
||||
responseData = { success: true };
|
||||
}
|
||||
//https://mailchimp.com/developer/reference/lists/list-members/#get_/lists/-list_id-/members/-subscriber_hash-
|
||||
if (operation === 'get') {
|
||||
|
||||
const listId = this.getNodeParameter('list', i) as string;
|
||||
const email = this.getNodeParameter('email', i) as string;
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
|
||||
if (options.fields) {
|
||||
qs.fields = options.fields as string;
|
||||
}
|
||||
if (mergeFieldsJson) {
|
||||
body.merge_fields = mergeFieldsJson;
|
||||
|
||||
if (options.excludeFields) {
|
||||
qs.exclude_fields = options.excludeFields as string;
|
||||
}
|
||||
if (groupJson) {
|
||||
body.interests = groupJson;
|
||||
|
||||
responseData = await mailchimpApiRequest.call(this, `/lists/${listId}/members/${email}`, 'GET', {}, qs);
|
||||
}
|
||||
//https://mailchimp.com/developer/reference/lists/list-members/#get_/lists/-list_id-/members
|
||||
if (operation === 'getAll') {
|
||||
const listId = this.getNodeParameter('list', i) as string;
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
|
||||
if (options.beforeLastChanged) {
|
||||
qs.before_last_changed = options.beforeLastChanged as string;
|
||||
}
|
||||
if (options.beforeTimestampOpt) {
|
||||
qs.before_timestamp_opt = options.beforeTimestampOpt as string;
|
||||
}
|
||||
// TODO
|
||||
//figure why for some reason when either fields or exclude_fields is set the endpoint returns nothing
|
||||
// interestingly it works perfect when retriving just one member
|
||||
|
||||
// if (options.fields) {
|
||||
// qs.fields = options.fields as string;
|
||||
// }
|
||||
// if (options.excludeFields) {
|
||||
// qs.exclude_fields = options.excludeFields as string;
|
||||
// }
|
||||
if (options.emailType) {
|
||||
qs.email_type = options.emailType as string;
|
||||
}
|
||||
if (options.status) {
|
||||
qs.status = options.status as string;
|
||||
}
|
||||
if (options.sinceLastChanged) {
|
||||
qs.since_last_changed = options.sinceLastChanged as string;
|
||||
}
|
||||
if (returnAll === true) {
|
||||
responseData = await mailchimpApiRequestAllItems.call(this, `/lists/${listId}/members`, 'GET', 'members', {}, qs);
|
||||
} else {
|
||||
qs.count = this.getNodeParameter('limit', i) as number;
|
||||
responseData = await mailchimpApiRequest.call(this, `/lists/${listId}/members`, 'GET', {}, qs);
|
||||
responseData = responseData.members;
|
||||
}
|
||||
}
|
||||
responseData = await mailchimpApiRequest.call(this, `/lists/${listId}/members/${email}`, 'PUT', body);
|
||||
}
|
||||
}
|
||||
if (resource === 'memberTag') {
|
||||
//https://mailchimp.com/developer/reference/lists/list-members/list-member-tags/#post_/lists/-list_id-/members/-subscriber_hash-/tags
|
||||
if (operation === 'create') {
|
||||
const listId = this.getNodeParameter('list', i) as string;
|
||||
const email = this.getNodeParameter('email', i) as string;
|
||||
const tags = this.getNodeParameter('tags', i) as string[];
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
//https://mailchimp.com/developer/reference/lists/list-members/#put_/lists/-list_id-/members/-subscriber_hash-
|
||||
if (operation === 'update') {
|
||||
|
||||
const body: IDataObject = {
|
||||
tags: [],
|
||||
};
|
||||
|
||||
if (options.isSyncing) {
|
||||
body.is_syncing = options.isSyncing as boolean;
|
||||
}
|
||||
|
||||
for (const tag of tags) {
|
||||
//@ts-ignore
|
||||
body.tags.push({
|
||||
name: tag,
|
||||
status: 'active',
|
||||
});
|
||||
}
|
||||
|
||||
responseData = await mailchimpApiRequest.call(this, `/lists/${listId}/members/${email}/tags`, 'POST', body);
|
||||
responseData = { success: true };
|
||||
}
|
||||
//https://mailchimp.com/developer/reference/lists/list-members/list-member-tags/#post_/lists/-list_id-/members/-subscriber_hash-/tags
|
||||
if (operation === 'delete') {
|
||||
|
||||
const listId = this.getNodeParameter('list', i) as string;
|
||||
const email = this.getNodeParameter('email', i) as string;
|
||||
const tags = this.getNodeParameter('tags', i) as string[];
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
|
||||
const body: IDataObject = {
|
||||
tags: [],
|
||||
};
|
||||
|
||||
if (options.isSyncing) {
|
||||
body.is_syncing = options.isSyncing as boolean;
|
||||
}
|
||||
|
||||
for (const tag of tags) {
|
||||
//@ts-ignore
|
||||
body.tags.push({
|
||||
name: tag,
|
||||
status: 'inactive',
|
||||
});
|
||||
}
|
||||
responseData = await mailchimpApiRequest.call(this, `/lists/${listId}/members/${email}/tags`, 'POST', body);
|
||||
responseData = { success: true };
|
||||
}
|
||||
}
|
||||
if (resource === 'campaign') {
|
||||
//https://mailchimp.com/developer/api/marketing/campaigns/list-campaigns/
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
if (options.status) {
|
||||
qs.status = options.status as string;
|
||||
}
|
||||
if (options.beforeCreateTime) {
|
||||
qs.before_create_time = options.beforeCreateTime as string;
|
||||
}
|
||||
if (options.beforeSendTime) {
|
||||
qs.before_send_time = options.beforeSendTime as string;
|
||||
}
|
||||
if (options.excludeFields) {
|
||||
qs.exclude_fields = (options.exclude_fields as string[]).join(',');
|
||||
}
|
||||
if (options.fields) {
|
||||
qs.fields = (options.fields as string[]).join(',');
|
||||
if ((options.fields as string[]).includes('*')) {
|
||||
qs.fields = campaignFieldsMetadata.join(',');
|
||||
const listId = this.getNodeParameter('list', i) as string;
|
||||
const email = this.getNodeParameter('email', i) as string;
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||
const jsonActive = this.getNodeParameter('jsonParameters', i) as IDataObject;
|
||||
const body: ICreateMemberBody = {
|
||||
listId,
|
||||
email_address: email,
|
||||
};
|
||||
if (updateFields.skipMergeValidation) {
|
||||
qs.skip_merge_validation = updateFields.skipMergeValidation as boolean;
|
||||
}
|
||||
} else {
|
||||
qs.fields = [
|
||||
'campaigns.id',
|
||||
'campaigns.status',
|
||||
'campaigns.tracking',
|
||||
'campaigns.settings.from_name',
|
||||
'campaigns.settings.title',
|
||||
'campaigns.settings.reply_to',
|
||||
].join(',');
|
||||
}
|
||||
if (updateFields.status) {
|
||||
body.status = updateFields.status as Status;
|
||||
}
|
||||
if (updateFields.emailType) {
|
||||
body.email_type = updateFields.emailType as string;
|
||||
}
|
||||
if (updateFields.language) {
|
||||
body.language = updateFields.language as string;
|
||||
}
|
||||
if (updateFields.vip) {
|
||||
body.vip = updateFields.vip as boolean;
|
||||
}
|
||||
if (updateFields.ipSignup) {
|
||||
body.ip_signup = updateFields.ipSignup as string;
|
||||
}
|
||||
if (updateFields.ipOptIn) {
|
||||
body.ip_opt = updateFields.ipOptIn as string;
|
||||
}
|
||||
if (updateFields.timestampOpt) {
|
||||
body.timestamp_opt = moment(updateFields.timestampOpt as string).format('YYYY-MM-DD HH:MM:SS') as string;
|
||||
}
|
||||
if (updateFields.timestampSignup) {
|
||||
body.timestamp_signup = moment(updateFields.timestampSignup as string).format('YYYY-MM-DD HH:MM:SS') as string;
|
||||
}
|
||||
if (!jsonActive) {
|
||||
if (updateFields.locationFieldsUi) {
|
||||
const locationValues = (updateFields.locationFieldsUi as IDataObject).locationFieldsValues as IDataObject;
|
||||
if (locationValues) {
|
||||
const location: ILocation = {};
|
||||
for (const key of Object.keys(locationValues)) {
|
||||
if (key === 'latitude') {
|
||||
location.latitude = parseFloat(locationValues[key] as string) as number;
|
||||
} else if (key === 'longitude') {
|
||||
location.longitude = parseFloat(locationValues[key] as string) as number;
|
||||
}
|
||||
}
|
||||
body.location = location;
|
||||
}
|
||||
}
|
||||
if (updateFields.mergeFieldsUi) {
|
||||
const mergeFieldsValues = (updateFields.mergeFieldsUi as IDataObject).mergeFieldsValues as IDataObject[];
|
||||
if (mergeFieldsValues) {
|
||||
const mergeFields = {};
|
||||
for (let i = 0; i < mergeFieldsValues.length; i++) {
|
||||
// @ts-ignore
|
||||
mergeFields[mergeFieldsValues[i].name] = mergeFieldsValues[i].value;
|
||||
}
|
||||
body.merge_fields = mergeFields;
|
||||
}
|
||||
}
|
||||
if (updateFields.groupsUi) {
|
||||
const groupsValues = (updateFields.groupsUi as IDataObject).groupsValues as IDataObject[];
|
||||
if (groupsValues) {
|
||||
const groups = {};
|
||||
for (let i = 0; i < groupsValues.length; i++) {
|
||||
// @ts-ignore
|
||||
groups[groupsValues[i].categoryFieldId] = groupsValues[i].value;
|
||||
}
|
||||
body.interests = groups;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const locationJson = validateJSON(this.getNodeParameter('locationJson', i) as string);
|
||||
const mergeFieldsJson = validateJSON(this.getNodeParameter('mergeFieldsJson', i) as string);
|
||||
const groupJson = validateJSON(this.getNodeParameter('groupJson', i) as string);
|
||||
|
||||
if (options.listId) {
|
||||
qs.list_id = options.listId as string;
|
||||
}
|
||||
if (options.sinceCreateTime) {
|
||||
qs.since_create_time = options.sinceCreateTime as string;
|
||||
}
|
||||
if (options.sinceSendTime) {
|
||||
qs.since_send_time = options.sinceSendTime as string;
|
||||
}
|
||||
if (options.sortDirection) {
|
||||
qs.sort_dir = options.sortDirection as string;
|
||||
}
|
||||
if (options.sortField) {
|
||||
qs.sort_field = options.sortField as string;
|
||||
}
|
||||
if (returnAll === true) {
|
||||
responseData = await mailchimpApiRequestAllItems.call(this, `/campaigns`, 'GET', 'campaigns', {}, qs);
|
||||
} else {
|
||||
qs.count = this.getNodeParameter('limit', i) as number;
|
||||
responseData = await mailchimpApiRequest.call(this, `/campaigns`, 'GET', {}, qs);
|
||||
responseData = responseData.campaigns;
|
||||
if (locationJson) {
|
||||
body.location = locationJson;
|
||||
}
|
||||
if (mergeFieldsJson) {
|
||||
body.merge_fields = mergeFieldsJson;
|
||||
}
|
||||
if (groupJson) {
|
||||
body.interests = groupJson;
|
||||
}
|
||||
}
|
||||
responseData = await mailchimpApiRequest.call(this, `/lists/${listId}/members/${email}`, 'PUT', body);
|
||||
}
|
||||
}
|
||||
//https://mailchimp.com/developer/api/marketing/campaigns/send-campaign/
|
||||
if (operation === 'send') {
|
||||
const campaignId = this.getNodeParameter('campaignId', i) as string;
|
||||
responseData = await mailchimpApiRequest.call(this, `/campaigns/${campaignId}/actions/send`, 'POST', {});
|
||||
responseData = { success: true };
|
||||
}
|
||||
//https://mailchimp.com/developer/api/marketing/campaigns/get-campaign-info/
|
||||
if (operation === 'get') {
|
||||
const campaignId = this.getNodeParameter('campaignId', i) as string;
|
||||
responseData = await mailchimpApiRequest.call(this, `/campaigns/${campaignId}`, 'GET', {});
|
||||
}
|
||||
//https://mailchimp.com/developer/api/marketing/campaigns/delete-campaign/
|
||||
if (operation === 'delete') {
|
||||
const campaignId = this.getNodeParameter('campaignId', i) as string;
|
||||
responseData = await mailchimpApiRequest.call(this, `/campaigns/${campaignId}`, 'DELETE', {});
|
||||
responseData = { success: true };
|
||||
}
|
||||
//https://mailchimp.com/developer/api/marketing/campaigns/replicate-campaign/
|
||||
if (operation === 'replicate') {
|
||||
const campaignId = this.getNodeParameter('campaignId', i) as string;
|
||||
responseData = await mailchimpApiRequest.call(this, `/campaigns/${campaignId}/actions/replicate`, 'POST', {});
|
||||
}
|
||||
//https://mailchimp.com/developer/api/marketing/campaigns/resend-campaign/
|
||||
if (operation === 'resend') {
|
||||
const campaignId = this.getNodeParameter('campaignId', i) as string;
|
||||
responseData = await mailchimpApiRequest.call(this, `/campaigns/${campaignId}/actions/create-resend`, 'POST', {});
|
||||
}
|
||||
}
|
||||
if (resource === 'memberTag') {
|
||||
//https://mailchimp.com/developer/reference/lists/list-members/list-member-tags/#post_/lists/-list_id-/members/-subscriber_hash-/tags
|
||||
if (operation === 'create') {
|
||||
const listId = this.getNodeParameter('list', i) as string;
|
||||
const email = this.getNodeParameter('email', i) as string;
|
||||
const tags = this.getNodeParameter('tags', i) as string[];
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
|
||||
if (Array.isArray(responseData)) {
|
||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||
} else {
|
||||
returnData.push(responseData as IDataObject);
|
||||
const body: IDataObject = {
|
||||
tags: [],
|
||||
};
|
||||
|
||||
if (options.isSyncing) {
|
||||
body.is_syncing = options.isSyncing as boolean;
|
||||
}
|
||||
|
||||
for (const tag of tags) {
|
||||
//@ts-ignore
|
||||
body.tags.push({
|
||||
name: tag,
|
||||
status: 'active',
|
||||
});
|
||||
}
|
||||
|
||||
responseData = await mailchimpApiRequest.call(this, `/lists/${listId}/members/${email}/tags`, 'POST', body);
|
||||
responseData = { success: true };
|
||||
}
|
||||
//https://mailchimp.com/developer/reference/lists/list-members/list-member-tags/#post_/lists/-list_id-/members/-subscriber_hash-/tags
|
||||
if (operation === 'delete') {
|
||||
|
||||
const listId = this.getNodeParameter('list', i) as string;
|
||||
const email = this.getNodeParameter('email', i) as string;
|
||||
const tags = this.getNodeParameter('tags', i) as string[];
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
|
||||
const body: IDataObject = {
|
||||
tags: [],
|
||||
};
|
||||
|
||||
if (options.isSyncing) {
|
||||
body.is_syncing = options.isSyncing as boolean;
|
||||
}
|
||||
|
||||
for (const tag of tags) {
|
||||
//@ts-ignore
|
||||
body.tags.push({
|
||||
name: tag,
|
||||
status: 'inactive',
|
||||
});
|
||||
}
|
||||
responseData = await mailchimpApiRequest.call(this, `/lists/${listId}/members/${email}/tags`, 'POST', body);
|
||||
responseData = { success: true };
|
||||
}
|
||||
}
|
||||
if (resource === 'campaign') {
|
||||
//https://mailchimp.com/developer/api/marketing/campaigns/list-campaigns/
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
if (options.status) {
|
||||
qs.status = options.status as string;
|
||||
}
|
||||
if (options.beforeCreateTime) {
|
||||
qs.before_create_time = options.beforeCreateTime as string;
|
||||
}
|
||||
if (options.beforeSendTime) {
|
||||
qs.before_send_time = options.beforeSendTime as string;
|
||||
}
|
||||
if (options.excludeFields) {
|
||||
qs.exclude_fields = (options.exclude_fields as string[]).join(',');
|
||||
}
|
||||
if (options.fields) {
|
||||
qs.fields = (options.fields as string[]).join(',');
|
||||
if ((options.fields as string[]).includes('*')) {
|
||||
qs.fields = campaignFieldsMetadata.join(',');
|
||||
}
|
||||
} else {
|
||||
qs.fields = [
|
||||
'campaigns.id',
|
||||
'campaigns.status',
|
||||
'campaigns.tracking',
|
||||
'campaigns.settings.from_name',
|
||||
'campaigns.settings.title',
|
||||
'campaigns.settings.reply_to',
|
||||
].join(',');
|
||||
}
|
||||
|
||||
if (options.listId) {
|
||||
qs.list_id = options.listId as string;
|
||||
}
|
||||
if (options.sinceCreateTime) {
|
||||
qs.since_create_time = options.sinceCreateTime as string;
|
||||
}
|
||||
if (options.sinceSendTime) {
|
||||
qs.since_send_time = options.sinceSendTime as string;
|
||||
}
|
||||
if (options.sortDirection) {
|
||||
qs.sort_dir = options.sortDirection as string;
|
||||
}
|
||||
if (options.sortField) {
|
||||
qs.sort_field = options.sortField as string;
|
||||
}
|
||||
if (returnAll === true) {
|
||||
responseData = await mailchimpApiRequestAllItems.call(this, `/campaigns`, 'GET', 'campaigns', {}, qs);
|
||||
} else {
|
||||
qs.count = this.getNodeParameter('limit', i) as number;
|
||||
responseData = await mailchimpApiRequest.call(this, `/campaigns`, 'GET', {}, qs);
|
||||
responseData = responseData.campaigns;
|
||||
}
|
||||
}
|
||||
//https://mailchimp.com/developer/api/marketing/campaigns/send-campaign/
|
||||
if (operation === 'send') {
|
||||
const campaignId = this.getNodeParameter('campaignId', i) as string;
|
||||
responseData = await mailchimpApiRequest.call(this, `/campaigns/${campaignId}/actions/send`, 'POST', {});
|
||||
responseData = { success: true };
|
||||
}
|
||||
//https://mailchimp.com/developer/api/marketing/campaigns/get-campaign-info/
|
||||
if (operation === 'get') {
|
||||
const campaignId = this.getNodeParameter('campaignId', i) as string;
|
||||
responseData = await mailchimpApiRequest.call(this, `/campaigns/${campaignId}`, 'GET', {});
|
||||
}
|
||||
//https://mailchimp.com/developer/api/marketing/campaigns/delete-campaign/
|
||||
if (operation === 'delete') {
|
||||
const campaignId = this.getNodeParameter('campaignId', i) as string;
|
||||
responseData = await mailchimpApiRequest.call(this, `/campaigns/${campaignId}`, 'DELETE', {});
|
||||
responseData = { success: true };
|
||||
}
|
||||
//https://mailchimp.com/developer/api/marketing/campaigns/replicate-campaign/
|
||||
if (operation === 'replicate') {
|
||||
const campaignId = this.getNodeParameter('campaignId', i) as string;
|
||||
responseData = await mailchimpApiRequest.call(this, `/campaigns/${campaignId}/actions/replicate`, 'POST', {});
|
||||
}
|
||||
//https://mailchimp.com/developer/api/marketing/campaigns/resend-campaign/
|
||||
if (operation === 'resend') {
|
||||
const campaignId = this.getNodeParameter('campaignId', i) as string;
|
||||
responseData = await mailchimpApiRequest.call(this, `/campaigns/${campaignId}/actions/create-resend`, 'POST', {});
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(responseData)) {
|
||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||
} else {
|
||||
returnData.push(responseData as IDataObject);
|
||||
}
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return [this.helpers.returnJsonArray(returnData)];
|
||||
|
||||
Reference in New Issue
Block a user