mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-26 13:14:07 -08:00
🔀 Merge branch 'feature/mailchimp-extended' of https://github.com/RicardoE105/n8n into RicardoE105-feature/mailchimp-extended
This commit is contained in:
commit
bb07e0f135
|
@ -49,7 +49,6 @@ export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctio
|
||||||
|
|
||||||
const datacenter = (credentials.apiKey as string).split('-').pop();
|
const datacenter = (credentials.apiKey as string).split('-').pop();
|
||||||
options.url = `https://${datacenter}.${host}${endpoint}`;
|
options.url = `https://${datacenter}.${host}${endpoint}`;
|
||||||
|
|
||||||
return await this.helpers.request!(options);
|
return await this.helpers.request!(options);
|
||||||
} else {
|
} else {
|
||||||
const credentials = this.getCredentials('mailchimpOAuth2Api') as IDataObject;
|
const credentials = this.getCredentials('mailchimpOAuth2Api') as IDataObject;
|
||||||
|
|
|
@ -47,6 +47,7 @@ interface ICreateMemberBody {
|
||||||
timestamp_opt?: string;
|
timestamp_opt?: string;
|
||||||
tags?: string[];
|
tags?: string[];
|
||||||
merge_fields?: IDataObject;
|
merge_fields?: IDataObject;
|
||||||
|
interests?: IDataObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Mailchimp implements INodeType {
|
export class Mailchimp implements INodeType {
|
||||||
|
@ -112,6 +113,10 @@ export class Mailchimp implements INodeType {
|
||||||
name: 'resource',
|
name: 'resource',
|
||||||
type: 'options',
|
type: 'options',
|
||||||
options: [
|
options: [
|
||||||
|
{
|
||||||
|
name: 'List Group',
|
||||||
|
value: 'listGroup',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'Member',
|
name: 'Member',
|
||||||
value: 'member',
|
value: 'member',
|
||||||
|
@ -194,6 +199,28 @@ export class Mailchimp implements INodeType {
|
||||||
default: 'create',
|
default: 'create',
|
||||||
description: 'The operation to perform.',
|
description: 'The operation to perform.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Operation',
|
||||||
|
name: 'operation',
|
||||||
|
type: 'options',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'listGroup',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Get All',
|
||||||
|
value: 'getAll',
|
||||||
|
description: 'Get all groups',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'getAll',
|
||||||
|
description: 'The operation to perform.',
|
||||||
|
},
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* member:create */
|
/* member:create */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
@ -534,6 +561,89 @@ export class Mailchimp implements INodeType {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Interest Groups',
|
||||||
|
name: 'groupsUi',
|
||||||
|
placeholder: 'Add Interest Group',
|
||||||
|
type: 'fixedCollection',
|
||||||
|
default: {},
|
||||||
|
typeOptions: {
|
||||||
|
multipleValues: true,
|
||||||
|
},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource:[
|
||||||
|
'member'
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'create',
|
||||||
|
],
|
||||||
|
jsonParameters: [
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'groupsValues',
|
||||||
|
displayName: 'Group',
|
||||||
|
typeOptions: {
|
||||||
|
multipleValueButtonText: 'Add Interest Group',
|
||||||
|
},
|
||||||
|
values: [
|
||||||
|
{
|
||||||
|
displayName: 'Category ID',
|
||||||
|
name: 'categoryId',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getGroupCategories',
|
||||||
|
loadOptionsDependsOn: [
|
||||||
|
'list',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Category Field ID',
|
||||||
|
name: 'categoryFieldId',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Value',
|
||||||
|
name: 'value',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
description: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Interest Groups',
|
||||||
|
name: 'groupJson',
|
||||||
|
type: 'json',
|
||||||
|
typeOptions: {
|
||||||
|
alwaysOpenEditWindow: true,
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
description: '',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource:[
|
||||||
|
'member',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'create',
|
||||||
|
],
|
||||||
|
jsonParameters: [
|
||||||
|
true,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* member:delete */
|
/* member:delete */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
@ -922,6 +1032,66 @@ export class Mailchimp implements INodeType {
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Type of email this member asked to get',
|
description: 'Type of email this member asked to get',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Interest Groups',
|
||||||
|
name: 'groupsUi',
|
||||||
|
placeholder: 'Add Interest Group',
|
||||||
|
type: 'fixedCollection',
|
||||||
|
default: {},
|
||||||
|
typeOptions: {
|
||||||
|
multipleValues: true,
|
||||||
|
},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
'/resource':[
|
||||||
|
'member'
|
||||||
|
],
|
||||||
|
'/operation':[
|
||||||
|
'update',
|
||||||
|
],
|
||||||
|
'/jsonParameters': [
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'groupsValues',
|
||||||
|
displayName: 'Group',
|
||||||
|
typeOptions: {
|
||||||
|
multipleValueButtonText: 'Add Interest Group',
|
||||||
|
},
|
||||||
|
values: [
|
||||||
|
{
|
||||||
|
displayName: 'Category ID',
|
||||||
|
name: 'categoryId',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getGroupCategories',
|
||||||
|
loadOptionsDependsOn: [
|
||||||
|
'list',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Category Field ID',
|
||||||
|
name: 'categoryFieldId',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Value',
|
||||||
|
name: 'value',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
description: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Language',
|
displayName: 'Language',
|
||||||
name: 'language',
|
name: 'language',
|
||||||
|
@ -1157,6 +1327,29 @@ export class Mailchimp implements INodeType {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Interest Groups',
|
||||||
|
name: 'groupJson',
|
||||||
|
type: 'json',
|
||||||
|
typeOptions: {
|
||||||
|
alwaysOpenEditWindow: true,
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
description: '',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource:[
|
||||||
|
'member',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'update',
|
||||||
|
],
|
||||||
|
jsonParameters: [
|
||||||
|
true,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* memberTag:create */
|
/* memberTag:create */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
@ -1250,6 +1443,96 @@ export class Mailchimp implements INodeType {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
/* member:getAll */
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
{
|
||||||
|
displayName: 'List',
|
||||||
|
name: 'list',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getLists',
|
||||||
|
},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'listGroup',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
options: [],
|
||||||
|
required: true,
|
||||||
|
description: 'List of lists',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Group Category',
|
||||||
|
name: 'groupCategory',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getGroupCategories',
|
||||||
|
loadOptionsDependsOn: [
|
||||||
|
'list',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'listGroup',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
options: [],
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Return All',
|
||||||
|
name: 'returnAll',
|
||||||
|
type: 'boolean',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'listGroup',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: false,
|
||||||
|
description: 'If all results should be returned or only up to a given limit.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Limit',
|
||||||
|
name: 'limit',
|
||||||
|
type: 'number',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'listGroup',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
returnAll: [
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
typeOptions: {
|
||||||
|
minValue: 1,
|
||||||
|
maxValue: 1000,
|
||||||
|
},
|
||||||
|
default: 500,
|
||||||
|
description: 'How many results to return.',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1261,7 +1544,7 @@ export class Mailchimp implements INodeType {
|
||||||
// select them easily
|
// select them easily
|
||||||
async getLists(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getLists(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
const returnData: INodePropertyOptions[] = [];
|
const returnData: INodePropertyOptions[] = [];
|
||||||
const { lists } = await mailchimpApiRequest.call(this, '/lists', 'GET');
|
const lists = await mailchimpApiRequestAllItems.call(this, '/lists', 'GET', 'lists');
|
||||||
for (const list of lists) {
|
for (const list of lists) {
|
||||||
const listName = list.name;
|
const listName = list.name;
|
||||||
const listId = list.id;
|
const listId = list.id;
|
||||||
|
@ -1289,6 +1572,23 @@ export class Mailchimp implements INodeType {
|
||||||
}
|
}
|
||||||
return returnData;
|
return returnData;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Get all the interest fields to display them to user so that he can
|
||||||
|
// select them easily
|
||||||
|
async getGroupCategories(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
|
const returnData: INodePropertyOptions[] = [];
|
||||||
|
const listId = this.getCurrentNodeParameter('list');
|
||||||
|
const { categories } = await mailchimpApiRequest.call(this, `/lists/${listId}/interest-categories`, 'GET');
|
||||||
|
for (const category of categories) {
|
||||||
|
const categoryName = category.title;
|
||||||
|
const categoryId = category.id;
|
||||||
|
returnData.push({
|
||||||
|
name: categoryName,
|
||||||
|
value: categoryId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return returnData;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1302,6 +1602,22 @@ export class Mailchimp implements INodeType {
|
||||||
const operation = this.getNodeParameter('operation', 0) as string;
|
const operation = this.getNodeParameter('operation', 0) as string;
|
||||||
|
|
||||||
for (let i = 0; i < length; i++) {
|
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;
|
||||||
|
|
||||||
|
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') {
|
if (resource === 'member') {
|
||||||
//https://mailchimp.com/developer/reference/lists/list-members/#post_/lists/-list_id-/members
|
//https://mailchimp.com/developer/reference/lists/list-members/#post_/lists/-list_id-/members
|
||||||
if (operation === 'create') {
|
if (operation === 'create') {
|
||||||
|
@ -1363,15 +1679,29 @@ export class Mailchimp implements INodeType {
|
||||||
}
|
}
|
||||||
body.merge_fields = mergeFields;
|
body.merge_fields = mergeFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const locationJson = validateJSON(this.getNodeParameter('locationJson', i) as string);
|
const locationJson = validateJSON(this.getNodeParameter('locationJson', i) as string);
|
||||||
const mergeFieldsJson = validateJSON(this.getNodeParameter('mergeFieldsJson', i) as string);
|
const mergeFieldsJson = validateJSON(this.getNodeParameter('mergeFieldsJson', i) as string);
|
||||||
|
const groupJson = validateJSON(this.getNodeParameter('groupJson', i) as string);
|
||||||
if (locationJson) {
|
if (locationJson) {
|
||||||
body.location = locationJson;
|
body.location = locationJson;
|
||||||
}
|
}
|
||||||
if (mergeFieldsJson) {
|
if (mergeFieldsJson) {
|
||||||
body.merge_fields = mergeFieldsJson;
|
body.merge_fields = mergeFieldsJson;
|
||||||
}
|
}
|
||||||
|
if (groupJson) {
|
||||||
|
body.interests = groupJson;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
responseData = await mailchimpApiRequest.call(this, `/lists/${listId}/members`, 'POST', body);
|
responseData = await mailchimpApiRequest.call(this, `/lists/${listId}/members`, 'POST', body);
|
||||||
}
|
}
|
||||||
|
@ -1504,15 +1834,31 @@ export class Mailchimp implements INodeType {
|
||||||
body.merge_fields = mergeFields;
|
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 {
|
} else {
|
||||||
const locationJson = validateJSON(this.getNodeParameter('locationJson', i) as string);
|
const locationJson = validateJSON(this.getNodeParameter('locationJson', i) as string);
|
||||||
const mergeFieldsJson = validateJSON(this.getNodeParameter('mergeFieldsJson', i) as string);
|
const mergeFieldsJson = validateJSON(this.getNodeParameter('mergeFieldsJson', i) as string);
|
||||||
|
const groupJson = validateJSON(this.getNodeParameter('groupJson', i) as string);
|
||||||
|
|
||||||
if (locationJson) {
|
if (locationJson) {
|
||||||
body.location = locationJson;
|
body.location = locationJson;
|
||||||
}
|
}
|
||||||
if (mergeFieldsJson) {
|
if (mergeFieldsJson) {
|
||||||
body.merge_fields = mergeFieldsJson;
|
body.merge_fields = mergeFieldsJson;
|
||||||
}
|
}
|
||||||
|
if (groupJson) {
|
||||||
|
body.interests = groupJson;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
responseData = await mailchimpApiRequest.call(this, `/lists/${listId}/members/${email}`, 'PUT', body);
|
responseData = await mailchimpApiRequest.call(this, `/lists/${listId}/members/${email}`, 'PUT', body);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue