2023-01-27 03:22:44 -08:00
import type {
2023-03-09 09:13:15 -08:00
IExecuteFunctions ,
2019-11-12 12:48:45 -08:00
IDataObject ,
2019-11-15 12:44:46 -08:00
ILoadOptionsFunctions ,
2019-11-12 12:48:45 -08:00
INodeExecutionData ,
INodePropertyOptions ,
2020-05-22 06:47:47 -07:00
INodeType ,
INodeTypeDescription ,
2019-11-12 12:48:45 -08:00
} from 'n8n-workflow' ;
2020-05-22 06:47:47 -07:00
2019-11-12 12:48:45 -08:00
import {
2020-10-05 15:44:52 -07:00
campaignFieldsMetadata ,
2019-11-12 12:48:45 -08:00
mailchimpApiRequest ,
2020-05-22 06:47:47 -07:00
mailchimpApiRequestAllItems ,
2019-11-15 12:44:46 -08:00
validateJSON ,
2019-11-12 12:48:45 -08:00
} from './GenericFunctions' ;
2019-11-14 15:44:07 -08:00
2022-04-08 14:32:08 -07:00
import moment from 'moment' ;
2020-05-22 06:47:47 -07:00
2019-11-14 15:44:07 -08:00
enum Status {
subscribe = 'subscribe' ,
unsubscribed = 'unsubscribe' ,
cleaned = 'cleaned' ,
pending = 'pending' ,
2019-11-15 12:44:46 -08:00
transactional = 'transactional' ,
2019-11-14 15:44:07 -08:00
}
interface ILocation {
latitude? : number ;
longitude? : number ;
}
interface ICreateMemberBody {
listId : string ;
email_address : string ;
email_type? : string ;
status? : Status ;
language? : string ;
vip? : boolean ;
location? : ILocation ;
2020-05-22 06:47:47 -07:00
ip_signup? : string ;
2019-11-14 15:44:07 -08:00
timestamp_signup? : string ;
ip_opt? : string ;
timestamp_opt? : string ;
tags? : string [ ] ;
merge_fields? : IDataObject ;
2020-07-09 10:37:35 -07:00
interests? : IDataObject ;
2019-11-14 15:44:07 -08:00
}
2019-11-12 12:48:45 -08:00
export class Mailchimp implements INodeType {
description : INodeTypeDescription = {
displayName : 'Mailchimp' ,
name : 'mailchimp' ,
2021-03-25 09:10:02 -07:00
icon : 'file:mailchimp.svg' ,
2019-11-12 12:48:45 -08:00
group : [ 'output' ] ,
version : 1 ,
subtitle : '={{$parameter["operation"] + ": " + $parameter["resource"]}}' ,
description : 'Consume Mailchimp API' ,
defaults : {
name : 'Mailchimp' ,
} ,
inputs : [ 'main' ] ,
outputs : [ 'main' ] ,
credentials : [
{
name : 'mailchimpApi' ,
required : true ,
2020-06-04 06:54:39 -07:00
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
authentication : [ 'apiKey' ] ,
2020-06-04 06:54:39 -07:00
} ,
} ,
} ,
{
name : 'mailchimpOAuth2Api' ,
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
authentication : [ 'oAuth2' ] ,
2020-06-04 06:54:39 -07:00
} ,
} ,
} ,
2019-11-12 12:48:45 -08:00
] ,
properties : [
2020-06-04 06:54:39 -07:00
{
displayName : 'Authentication' ,
name : 'authentication' ,
type : 'options' ,
options : [
{
2020-06-13 19:37:03 -07:00
name : 'API Key' ,
value : 'apiKey' ,
2020-06-04 06:54:39 -07:00
} ,
{
name : 'OAuth2' ,
value : 'oAuth2' ,
} ,
] ,
2020-06-13 19:37:03 -07:00
default : 'apiKey' ,
2020-06-04 06:54:39 -07:00
} ,
2019-11-12 12:48:45 -08:00
{
displayName : 'Resource' ,
name : 'resource' ,
type : 'options' ,
2022-05-20 14:47:24 -07:00
noDataExpression : true ,
2019-11-12 12:48:45 -08:00
options : [
2020-10-02 16:40:10 -07:00
{
name : 'Campaign' ,
2020-10-22 06:46:03 -07:00
value : 'campaign' ,
2020-10-02 16:40:10 -07:00
} ,
2020-07-09 10:37:35 -07:00
{
name : 'List Group' ,
value : 'listGroup' ,
} ,
2019-11-12 12:48:45 -08:00
{
name : 'Member' ,
value : 'member' ,
2020-05-22 06:47:47 -07:00
} ,
{
name : 'Member Tag' ,
value : 'memberTag' ,
2019-11-12 12:48:45 -08:00
} ,
] ,
2019-11-15 12:44:46 -08:00
default : 'member' ,
2019-11-12 12:48:45 -08:00
required : true ,
} ,
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
2022-05-20 14:47:24 -07:00
noDataExpression : true ,
2019-11-12 12:48:45 -08:00
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
2019-11-12 12:48:45 -08:00
} ,
} ,
options : [
{
name : 'Create' ,
value : 'create' ,
2019-11-14 15:44:07 -08:00
description : 'Create a new member on list' ,
2022-07-10 13:50:51 -07:00
action : 'Create a member' ,
2019-11-12 12:48:45 -08:00
} ,
2020-05-22 06:47:47 -07:00
{
name : 'Delete' ,
value : 'delete' ,
description : 'Delete a member on list' ,
2022-07-10 13:50:51 -07:00
action : 'Delete a member' ,
2020-05-22 06:47:47 -07:00
} ,
{
name : 'Get' ,
value : 'get' ,
description : 'Get a member on list' ,
2022-07-10 13:50:51 -07:00
action : 'Get a member' ,
2020-05-22 06:47:47 -07:00
} ,
{
2022-09-07 07:51:14 -07:00
name : 'Get Many' ,
2020-05-22 06:47:47 -07:00
value : 'getAll' ,
2022-09-13 03:36:36 -07:00
description : 'Get many members on a list' ,
2022-09-08 08:10:13 -07:00
action : 'Get many members' ,
2020-05-22 06:47:47 -07:00
} ,
{
name : 'Update' ,
value : 'update' ,
description : 'Update a new member on list' ,
2022-07-10 13:50:51 -07:00
action : 'Update a member' ,
2020-05-22 06:47:47 -07:00
} ,
] ,
default : 'create' ,
} ,
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
2022-05-20 14:47:24 -07:00
noDataExpression : true ,
2020-05-22 06:47:47 -07:00
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'memberTag' ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
options : [
{
name : 'Create' ,
value : 'create' ,
description : 'Add tags from a list member' ,
2022-07-10 13:50:51 -07:00
action : 'Create a member tag' ,
2020-05-22 06:47:47 -07:00
} ,
{
name : 'Delete' ,
value : 'delete' ,
description : 'Remove tags from a list member' ,
2022-07-10 13:50:51 -07:00
action : 'Delete a member tag' ,
2020-05-22 06:47:47 -07:00
} ,
2019-11-12 12:48:45 -08:00
] ,
2019-11-15 12:44:46 -08:00
default : 'create' ,
2019-11-12 12:48:45 -08:00
} ,
2020-07-09 10:37:35 -07:00
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
2022-05-20 14:47:24 -07:00
noDataExpression : true ,
2020-07-09 10:37:35 -07:00
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'listGroup' ] ,
2020-07-09 10:37:35 -07:00
} ,
} ,
options : [
{
2022-09-07 07:51:14 -07:00
name : 'Get Many' ,
2020-07-09 10:37:35 -07:00
value : 'getAll' ,
2022-09-13 03:36:36 -07:00
description : 'Get many groups' ,
2022-09-08 08:10:13 -07:00
action : 'Get many list groups' ,
2020-07-09 10:37:35 -07:00
} ,
] ,
default : 'getAll' ,
} ,
2020-10-02 15:45:58 -07:00
{
displayName : 'Operation' ,
name : 'operation' ,
2022-08-17 08:50:24 -07:00
type : 'options' ,
2022-05-20 14:47:24 -07:00
noDataExpression : true ,
2020-10-02 15:45:58 -07:00
required : true ,
2022-08-17 08:50:24 -07:00
displayOptions : {
2020-10-02 15:45:58 -07:00
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'campaign' ] ,
2020-10-02 15:45:58 -07:00
} ,
} ,
options : [
2020-10-02 16:40:10 -07:00
{
name : 'Delete' ,
value : 'delete' ,
2020-10-22 06:46:03 -07:00
description : 'Delete a campaign' ,
2022-07-10 13:50:51 -07:00
action : 'Delete a campaign' ,
2020-10-02 16:40:10 -07:00
} ,
{
name : 'Get' ,
value : 'get' ,
2020-10-22 06:46:03 -07:00
description : 'Get a campaign' ,
2022-07-10 13:50:51 -07:00
action : 'Get a campaign' ,
2020-10-02 16:40:10 -07:00
} ,
2020-10-02 15:45:58 -07:00
{
2022-09-07 07:51:14 -07:00
name : 'Get Many' ,
2020-10-02 15:45:58 -07:00
value : 'getAll' ,
2022-09-13 03:36:36 -07:00
description : 'Get many campaigns' ,
2022-09-08 08:10:13 -07:00
action : 'Get many campaigns' ,
2020-10-02 15:45:58 -07:00
} ,
2020-10-05 12:16:44 -07:00
{
name : 'Replicate' ,
value : 'replicate' ,
2020-10-22 06:46:03 -07:00
description : 'Replicate a campaign' ,
2022-07-10 13:50:51 -07:00
action : 'Replicate a campaign' ,
2020-10-05 12:16:44 -07:00
} ,
{
name : 'Resend' ,
value : 'resend' ,
2020-10-22 06:46:03 -07:00
description : 'Creates a Resend to Non-Openers version of this campaign' ,
2022-07-10 13:50:51 -07:00
action : 'Resend a campaign' ,
2020-10-05 12:16:44 -07:00
} ,
2020-10-02 15:45:58 -07:00
{
name : 'Send' ,
value : 'send' ,
2020-10-22 06:46:03 -07:00
description : 'Send a campaign' ,
2022-07-10 13:50:51 -07:00
action : 'Send a campaign' ,
2020-10-02 15:45:58 -07:00
} ,
] ,
default : 'getAll' ,
} ,
2022-08-17 08:50:24 -07:00
/* -------------------------------------------------------------------------- */
/* member:create */
/* -------------------------------------------------------------------------- */
2019-11-14 15:44:07 -08:00
{
2022-06-03 10:23:49 -07:00
displayName : 'List Name or ID' ,
2019-11-14 15:44:07 -08:00
name : 'list' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getLists' ,
} ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'create' ] ,
2019-11-14 15:44:07 -08:00
} ,
} ,
default : '' ,
options : [ ] ,
required : true ,
2022-08-17 08:50:24 -07:00
description :
'List of lists. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2019-11-14 15:44:07 -08:00
} ,
{
displayName : 'Email' ,
name : 'email' ,
type : 'string' ,
2022-06-20 07:54:01 -07:00
placeholder : 'name@email.com' ,
2019-11-14 15:44:07 -08:00
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'create' ] ,
2019-11-14 15:44:07 -08:00
} ,
} ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'Email address for a subscriber' ,
2019-11-14 15:44:07 -08:00
} ,
{
displayName : 'Status' ,
name : 'status' ,
type : 'options' ,
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'create' ] ,
2019-11-14 15:44:07 -08:00
} ,
} ,
options : [
{
name : 'Cleaned' ,
value : 'cleaned' ,
} ,
{
name : 'Pending' ,
value : 'pending' ,
} ,
2022-06-03 10:23:49 -07:00
{
name : 'Subscribed' ,
value : 'subscribed' ,
} ,
2019-11-14 15:44:07 -08:00
{
name : 'Transactional' ,
value : 'transactional' ,
} ,
2022-06-03 10:23:49 -07:00
{
name : 'Unsubscribed' ,
value : 'unsubscribed' ,
} ,
2019-11-14 15:44:07 -08:00
] ,
default : '' ,
2022-08-17 08:50:24 -07:00
description : "Subscriber's current status" ,
2019-11-14 15:44:07 -08:00
} ,
{
displayName : 'JSON Parameters' ,
name : 'jsonParameters' ,
type : 'boolean' ,
default : false ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'create' ] ,
2019-11-14 15:44:07 -08:00
} ,
} ,
} ,
{
displayName : 'Options' ,
name : 'options' ,
type : 'collection' ,
placeholder : 'Add Option' ,
default : { } ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'create' ] ,
2019-11-14 15:44:07 -08:00
} ,
} ,
options : [
{
displayName : 'Email Type' ,
name : 'emailType' ,
type : 'options' ,
options : [
{
2020-05-22 06:47:47 -07:00
name : 'HTML' ,
value : 'html' ,
2019-11-14 15:44:07 -08:00
} ,
{
name : 'Text' ,
value : 'text' ,
} ,
] ,
default : '' ,
description : 'Type of email this member asked to get' ,
} ,
{
2020-05-22 06:47:47 -07:00
displayName : 'Language' ,
name : 'language' ,
2019-11-14 15:44:07 -08:00
type : 'string' ,
default : '' ,
2022-08-17 08:50:24 -07:00
description : "If set/detected, the subscriber's language" ,
2019-11-14 15:44:07 -08:00
} ,
{
displayName : 'Opt-in IP' ,
name : 'ipOptIn' ,
type : 'string' ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'The IP address the subscriber used to confirm their opt-in status' ,
2019-11-14 15:44:07 -08:00
} ,
2020-05-22 06:47:47 -07:00
{
displayName : 'Signup IP' ,
name : 'ipSignup' ,
type : 'string' ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'IP address the subscriber signed up from' ,
2020-05-22 06:47:47 -07:00
} ,
2019-11-14 15:44:07 -08:00
{
displayName : 'Signup Timestamp' ,
name : 'timestampSignup' ,
type : 'dateTime' ,
default : '' ,
2022-08-17 08:50:24 -07:00
description :
'The date and time the subscriber signed up for the list in ISO 8601 format' ,
2019-11-14 15:44:07 -08:00
} ,
{
2020-05-22 06:47:47 -07:00
displayName : 'Tags' ,
name : 'tags' ,
2019-11-14 15:44:07 -08:00
type : 'string' ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'The tags that are associated with a member separeted by ,' ,
2019-11-14 15:44:07 -08:00
} ,
{
displayName : 'Vip' ,
name : 'vip' ,
type : 'boolean' ,
default : false ,
2022-06-20 07:54:01 -07:00
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
2022-05-06 14:01:25 -07:00
description : 'Vip status for subscribers' ,
2019-11-14 15:44:07 -08:00
} ,
{
displayName : 'Opt-in Timestamp' ,
name : 'timestampOpt' ,
type : 'dateTime' ,
default : '' ,
2022-08-17 08:50:24 -07:00
description :
'The date and time the subscribe confirmed their opt-in status in ISO 8601 format' ,
2019-11-14 15:44:07 -08:00
} ,
2020-05-22 06:47:47 -07:00
] ,
2019-11-14 15:44:07 -08:00
} ,
{
displayName : 'Location' ,
name : 'locationFieldsUi' ,
type : 'fixedCollection' ,
placeholder : 'Add Location' ,
2019-11-15 12:44:46 -08:00
default : { } ,
2022-05-06 14:01:25 -07:00
description : 'Subscriber location information.n' ,
2019-11-14 15:44:07 -08:00
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'create' ] ,
jsonParameters : [ false ] ,
2019-11-14 15:44:07 -08:00
} ,
} ,
options : [
{
name : 'locationFieldsValues' ,
displayName : 'Location' ,
values : [
{
displayName : 'Latitude' ,
name : 'latitude' ,
type : 'string' ,
required : true ,
2022-05-06 14:01:25 -07:00
description : 'The location latitude' ,
2019-11-15 12:44:46 -08:00
default : '' ,
2019-11-14 15:44:07 -08:00
} ,
{
displayName : 'Longitude' ,
name : 'longitude' ,
type : 'string' ,
required : true ,
2022-05-06 14:01:25 -07:00
description : 'The location longitude' ,
2019-11-15 12:44:46 -08:00
default : '' ,
2019-11-14 15:44:07 -08:00
} ,
] ,
2020-10-22 06:46:03 -07:00
} ,
2019-11-14 15:44:07 -08:00
] ,
} ,
{
displayName : 'Merge Fields' ,
name : 'mergeFieldsUi' ,
placeholder : 'Add Merge Fields' ,
type : 'fixedCollection' ,
2019-11-15 12:44:46 -08:00
default : { } ,
2019-11-14 15:44:07 -08:00
typeOptions : {
multipleValues : true ,
} ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'create' ] ,
jsonParameters : [ false ] ,
2019-11-14 15:44:07 -08:00
} ,
} ,
2022-05-06 14:01:25 -07:00
description : 'An individual merge var and value for a member' ,
2019-11-14 15:44:07 -08:00
options : [
{
name : 'mergeFieldsValues' ,
displayName : 'Field' ,
typeOptions : {
2019-11-15 12:44:46 -08:00
multipleValueButtonText : 'Add Field' ,
2019-11-14 15:44:07 -08:00
} ,
values : [
{
2022-06-03 10:23:49 -07:00
displayName : 'Field Name or ID' ,
2019-11-14 15:44:07 -08:00
name : 'name' ,
2020-05-22 06:47:47 -07:00
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getMergeFields' ,
2022-08-17 08:50:24 -07:00
loadOptionsDependsOn : [ 'list' ] ,
2020-05-22 06:47:47 -07:00
} ,
2019-11-14 15:44:07 -08:00
required : true ,
2022-08-17 08:50:24 -07:00
description :
'Merge Field name. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2019-11-15 12:44:46 -08:00
default : '' ,
2019-11-14 15:44:07 -08:00
} ,
{
2019-11-15 12:44:46 -08:00
displayName : 'Field Value' ,
2019-11-14 15:44:07 -08:00
name : 'value' ,
required : true ,
type : 'string' ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'Merge field value' ,
2019-11-14 15:44:07 -08:00
} ,
] ,
} ,
] ,
} ,
{
displayName : 'Merge Fields' ,
name : 'mergeFieldsJson' ,
type : 'json' ,
typeOptions : {
2019-11-15 12:44:46 -08:00
alwaysOpenEditWindow : true ,
2019-11-14 15:44:07 -08:00
} ,
default : '' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'create' ] ,
jsonParameters : [ true ] ,
2019-11-14 15:44:07 -08:00
} ,
} ,
} ,
{
displayName : 'Location' ,
name : 'locationJson' ,
type : 'json' ,
typeOptions : {
2019-11-15 12:44:46 -08:00
alwaysOpenEditWindow : true ,
2019-11-14 15:44:07 -08:00
} ,
default : '' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'create' ] ,
jsonParameters : [ true ] ,
2019-11-14 15:44:07 -08:00
} ,
} ,
} ,
2020-07-09 10:37:35 -07:00
{
displayName : 'Interest Groups' ,
name : 'groupsUi' ,
placeholder : 'Add Interest Group' ,
type : 'fixedCollection' ,
default : { } ,
typeOptions : {
multipleValues : true ,
} ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'create' ] ,
jsonParameters : [ false ] ,
2020-07-09 10:37:35 -07:00
} ,
} ,
options : [
{
name : 'groupsValues' ,
displayName : 'Group' ,
typeOptions : {
multipleValueButtonText : 'Add Interest Group' ,
} ,
values : [
{
2022-06-03 10:23:49 -07:00
displayName : 'Category Name or ID' ,
2020-07-09 10:37:35 -07:00
name : 'categoryId' ,
type : 'options' ,
2022-08-17 08:50:24 -07:00
description :
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>' ,
2020-07-09 10:37:35 -07:00
typeOptions : {
loadOptionsMethod : 'getGroupCategories' ,
2022-08-17 08:50:24 -07:00
loadOptionsDependsOn : [ 'list' ] ,
2020-07-09 10:37:35 -07:00
} ,
default : '' ,
} ,
{
displayName : 'Category Field ID' ,
name : 'categoryFieldId' ,
type : 'string' ,
default : '' ,
} ,
{
displayName : 'Value' ,
name : 'value' ,
type : 'boolean' ,
default : false ,
} ,
] ,
} ,
] ,
} ,
{
displayName : 'Interest Groups' ,
name : 'groupJson' ,
type : 'json' ,
typeOptions : {
alwaysOpenEditWindow : true ,
} ,
default : '' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'create' ] ,
jsonParameters : [ true ] ,
2020-07-09 10:37:35 -07:00
} ,
} ,
} ,
2022-08-17 08:50:24 -07:00
/* -------------------------------------------------------------------------- */
/* member:delete */
/* -------------------------------------------------------------------------- */
2020-05-22 06:47:47 -07:00
{
2022-06-03 10:23:49 -07:00
displayName : 'List Name or ID' ,
2020-05-22 06:47:47 -07:00
name : 'list' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getLists' ,
} ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'delete' ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
default : '' ,
options : [ ] ,
required : true ,
2022-08-17 08:50:24 -07:00
description :
'List of lists. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2019-11-12 12:48:45 -08:00
} ,
2020-05-22 06:47:47 -07:00
{
displayName : 'Email' ,
name : 'email' ,
type : 'string' ,
2022-06-20 07:54:01 -07:00
placeholder : 'name@email.com' ,
2020-05-22 06:47:47 -07:00
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'delete' ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
default : '' ,
required : true ,
2022-08-17 08:50:24 -07:00
description : "Member's email" ,
2020-05-22 06:47:47 -07:00
} ,
2022-08-17 08:50:24 -07:00
/* -------------------------------------------------------------------------- */
/* member:get */
/* -------------------------------------------------------------------------- */
2020-05-22 06:47:47 -07:00
{
2022-06-03 10:23:49 -07:00
displayName : 'List Name or ID' ,
2020-05-22 06:47:47 -07:00
name : 'list' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getLists' ,
} ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'get' ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
default : '' ,
options : [ ] ,
required : true ,
2022-08-17 08:50:24 -07:00
description :
'List of lists. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2020-05-22 06:47:47 -07:00
} ,
{
displayName : 'Email' ,
name : 'email' ,
type : 'string' ,
2022-06-20 07:54:01 -07:00
placeholder : 'name@email.com' ,
2020-05-22 06:47:47 -07:00
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'get' ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
default : '' ,
required : true ,
2022-08-17 08:50:24 -07:00
description : "Member's email" ,
2020-05-22 06:47:47 -07:00
} ,
{
displayName : 'Options' ,
name : 'options' ,
type : 'collection' ,
placeholder : 'Add Option' ,
default : { } ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'get' ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
options : [
{
displayName : 'Fields' ,
name : 'fields' ,
type : 'string' ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'A comma-separated list of fields to return' ,
2020-05-22 06:47:47 -07:00
} ,
{
displayName : 'Exclude Fields' ,
name : 'excludeFields' ,
type : 'string' ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'A comma-separated list of fields to exclude' ,
2020-05-22 06:47:47 -07:00
} ,
2020-10-22 06:46:03 -07:00
] ,
2020-05-22 06:47:47 -07:00
} ,
2022-08-17 08:50:24 -07:00
/* -------------------------------------------------------------------------- */
/* member:getAll */
/* -------------------------------------------------------------------------- */
2020-05-22 06:47:47 -07:00
{
2022-06-03 10:23:49 -07:00
displayName : 'List Name or ID' ,
2020-05-22 06:47:47 -07:00
name : 'list' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getLists' ,
} ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'getAll' ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
default : '' ,
options : [ ] ,
required : true ,
2022-08-17 08:50:24 -07:00
description :
'List of lists. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2020-05-22 06:47:47 -07:00
} ,
{
displayName : 'Return All' ,
name : 'returnAll' ,
type : 'boolean' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'getAll' ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
default : false ,
2022-05-06 14:01:25 -07:00
description : 'Whether to return all results or only up to a given limit' ,
2020-05-22 06:47:47 -07:00
} ,
{
displayName : 'Limit' ,
name : 'limit' ,
type : 'number' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'getAll' ] ,
returnAll : [ false ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
typeOptions : {
minValue : 1 ,
maxValue : 1000 ,
} ,
default : 500 ,
2022-05-06 14:01:25 -07:00
description : 'Max number of results to return' ,
2020-05-22 06:47:47 -07:00
} ,
{
displayName : 'Options' ,
name : 'options' ,
type : 'collection' ,
placeholder : 'Add Option' ,
default : { } ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'getAll' ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
options : [
{
displayName : 'Before Last Changed' ,
name : 'beforeLastChanged' ,
type : 'dateTime' ,
default : '' ,
2022-08-17 08:50:24 -07:00
description :
'Restrict results to subscribers whose information changed before the set timeframe' ,
2020-05-22 06:47:47 -07:00
} ,
{
displayName : 'Before Timestamp Opt' ,
name : 'beforeTimestampOpt' ,
type : 'dateTime' ,
default : '' ,
description : 'Restrict results to subscribers who opted-in before the set timeframe' ,
} ,
// {
// displayName: 'Fields',
// name: 'fields',
// type: 'string',
// default: '',
// description: 'A comma-separated list of fields to return.',
// },
// {
// displayName: 'Exclude Fields',
// name: 'excludeFields',
// type: 'string',
// default: '',
// description: 'A comma-separated list of fields to exclude.',
// },
{
displayName : 'Email Type' ,
name : 'emailType' ,
type : 'options' ,
options : [
{
name : 'HTML' ,
value : 'html' ,
} ,
{
name : 'Text' ,
value : 'text' ,
} ,
] ,
default : '' ,
description : 'Type of email this member asked to get' ,
} ,
{
displayName : 'Status' ,
name : 'status' ,
type : 'options' ,
options : [
{
name : 'Cleaned' ,
value : 'cleaned' ,
} ,
{
name : 'Pending' ,
value : 'pending' ,
} ,
2022-06-03 10:23:49 -07:00
{
name : 'Subscribed' ,
value : 'subscribed' ,
} ,
2020-05-22 06:47:47 -07:00
{
name : 'Transactional' ,
value : 'transactional' ,
} ,
2022-06-03 10:23:49 -07:00
{
name : 'Unsubscribed' ,
value : 'unsubscribed' ,
} ,
2020-05-22 06:47:47 -07:00
] ,
default : '' ,
2022-08-17 08:50:24 -07:00
description : "Subscriber's current status" ,
2020-05-22 06:47:47 -07:00
} ,
{
displayName : 'Since Last Changed' ,
name : 'sinceLastChanged' ,
type : 'dateTime' ,
default : '' ,
2022-08-17 08:50:24 -07:00
description :
'Restrict results to subscribers whose information changed after the set timeframe' ,
2020-05-22 06:47:47 -07:00
} ,
] ,
} ,
2022-08-17 08:50:24 -07:00
/* -------------------------------------------------------------------------- */
/* member:update */
/* -------------------------------------------------------------------------- */
2020-05-22 06:47:47 -07:00
{
2022-06-03 10:23:49 -07:00
displayName : 'List Name or ID' ,
2020-05-22 06:47:47 -07:00
name : 'list' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getLists' ,
} ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'update' ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
default : '' ,
options : [ ] ,
required : true ,
2022-08-17 08:50:24 -07:00
description :
'List of lists. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2020-05-22 06:47:47 -07:00
} ,
{
displayName : 'Email' ,
name : 'email' ,
type : 'string' ,
2022-06-20 07:54:01 -07:00
placeholder : 'name@email.com' ,
2020-05-22 06:47:47 -07:00
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'update' ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'Email address of the subscriber' ,
2020-05-22 06:47:47 -07:00
} ,
{
displayName : 'JSON Parameters' ,
name : 'jsonParameters' ,
type : 'boolean' ,
default : false ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'update' ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
} ,
{
displayName : 'Update Fields' ,
name : 'updateFields' ,
type : 'collection' ,
placeholder : 'Add Field' ,
default : { } ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'update' ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
options : [
{
displayName : 'Email Type' ,
name : 'emailType' ,
type : 'options' ,
options : [
{
name : 'HTML' ,
value : 'html' ,
} ,
{
name : 'Text' ,
value : 'text' ,
} ,
] ,
default : '' ,
description : 'Type of email this member asked to get' ,
} ,
2020-07-09 10:37:35 -07:00
{
displayName : 'Interest Groups' ,
name : 'groupsUi' ,
placeholder : 'Add Interest Group' ,
type : 'fixedCollection' ,
default : { } ,
typeOptions : {
multipleValues : true ,
} ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
'/resource' : [ 'member' ] ,
'/operation' : [ 'update' ] ,
'/jsonParameters' : [ false ] ,
2020-07-09 10:37:35 -07:00
} ,
} ,
options : [
{
name : 'groupsValues' ,
displayName : 'Group' ,
typeOptions : {
multipleValueButtonText : 'Add Interest Group' ,
} ,
values : [
{
2022-06-03 10:23:49 -07:00
displayName : 'Category Name or ID' ,
2020-07-09 10:37:35 -07:00
name : 'categoryId' ,
type : 'options' ,
2022-08-17 08:50:24 -07:00
description :
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>' ,
2020-07-09 10:37:35 -07:00
typeOptions : {
loadOptionsMethod : 'getGroupCategories' ,
2022-08-17 08:50:24 -07:00
loadOptionsDependsOn : [ 'list' ] ,
2020-07-09 10:37:35 -07:00
} ,
default : '' ,
} ,
{
displayName : 'Category Field ID' ,
name : 'categoryFieldId' ,
type : 'string' ,
default : '' ,
} ,
{
displayName : 'Value' ,
name : 'value' ,
type : 'boolean' ,
default : false ,
} ,
] ,
} ,
] ,
} ,
2020-05-22 06:47:47 -07:00
{
displayName : 'Language' ,
name : 'language' ,
type : 'string' ,
default : '' ,
2022-08-17 08:50:24 -07:00
description : "If set/detected, the subscriber's language" ,
2020-05-22 06:47:47 -07:00
} ,
{
displayName : 'Merge Fields' ,
name : 'mergeFieldsUi' ,
placeholder : 'Add Merge Fields' ,
type : 'fixedCollection' ,
default : { } ,
typeOptions : {
multipleValues : true ,
} ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
'/resource' : [ 'member' ] ,
'/operation' : [ 'update' ] ,
'/jsonParameters' : [ false ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
2022-05-06 14:01:25 -07:00
description : 'An individual merge var and value for a member' ,
2020-05-22 06:47:47 -07:00
options : [
{
name : 'mergeFieldsValues' ,
displayName : 'Field' ,
typeOptions : {
multipleValueButtonText : 'Add Field' ,
} ,
values : [
{
2022-06-03 10:23:49 -07:00
displayName : 'Field Name or ID' ,
2020-05-22 06:47:47 -07:00
name : 'name' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getMergeFields' ,
2022-08-17 08:50:24 -07:00
loadOptionsDependsOn : [ 'list' ] ,
2020-05-22 06:47:47 -07:00
} ,
required : true ,
2022-08-17 08:50:24 -07:00
description :
'Merge Field name. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2020-05-22 06:47:47 -07:00
default : '' ,
} ,
{
displayName : 'Field Value' ,
name : 'value' ,
required : true ,
type : 'string' ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'Merge field value' ,
2020-05-22 06:47:47 -07:00
} ,
] ,
} ,
] ,
} ,
{
displayName : 'Opt-in IP' ,
name : 'ipOptIn' ,
type : 'string' ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'The IP address the subscriber used to confirm their opt-in status' ,
2020-05-22 06:47:47 -07:00
} ,
{
displayName : 'Signup IP' ,
name : 'ipSignup' ,
type : 'string' ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'IP address the subscriber signed up from' ,
2020-05-22 06:47:47 -07:00
} ,
{
displayName : 'Signup Timestamp' ,
name : 'timestampSignup' ,
type : 'dateTime' ,
default : '' ,
2022-08-17 08:50:24 -07:00
description :
'The date and time the subscriber signed up for the list in ISO 8601 format' ,
2020-05-22 06:47:47 -07:00
} ,
{
displayName : 'Skip Merge Validation' ,
name : 'skipMergeValidation' ,
type : 'boolean' ,
default : false ,
2022-08-17 08:50:24 -07:00
description :
'Whether member data will be accepted without merge field values, even if the merge field is usually required' ,
2020-05-22 06:47:47 -07:00
} ,
{
displayName : 'Status' ,
name : 'status' ,
type : 'options' ,
options : [
{
name : 'Cleaned' ,
value : 'cleaned' ,
} ,
{
name : 'Pending' ,
value : 'pending' ,
} ,
2022-06-03 10:23:49 -07:00
{
name : 'Subscribed' ,
value : 'subscribed' ,
} ,
2020-05-22 06:47:47 -07:00
{
name : 'Transactional' ,
value : 'transactional' ,
} ,
2022-06-03 10:23:49 -07:00
{
name : 'Unsubscribed' ,
value : 'unsubscribed' ,
} ,
2020-05-22 06:47:47 -07:00
] ,
default : '' ,
2022-08-17 08:50:24 -07:00
description : "Subscriber's current status" ,
2020-05-22 06:47:47 -07:00
} ,
{
displayName : 'Vip' ,
name : 'vip' ,
type : 'boolean' ,
default : false ,
2022-06-20 07:54:01 -07:00
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
2022-05-06 14:01:25 -07:00
description : 'Vip status for subscribers' ,
2020-05-22 06:47:47 -07:00
} ,
{
displayName : 'Location' ,
name : 'locationFieldsUi' ,
type : 'fixedCollection' ,
placeholder : 'Add Location' ,
default : { } ,
2022-05-06 14:01:25 -07:00
description : 'Subscriber location information.n' ,
2020-05-22 06:47:47 -07:00
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
'/resource' : [ 'member' ] ,
'/operation' : [ 'update' ] ,
'/jsonParameters' : [ false ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
options : [
{
name : 'locationFieldsValues' ,
displayName : 'Location' ,
values : [
{
displayName : 'Latitude' ,
name : 'latitude' ,
type : 'string' ,
required : true ,
2022-05-06 14:01:25 -07:00
description : 'The location latitude' ,
2020-05-22 06:47:47 -07:00
default : '' ,
} ,
{
displayName : 'Longitude' ,
name : 'longitude' ,
type : 'string' ,
required : true ,
2022-05-06 14:01:25 -07:00
description : 'The location longitude' ,
2020-05-22 06:47:47 -07:00
default : '' ,
} ,
] ,
} ,
] ,
} ,
{
displayName : 'Opt-in Timestamp' ,
name : 'timestampOpt' ,
type : 'dateTime' ,
default : '' ,
2022-08-17 08:50:24 -07:00
description :
'The date and time the subscribe confirmed their opt-in status in ISO 8601 format' ,
2020-05-22 06:47:47 -07:00
} ,
] ,
} ,
{
displayName : 'Merge Fields' ,
name : 'mergeFieldsJson' ,
type : 'json' ,
typeOptions : {
alwaysOpenEditWindow : true ,
} ,
default : '' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'update' ] ,
jsonParameters : [ true ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
} ,
{
displayName : 'Location' ,
name : 'locationJson' ,
type : 'json' ,
typeOptions : {
alwaysOpenEditWindow : true ,
} ,
default : '' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'update' ] ,
jsonParameters : [ true ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
} ,
2020-07-09 10:37:35 -07:00
{
displayName : 'Interest Groups' ,
name : 'groupJson' ,
type : 'json' ,
typeOptions : {
alwaysOpenEditWindow : true ,
} ,
default : '' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'member' ] ,
operation : [ 'update' ] ,
jsonParameters : [ true ] ,
2020-07-09 10:37:35 -07:00
} ,
} ,
} ,
2022-08-17 08:50:24 -07:00
/* -------------------------------------------------------------------------- */
/* memberTag:create */
/* -------------------------------------------------------------------------- */
2020-05-22 06:47:47 -07:00
{
2022-06-03 10:23:49 -07:00
displayName : 'List Name or ID' ,
2020-05-22 06:47:47 -07:00
name : 'list' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getLists' ,
} ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'memberTag' ] ,
operation : [ 'create' , 'delete' ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
default : '' ,
options : [ ] ,
required : true ,
2022-08-17 08:50:24 -07:00
description :
'List of lists. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2020-05-22 06:47:47 -07:00
} ,
{
displayName : 'Email' ,
name : 'email' ,
type : 'string' ,
2022-06-20 07:54:01 -07:00
placeholder : 'name@email.com' ,
2020-05-22 06:47:47 -07:00
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'memberTag' ] ,
operation : [ 'create' , 'delete' ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'Email address of the subscriber' ,
2020-05-22 06:47:47 -07:00
} ,
{
displayName : 'Tags' ,
name : 'tags' ,
type : 'string' ,
typeOptions : {
multipleValues : true ,
multipleValueButtonText : 'Add Tag' ,
} ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'memberTag' ] ,
operation : [ 'create' , 'delete' ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
default : [ ] ,
} ,
{
displayName : 'Options' ,
name : 'options' ,
type : 'collection' ,
placeholder : 'Add Option' ,
default : { } ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'memberTag' ] ,
operation : [ 'create' , 'delete' ] ,
2020-05-22 06:47:47 -07:00
} ,
} ,
options : [
{
displayName : 'Is Syncing' ,
name : 'isSyncing' ,
type : 'boolean' ,
default : false ,
2022-06-20 07:54:01 -07:00
description : 'Whether automations based on the tags in the request will not fire' ,
2020-05-22 06:47:47 -07:00
} ,
] ,
} ,
2022-08-17 08:50:24 -07:00
/* -------------------------------------------------------------------------- */
/* member:getAll */
/* -------------------------------------------------------------------------- */
2020-07-09 10:37:35 -07:00
{
2022-06-03 10:23:49 -07:00
displayName : 'List Name or ID' ,
2020-07-09 10:37:35 -07:00
name : 'list' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getLists' ,
} ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'listGroup' ] ,
operation : [ 'getAll' ] ,
2020-07-09 10:37:35 -07:00
} ,
} ,
default : '' ,
options : [ ] ,
required : true ,
2022-08-17 08:50:24 -07:00
description :
'List of lists. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2020-07-09 10:37:35 -07:00
} ,
{
2022-06-03 10:23:49 -07:00
displayName : 'Group Category Name or ID' ,
2020-07-09 10:37:35 -07:00
name : 'groupCategory' ,
type : 'options' ,
2022-08-17 08:50:24 -07:00
description :
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>' ,
2020-07-09 10:37:35 -07:00
typeOptions : {
loadOptionsMethod : 'getGroupCategories' ,
2022-08-17 08:50:24 -07:00
loadOptionsDependsOn : [ 'list' ] ,
2020-07-09 10:37:35 -07:00
} ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'listGroup' ] ,
operation : [ 'getAll' ] ,
2020-07-09 10:37:35 -07:00
} ,
} ,
default : '' ,
options : [ ] ,
required : true ,
} ,
{
displayName : 'Return All' ,
name : 'returnAll' ,
type : 'boolean' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'listGroup' ] ,
operation : [ 'getAll' ] ,
2020-07-09 10:37:35 -07:00
} ,
} ,
default : false ,
2022-05-06 14:01:25 -07:00
description : 'Whether to return all results or only up to a given limit' ,
2020-07-09 10:37:35 -07:00
} ,
{
displayName : 'Limit' ,
name : 'limit' ,
type : 'number' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'listGroup' ] ,
operation : [ 'getAll' ] ,
returnAll : [ false ] ,
2020-07-09 10:37:35 -07:00
} ,
} ,
typeOptions : {
minValue : 1 ,
maxValue : 1000 ,
} ,
default : 500 ,
2022-05-06 14:01:25 -07:00
description : 'Max number of results to return' ,
2020-07-09 10:37:35 -07:00
} ,
2022-08-17 08:50:24 -07:00
/* -------------------------------------------------------------------------- */
/* campaign:getAll */
/* -------------------------------------------------------------------------- */
2020-10-02 15:45:58 -07:00
{
displayName : 'Return All' ,
name : 'returnAll' ,
type : 'boolean' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'campaign' ] ,
operation : [ 'getAll' ] ,
2020-10-02 15:45:58 -07:00
} ,
} ,
default : false ,
2022-05-06 14:01:25 -07:00
description : 'Whether to return all results or only up to a given limit' ,
2020-10-02 15:45:58 -07:00
} ,
{
displayName : 'Limit' ,
name : 'limit' ,
type : 'number' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'campaign' ] ,
operation : [ 'getAll' ] ,
returnAll : [ false ] ,
2020-10-02 15:45:58 -07:00
} ,
} ,
typeOptions : {
minValue : 1 ,
maxValue : 1000 ,
} ,
default : 10 ,
2022-05-06 14:01:25 -07:00
description : 'Max number of results to return' ,
2020-10-02 15:45:58 -07:00
} ,
{
displayName : 'Options' ,
name : 'options' ,
type : 'collection' ,
placeholder : 'Add Option' ,
default : { } ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'campaign' ] ,
operation : [ 'getAll' ] ,
2020-10-02 15:45:58 -07:00
} ,
} ,
options : [
{
displayName : 'Before Create Time' ,
name : 'beforeCreateTime' ,
type : 'dateTime' ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'Restrict the response to campaigns created before the set time' ,
2020-10-02 15:45:58 -07:00
} ,
{
displayName : 'Before Send Time' ,
name : 'beforeSendTime' ,
type : 'dateTime' ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'Restrict the response to campaigns sent before the set time' ,
2020-10-02 15:45:58 -07:00
} ,
{
2022-06-20 07:54:01 -07:00
displayName : 'Exclude Field Names or IDs' ,
2020-10-02 15:45:58 -07:00
name : 'excludeFields' ,
2020-10-05 15:44:52 -07:00
type : 'multiOptions' ,
typeOptions : {
loadOptionsMethod : 'getCampaignsFields' ,
} ,
default : [ ] ,
2022-08-17 08:50:24 -07:00
description :
'A comma-separated list of fields to exclude. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2020-10-02 15:45:58 -07:00
} ,
{
2022-06-20 07:54:01 -07:00
displayName : 'Field Names or IDs' ,
2020-10-02 15:45:58 -07:00
name : 'fields' ,
2020-10-05 15:44:52 -07:00
type : 'multiOptions' ,
typeOptions : {
loadOptionsMethod : 'getCampaignsFields' ,
} ,
default : [
'campaigns.id' ,
2020-10-07 11:21:58 -07:00
'campaigns.status' ,
'campaigns.tracking' ,
'campaigns.settings.from_name' ,
'campaigns.settings.reply_to' ,
'campaigns.settings.title' ,
2020-10-05 15:44:52 -07:00
] ,
2022-08-17 08:50:24 -07:00
description :
'A comma-separated list of fields to return. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2020-10-02 15:45:58 -07:00
} ,
{
2022-06-03 10:23:49 -07:00
displayName : 'List Name or ID' ,
2020-10-02 15:45:58 -07:00
name : 'listId' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getLists' ,
} ,
default : '' ,
2022-08-17 08:50:24 -07:00
description :
'List of lists. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2020-10-02 15:45:58 -07:00
} ,
{
displayName : 'Since Create Time' ,
name : 'sinceCreateTime' ,
type : 'dateTime' ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'Restrict the response to campaigns created after the set time' ,
2020-10-02 15:45:58 -07:00
} ,
{
displayName : 'Since Send Time' ,
name : 'sinceSendTime' ,
type : 'dateTime' ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'Restrict the response to campaigns sent after the set time' ,
2020-10-02 15:45:58 -07:00
} ,
2020-10-05 15:44:52 -07:00
{
displayName : 'Sort Direction' ,
name : 'sortDirection' ,
type : 'options' ,
options : [
{
name : 'ASC' ,
value : 'ASC' ,
} ,
{
name : 'DESC' ,
value : 'DESC' ,
} ,
] ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'Determines the order direction for sorted results' ,
2020-10-05 15:44:52 -07:00
} ,
{
displayName : 'Sort Field' ,
name : 'sortField' ,
type : 'options' ,
options : [
{
name : 'Create Time' ,
value : 'create_time' ,
} ,
{
name : 'Send Time' ,
value : 'send_time' ,
} ,
] ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'Returns files sorted by the specified field' ,
2020-10-05 15:44:52 -07:00
} ,
2020-10-02 15:45:58 -07:00
{
displayName : 'Status' ,
name : 'status' ,
type : 'options' ,
options : [
{
name : 'Save' ,
value : 'save' ,
} ,
{
name : 'Sending' ,
value : 'sending' ,
} ,
{
name : 'Sent' ,
value : 'sent' ,
} ,
{
name : 'Schedule' ,
value : 'schedule' ,
} ,
] ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'The status of the campaign' ,
2020-10-02 15:45:58 -07:00
} ,
] ,
} ,
2022-08-17 08:50:24 -07:00
/* -------------------------------------------------------------------------- */
/* campaign:send */
/* -------------------------------------------------------------------------- */
2020-10-02 15:45:58 -07:00
{
displayName : 'Campaign ID' ,
name : 'campaignId' ,
2020-10-05 15:44:52 -07:00
type : 'string' ,
2020-10-02 15:45:58 -07:00
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'campaign' ] ,
operation : [ 'send' , 'get' , 'delete' , 'replicate' , 'resend' ] ,
2020-10-22 06:46:03 -07:00
} ,
2020-10-02 15:45:58 -07:00
} ,
required : true ,
default : '' ,
description : 'List of Campaigns' ,
2022-08-17 08:50:24 -07:00
options : [ ] ,
2020-10-02 15:45:58 -07:00
} ,
2020-05-22 06:47:47 -07:00
] ,
} ;
methods = {
loadOptions : {
// Get all the available lists to display them to user so that he can
// select them easily
async getLists ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
2020-07-09 10:37:35 -07:00
const lists = await mailchimpApiRequestAllItems . call ( this , '/lists' , 'GET' , 'lists' ) ;
2020-05-22 06:47:47 -07:00
for ( const list of lists ) {
const listName = list . name ;
const listId = list . id ;
returnData . push ( {
name : listName ,
value : listId ,
} ) ;
}
return returnData ;
} ,
// Get all the available merge fields to display them to user so that he can
// select them easily
async getMergeFields ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
const listId = this . getCurrentNodeParameter ( 'list' ) ;
2022-08-17 08:50:24 -07:00
const { merge_fields } = await mailchimpApiRequest . call (
this ,
` /lists/ ${ listId } /merge-fields ` ,
'GET' ,
) ;
2020-05-22 06:47:47 -07:00
for ( const mergeField of merge_fields ) {
const mergeFieldName = mergeField . name ;
const mergeFieldId = mergeField . tag ;
returnData . push ( {
name : mergeFieldName ,
value : mergeFieldId ,
} ) ;
}
return returnData ;
} ,
2020-07-09 10:37:35 -07:00
// 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' ) ;
2022-08-17 08:50:24 -07:00
const { categories } = await mailchimpApiRequest . call (
this ,
` /lists/ ${ listId } /interest-categories ` ,
'GET' ,
) ;
2020-07-09 10:37:35 -07:00
for ( const category of categories ) {
const categoryName = category . title ;
const categoryId = category . id ;
returnData . push ( {
name : categoryName ,
value : categoryId ,
} ) ;
}
return returnData ;
} ,
2020-10-02 15:45:58 -07:00
// Get all the available campaigns to display them to users so that they can select them easily
async getCampaigns ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
2022-08-17 08:50:24 -07:00
const campaigns = await mailchimpApiRequestAllItems . call (
this ,
'/campaigns' ,
'GET' ,
'campaigns' ,
) ;
2020-10-02 15:45:58 -07:00
for ( const campaign of campaigns ) {
const campaignName = campaign . settings . title ;
const campaignId = campaign . id ;
returnData . push ( {
name : campaignName ,
value : campaignId ,
} ) ;
}
2020-10-05 15:44:52 -07:00
return returnData ;
} ,
// Get all the available fields to display them to users so that they can select them easily
async getCampaignsFields ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
for ( const campaignFields of campaignFieldsMetadata ) {
returnData . push ( {
name : campaignFields ,
value : campaignFields ,
} ) ;
}
return returnData ;
2020-10-22 06:46:03 -07:00
} ,
2020-10-05 15:44:52 -07:00
} ,
2020-05-22 06:47:47 -07:00
} ;
async execute ( this : IExecuteFunctions ) : Promise < INodeExecutionData [ ] [ ] > {
const items = this . getInputData ( ) ;
2022-08-30 08:55:33 -07:00
const returnData : INodeExecutionData [ ] = [ ] ;
2022-04-22 09:29:51 -07:00
const length = items . length ;
2020-05-22 06:47:47 -07:00
let responseData ;
const qs : IDataObject = { } ;
2022-12-02 03:53:59 -08:00
const resource = this . getNodeParameter ( 'resource' , 0 ) ;
const operation = this . getNodeParameter ( 'operation' , 0 ) ;
2020-05-22 06:47:47 -07:00
for ( let i = 0 ; i < length ; i ++ ) {
2021-07-19 23:58:54 -07:00
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 ;
2022-11-18 05:31:38 -08:00
const returnAll = this . getNodeParameter ( 'returnAll' , i ) ;
2020-07-09 10:37:35 -07:00
2022-12-02 12:54:28 -08:00
if ( returnAll ) {
2022-08-17 08:50:24 -07:00
responseData = await mailchimpApiRequestAllItems . call (
this ,
` /lists/ ${ listId } /interest-categories/ ${ categoryId } /interests ` ,
'GET' ,
'interests' ,
{ } ,
qs ,
) ;
2021-07-19 23:58:54 -07:00
} else {
2022-11-18 06:26:22 -08:00
qs . count = this . getNodeParameter ( 'limit' , i ) ;
2022-08-17 08:50:24 -07:00
responseData = await mailchimpApiRequest . call (
this ,
` /lists/ ${ listId } /interest-categories/ ${ categoryId } /interests ` ,
'GET' ,
{ } ,
qs ,
) ;
2021-07-19 23:58:54 -07:00
responseData = responseData . interests ;
}
2020-07-09 10:37:35 -07:00
}
}
2021-07-19 23:58:54 -07:00
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 ;
2022-11-18 07:29:44 -08:00
const options = this . getNodeParameter ( 'options' , i ) ;
2022-11-18 05:31:38 -08:00
const jsonActive = this . getNodeParameter ( 'jsonParameters' , i ) ;
2020-05-22 06:47:47 -07:00
2021-07-19 23:58:54 -07:00
const body : ICreateMemberBody = {
listId ,
email_address : email ,
status ,
} ;
if ( options . emailType ) {
body . email_type = options . emailType as string ;
2020-05-22 06:47:47 -07:00
}
2021-07-19 23:58:54 -07:00
if ( options . language ) {
body . language = options . language as string ;
2020-05-22 06:47:47 -07:00
}
2021-07-19 23:58:54 -07:00
if ( options . vip ) {
body . vip = options . vip as boolean ;
2020-07-09 10:37:35 -07:00
}
2021-07-19 23:58:54 -07:00
if ( options . ipSignup ) {
body . ip_signup = options . ipSignup as string ;
2020-05-22 06:47:47 -07:00
}
2021-07-19 23:58:54 -07:00
if ( options . ipOptIn ) {
body . ip_opt = options . ipOptIn as string ;
2020-05-22 06:47:47 -07:00
}
2021-07-19 23:58:54 -07:00
if ( options . timestampOpt ) {
2022-08-17 08:50:24 -07:00
body . timestamp_opt = moment ( options . timestampOpt as string ) . format (
'YYYY-MM-DD HH:MM:SS' ,
2022-12-02 12:54:28 -08:00
) ;
2020-07-09 10:37:35 -07:00
}
2021-07-19 23:58:54 -07:00
if ( options . timestampSignup ) {
2022-08-17 08:50:24 -07:00
body . timestamp_signup = moment ( options . timestampSignup as string ) . format (
'YYYY-MM-DD HH:MM:SS' ,
2022-12-02 12:54:28 -08:00
) ;
2021-07-19 23:58:54 -07:00
}
if ( options . tags ) {
// @ts-ignore
body . tags = options . tags . split ( ',' ) as string [ ] ;
}
if ( ! jsonActive ) {
2022-08-17 08:50:24 -07:00
const locationValues = ( this . getNodeParameter ( 'locationFieldsUi' , i ) as IDataObject )
. locationFieldsValues as IDataObject ;
2020-05-22 06:47:47 -07:00
if ( locationValues ) {
const location : ILocation = { } ;
for ( const key of Object . keys ( locationValues ) ) {
if ( key === 'latitude' ) {
2022-12-02 12:54:28 -08:00
location . latitude = parseFloat ( locationValues [ key ] as string ) ;
2020-05-22 06:47:47 -07:00
} else if ( key === 'longitude' ) {
2022-12-02 12:54:28 -08:00
location . longitude = parseFloat ( locationValues [ key ] as string ) ;
2020-05-22 06:47:47 -07:00
}
}
body . location = location ;
}
2022-08-17 08:50:24 -07:00
const mergeFieldsValues = ( this . getNodeParameter ( 'mergeFieldsUi' , i ) as IDataObject )
. mergeFieldsValues as IDataObject [ ] ;
2020-05-22 06:47:47 -07:00
if ( mergeFieldsValues ) {
const mergeFields = { } ;
2022-12-02 12:54:28 -08:00
for ( let index = 0 ; index < mergeFieldsValues . length ; index ++ ) {
2020-05-22 06:47:47 -07:00
// @ts-ignore
2022-12-02 12:54:28 -08:00
mergeFields [ mergeFieldsValues [ index ] . name ] = mergeFieldsValues [ index ] . value ;
2020-05-22 06:47:47 -07:00
}
body . merge_fields = mergeFields ;
}
2021-07-19 23:58:54 -07:00
2022-08-17 08:50:24 -07:00
const groupsValues = ( this . getNodeParameter ( 'groupsUi' , i ) as IDataObject )
. groupsValues as IDataObject [ ] ;
2020-07-09 10:37:35 -07:00
if ( groupsValues ) {
const groups = { } ;
2022-12-02 12:54:28 -08:00
for ( let index = 0 ; index < groupsValues . length ; index ++ ) {
2020-07-09 10:37:35 -07:00
// @ts-ignore
2022-12-02 12:54:28 -08:00
groups [ groupsValues [ index ] . categoryFieldId ] = groupsValues [ index ] . value ;
2020-07-09 10:37:35 -07:00
}
body . interests = groups ;
}
2021-07-19 23:58:54 -07:00
} else {
const locationJson = validateJSON ( this . getNodeParameter ( 'locationJson' , i ) as string ) ;
2022-08-17 08:50:24 -07:00
const mergeFieldsJson = validateJSON (
this . getNodeParameter ( 'mergeFieldsJson' , i ) as string ,
) ;
2021-07-19 23:58:54 -07:00
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 ;
}
2020-07-09 10:37:35 -07:00
}
2022-08-17 08:50:24 -07:00
responseData = await mailchimpApiRequest . call (
this ,
` /lists/ ${ listId } /members ` ,
'POST' ,
body ,
) ;
2021-07-19 23:58:54 -07:00
}
//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 ;
2022-08-17 08:50:24 -07:00
responseData = await mailchimpApiRequest . call (
this ,
` /lists/ ${ listId } /members/ ${ email } /actions/delete-permanent ` ,
'POST' ,
) ;
2021-07-19 23:58:54 -07:00
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 ;
2022-11-18 07:29:44 -08:00
const options = this . getNodeParameter ( 'options' , i ) ;
2021-07-19 23:58:54 -07:00
if ( options . fields ) {
qs . fields = options . fields as string ;
2020-05-22 06:47:47 -07:00
}
2021-07-19 23:58:54 -07:00
if ( options . excludeFields ) {
qs . exclude_fields = options . excludeFields as string ;
2020-07-09 10:37:35 -07:00
}
2021-07-19 23:58:54 -07:00
2022-08-17 08:50:24 -07:00
responseData = await mailchimpApiRequest . call (
this ,
` /lists/ ${ listId } /members/ ${ email } ` ,
'GET' ,
{ } ,
qs ,
) ;
2020-05-22 06:47:47 -07:00
}
2021-07-19 23:58:54 -07:00
//https://mailchimp.com/developer/reference/lists/list-members/#get_/lists/-list_id-/members
if ( operation === 'getAll' ) {
const listId = this . getNodeParameter ( 'list' , i ) as string ;
2022-11-18 05:31:38 -08:00
const returnAll = this . getNodeParameter ( 'returnAll' , i ) ;
2022-11-18 07:29:44 -08:00
const options = this . getNodeParameter ( 'options' , i ) ;
2020-05-22 06:47:47 -07:00
2021-07-19 23:58:54 -07:00
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
2020-05-22 06:47:47 -07:00
2021-07-19 23:58:54 -07:00
// 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 ;
}
2022-12-02 12:54:28 -08:00
if ( returnAll ) {
2022-08-17 08:50:24 -07:00
responseData = await mailchimpApiRequestAllItems . call (
this ,
` /lists/ ${ listId } /members ` ,
'GET' ,
'members' ,
{ } ,
qs ,
) ;
2021-07-19 23:58:54 -07:00
} else {
2022-11-18 06:26:22 -08:00
qs . count = this . getNodeParameter ( 'limit' , i ) ;
2022-08-17 08:50:24 -07:00
responseData = await mailchimpApiRequest . call (
this ,
` /lists/ ${ listId } /members ` ,
'GET' ,
{ } ,
qs ,
) ;
2021-07-19 23:58:54 -07:00
responseData = responseData . members ;
}
2020-05-22 06:47:47 -07:00
}
2021-07-19 23:58:54 -07:00
//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 ;
2022-11-18 07:29:44 -08:00
const updateFields = this . getNodeParameter ( 'updateFields' , i ) ;
2022-11-18 05:31:38 -08:00
const jsonActive = this . getNodeParameter ( 'jsonParameters' , i ) ;
2021-07-19 23:58:54 -07:00
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 ) {
2022-08-17 08:50:24 -07:00
body . timestamp_opt = moment ( updateFields . timestampOpt as string ) . format (
'YYYY-MM-DD HH:MM:SS' ,
2022-12-02 12:54:28 -08:00
) ;
2021-07-19 23:58:54 -07:00
}
if ( updateFields . timestampSignup ) {
2022-08-17 08:50:24 -07:00
body . timestamp_signup = moment ( updateFields . timestampSignup as string ) . format (
'YYYY-MM-DD HH:MM:SS' ,
2022-12-02 12:54:28 -08:00
) ;
2021-07-19 23:58:54 -07:00
}
if ( ! jsonActive ) {
if ( updateFields . locationFieldsUi ) {
2022-08-17 08:50:24 -07:00
const locationValues = ( updateFields . locationFieldsUi as IDataObject )
. locationFieldsValues as IDataObject ;
2021-07-19 23:58:54 -07:00
if ( locationValues ) {
const location : ILocation = { } ;
for ( const key of Object . keys ( locationValues ) ) {
if ( key === 'latitude' ) {
2022-12-02 12:54:28 -08:00
location . latitude = parseFloat ( locationValues [ key ] as string ) ;
2021-07-19 23:58:54 -07:00
} else if ( key === 'longitude' ) {
2022-12-02 12:54:28 -08:00
location . longitude = parseFloat ( locationValues [ key ] as string ) ;
2021-07-19 23:58:54 -07:00
}
}
body . location = location ;
}
}
if ( updateFields . mergeFieldsUi ) {
2022-08-17 08:50:24 -07:00
const mergeFieldsValues = ( updateFields . mergeFieldsUi as IDataObject )
. mergeFieldsValues as IDataObject [ ] ;
2021-07-19 23:58:54 -07:00
if ( mergeFieldsValues ) {
const mergeFields = { } ;
2022-12-02 12:54:28 -08:00
for ( let index = 0 ; index < mergeFieldsValues . length ; index ++ ) {
2021-07-19 23:58:54 -07:00
// @ts-ignore
2022-12-02 12:54:28 -08:00
mergeFields [ mergeFieldsValues [ index ] . name ] = mergeFieldsValues [ index ] . value ;
2021-07-19 23:58:54 -07:00
}
body . merge_fields = mergeFields ;
}
}
if ( updateFields . groupsUi ) {
2022-08-17 08:50:24 -07:00
const groupsValues = ( updateFields . groupsUi as IDataObject )
. groupsValues as IDataObject [ ] ;
2021-07-19 23:58:54 -07:00
if ( groupsValues ) {
const groups = { } ;
2022-12-02 12:54:28 -08:00
for ( let index = 0 ; index < groupsValues . length ; index ++ ) {
2021-07-19 23:58:54 -07:00
// @ts-ignore
2022-12-02 12:54:28 -08:00
groups [ groupsValues [ index ] . categoryFieldId ] = groupsValues [ index ] . value ;
2021-07-19 23:58:54 -07:00
}
body . interests = groups ;
}
}
} else {
const locationJson = validateJSON ( this . getNodeParameter ( 'locationJson' , i ) as string ) ;
2022-08-17 08:50:24 -07:00
const mergeFieldsJson = validateJSON (
this . getNodeParameter ( 'mergeFieldsJson' , i ) as string ,
) ;
2021-07-19 23:58:54 -07:00
const groupJson = validateJSON ( this . getNodeParameter ( 'groupJson' , i ) as string ) ;
2020-05-22 06:47:47 -07:00
2021-07-19 23:58:54 -07:00
if ( locationJson ) {
body . location = locationJson ;
}
if ( mergeFieldsJson ) {
body . merge_fields = mergeFieldsJson ;
}
if ( groupJson ) {
body . interests = groupJson ;
}
}
2022-08-17 08:50:24 -07:00
responseData = await mailchimpApiRequest . call (
this ,
` /lists/ ${ listId } /members/ ${ email } ` ,
'PUT' ,
body ,
) ;
2021-07-19 23:58:54 -07:00
}
2020-05-22 06:47:47 -07:00
}
2021-07-19 23:58:54 -07:00
if ( resource === 'memberTag' ) {
2022-08-17 08:50:24 -07:00
//https://mailchimp.com/developer/reference/lists/list-members/list-member-tags/#post_/lists/-list_id-/members/-subscriber_hash-/tags
2021-07-19 23:58:54 -07:00
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 [ ] ;
2022-11-18 07:29:44 -08:00
const options = this . getNodeParameter ( 'options' , i ) ;
2021-07-19 23:58:54 -07:00
const body : IDataObject = {
tags : [ ] ,
} ;
2020-05-22 06:47:47 -07:00
2021-07-19 23:58:54 -07:00
if ( options . isSyncing ) {
body . is_syncing = options . isSyncing as boolean ;
}
2020-05-22 06:47:47 -07:00
2021-07-19 23:58:54 -07:00
for ( const tag of tags ) {
//@ts-ignore
body . tags . push ( {
name : tag ,
status : 'active' ,
} ) ;
}
2020-05-22 06:47:47 -07:00
2022-08-17 08:50:24 -07:00
responseData = await mailchimpApiRequest . call (
this ,
` /lists/ ${ listId } /members/ ${ email } /tags ` ,
'POST' ,
body ,
) ;
2021-07-19 23:58:54 -07:00
responseData = { success : true } ;
2020-05-22 06:47:47 -07:00
}
2022-08-17 08:50:24 -07:00
//https://mailchimp.com/developer/reference/lists/list-members/list-member-tags/#post_/lists/-list_id-/members/-subscriber_hash-/tags
2021-07-19 23:58:54 -07:00
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 [ ] ;
2022-11-18 07:29:44 -08:00
const options = this . getNodeParameter ( 'options' , i ) ;
2021-07-19 23:58:54 -07:00
const body : IDataObject = {
tags : [ ] ,
} ;
2020-05-22 06:47:47 -07:00
2021-07-19 23:58:54 -07:00
if ( options . isSyncing ) {
body . is_syncing = options . isSyncing as boolean ;
}
for ( const tag of tags ) {
//@ts-ignore
body . tags . push ( {
name : tag ,
status : 'inactive' ,
} ) ;
}
2022-08-17 08:50:24 -07:00
responseData = await mailchimpApiRequest . call (
this ,
` /lists/ ${ listId } /members/ ${ email } /tags ` ,
'POST' ,
body ,
) ;
2021-07-19 23:58:54 -07:00
responseData = { success : true } ;
2020-05-22 06:47:47 -07:00
}
}
2021-07-19 23:58:54 -07:00
if ( resource === 'campaign' ) {
//https://mailchimp.com/developer/api/marketing/campaigns/list-campaigns/
if ( operation === 'getAll' ) {
2022-11-18 05:31:38 -08:00
const returnAll = this . getNodeParameter ( 'returnAll' , i ) ;
2022-11-18 07:29:44 -08:00
const options = this . getNodeParameter ( 'options' , i ) ;
2021-07-19 23:58:54 -07:00
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 ( ',' ) ;
2020-10-05 15:44:52 -07:00
}
2021-07-19 23:58:54 -07:00
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 ;
}
2022-12-02 12:54:28 -08:00
if ( returnAll ) {
2022-08-17 08:50:24 -07:00
responseData = await mailchimpApiRequestAllItems . call (
this ,
2022-12-29 03:20:43 -08:00
'/campaigns' ,
2022-08-17 08:50:24 -07:00
'GET' ,
'campaigns' ,
{ } ,
qs ,
) ;
2021-07-19 23:58:54 -07:00
} else {
2022-11-18 06:26:22 -08:00
qs . count = this . getNodeParameter ( 'limit' , i ) ;
2022-12-29 03:20:43 -08:00
responseData = await mailchimpApiRequest . call ( this , '/campaigns' , 'GET' , { } , qs ) ;
2021-07-19 23:58:54 -07:00
responseData = responseData . campaigns ;
}
2020-10-02 15:45:58 -07:00
}
2021-07-19 23:58:54 -07:00
//https://mailchimp.com/developer/api/marketing/campaigns/send-campaign/
if ( operation === 'send' ) {
const campaignId = this . getNodeParameter ( 'campaignId' , i ) as string ;
2022-08-17 08:50:24 -07:00
responseData = await mailchimpApiRequest . call (
this ,
` /campaigns/ ${ campaignId } /actions/send ` ,
'POST' ,
{ } ,
) ;
2021-07-19 23:58:54 -07:00
responseData = { success : true } ;
2020-10-02 15:45:58 -07:00
}
2021-07-19 23:58:54 -07:00
//https://mailchimp.com/developer/api/marketing/campaigns/get-campaign-info/
if ( operation === 'get' ) {
const campaignId = this . getNodeParameter ( 'campaignId' , i ) as string ;
2022-08-17 08:50:24 -07:00
responseData = await mailchimpApiRequest . call (
this ,
` /campaigns/ ${ campaignId } ` ,
'GET' ,
{ } ,
) ;
2020-10-05 15:44:52 -07:00
}
2021-07-19 23:58:54 -07:00
//https://mailchimp.com/developer/api/marketing/campaigns/delete-campaign/
if ( operation === 'delete' ) {
const campaignId = this . getNodeParameter ( 'campaignId' , i ) as string ;
2022-08-17 08:50:24 -07:00
responseData = await mailchimpApiRequest . call (
this ,
` /campaigns/ ${ campaignId } ` ,
'DELETE' ,
{ } ,
) ;
2021-07-19 23:58:54 -07:00
responseData = { success : true } ;
2020-10-05 15:44:52 -07:00
}
2021-07-19 23:58:54 -07:00
//https://mailchimp.com/developer/api/marketing/campaigns/replicate-campaign/
if ( operation === 'replicate' ) {
const campaignId = this . getNodeParameter ( 'campaignId' , i ) as string ;
2022-08-17 08:50:24 -07:00
responseData = await mailchimpApiRequest . call (
this ,
` /campaigns/ ${ campaignId } /actions/replicate ` ,
'POST' ,
{ } ,
) ;
2020-10-02 15:45:58 -07:00
}
2021-07-19 23:58:54 -07:00
//https://mailchimp.com/developer/api/marketing/campaigns/resend-campaign/
if ( operation === 'resend' ) {
const campaignId = this . getNodeParameter ( 'campaignId' , i ) as string ;
2022-08-17 08:50:24 -07:00
responseData = await mailchimpApiRequest . call (
this ,
` /campaigns/ ${ campaignId } /actions/create-resend ` ,
'POST' ,
{ } ,
) ;
2020-10-02 15:45:58 -07:00
}
}
2021-07-19 23:58:54 -07:00
2022-08-30 08:55:33 -07:00
const executionData = this . helpers . constructExecutionMetaData (
2023-02-27 19:39:43 -08:00
this . helpers . returnJsonArray ( responseData as IDataObject ) ,
2022-08-30 08:55:33 -07:00
{ itemData : { item : i } } ,
) ;
returnData . push ( . . . executionData ) ;
2021-07-19 23:58:54 -07:00
} catch ( error ) {
if ( this . continueOnFail ( ) ) {
2022-09-13 03:36:36 -07:00
returnData . push ( { json : { error : error.message } } ) ;
2021-07-19 23:58:54 -07:00
continue ;
2020-10-02 16:40:10 -07:00
}
2021-07-19 23:58:54 -07:00
throw error ;
2019-11-14 15:44:07 -08:00
}
}
2022-08-30 08:55:33 -07:00
return this . prepareOutputData ( returnData ) ;
2019-11-12 12:48:45 -08:00
}
}