mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
⚡ Improvements to Converkit-Node
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
|
ILoadOptionsFunctions,
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -7,6 +8,7 @@ import {
|
|||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
INodeType,
|
INodeType,
|
||||||
|
INodePropertyOptions,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -14,9 +16,9 @@ import {
|
|||||||
} from './GenericFunctions';
|
} from './GenericFunctions';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
fieldOperations,
|
customFieldOperations,
|
||||||
fieldFields,
|
customFieldFields,
|
||||||
} from './FieldDescription';
|
} from './CustomFieldDescription';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
formOperations,
|
formOperations,
|
||||||
@@ -33,6 +35,11 @@ import {
|
|||||||
tagFields,
|
tagFields,
|
||||||
} from './TagDescription';
|
} from './TagDescription';
|
||||||
|
|
||||||
|
import {
|
||||||
|
tagSubscriberOperations,
|
||||||
|
tagSubscriberFields,
|
||||||
|
} from './TagSubscriberDescription';
|
||||||
|
|
||||||
export class ConvertKit implements INodeType {
|
export class ConvertKit implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
displayName: 'ConvertKit',
|
displayName: 'ConvertKit',
|
||||||
@@ -61,8 +68,8 @@ export class ConvertKit implements INodeType {
|
|||||||
type: 'options',
|
type: 'options',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'Field',
|
name: 'Custom Field',
|
||||||
value: 'field',
|
value: 'customField',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Form',
|
name: 'Form',
|
||||||
@@ -76,15 +83,19 @@ export class ConvertKit implements INodeType {
|
|||||||
name: 'Tag',
|
name: 'Tag',
|
||||||
value: 'tag',
|
value: 'tag',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Tag Subscriber',
|
||||||
|
value: 'tagSubscriber',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
default: 'field',
|
default: 'customField',
|
||||||
description: 'The resource to operate on.'
|
description: 'The resource to operate on.'
|
||||||
},
|
},
|
||||||
//--------------------
|
//--------------------
|
||||||
// Field Description
|
// Field Description
|
||||||
//--------------------
|
//--------------------
|
||||||
...fieldOperations,
|
...customFieldOperations,
|
||||||
...fieldFields,
|
...customFieldFields,
|
||||||
//--------------------
|
//--------------------
|
||||||
// FormDescription
|
// FormDescription
|
||||||
//--------------------
|
//--------------------
|
||||||
@@ -100,187 +111,373 @@ export class ConvertKit implements INodeType {
|
|||||||
//--------------------
|
//--------------------
|
||||||
...tagOperations,
|
...tagOperations,
|
||||||
...tagFields,
|
...tagFields,
|
||||||
|
//--------------------
|
||||||
|
// Tag Subscriber Description
|
||||||
|
//--------------------
|
||||||
|
...tagSubscriberOperations,
|
||||||
|
...tagSubscriberFields,
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
methods = {
|
||||||
|
loadOptions: {
|
||||||
|
// Get all the tags to display them to user so that he can
|
||||||
|
// select them easily
|
||||||
|
async getTags(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
|
const returnData: INodePropertyOptions[] = [];
|
||||||
|
const { tags } = await convertKitApiRequest.call(this, 'GET', '/tags');
|
||||||
|
for (const tag of tags) {
|
||||||
|
const tagName = tag.name;
|
||||||
|
const tagId = tag.id;
|
||||||
|
returnData.push({
|
||||||
|
name: tagName,
|
||||||
|
value: tagId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnData;
|
||||||
|
},
|
||||||
|
// Get all the forms to display them to user so that he can
|
||||||
|
// select them easily
|
||||||
|
async getForms(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
|
const returnData: INodePropertyOptions[] = [];
|
||||||
|
const { forms } = await convertKitApiRequest.call(this, 'GET', '/forms');
|
||||||
|
for (const form of forms) {
|
||||||
|
const formName = form.name;
|
||||||
|
const formId = form.id;
|
||||||
|
returnData.push({
|
||||||
|
name: formName,
|
||||||
|
value: formId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnData;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Get all the sequences to display them to user so that he can
|
||||||
|
// select them easily
|
||||||
|
async getSequences(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
|
const returnData: INodePropertyOptions[] = [];
|
||||||
|
const { courses } = await convertKitApiRequest.call(this, 'GET', '/sequences');
|
||||||
|
for (const course of courses) {
|
||||||
|
const courseName = course.name;
|
||||||
|
const courseId = course.id;
|
||||||
|
returnData.push({
|
||||||
|
name: courseName,
|
||||||
|
value: courseId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnData;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||||
const items = this.getInputData();
|
const items = this.getInputData();
|
||||||
const returnData: IDataObject[] = [];
|
const returnData: IDataObject[] = [];
|
||||||
|
|
||||||
let method = '';
|
|
||||||
let endpoint = '';
|
|
||||||
const qs: IDataObject = {};
|
const qs: IDataObject = {};
|
||||||
let responseData;
|
let responseData;
|
||||||
|
|
||||||
const resource = this.getNodeParameter('resource', 0) as string;
|
const resource = this.getNodeParameter('resource', 0) as string;
|
||||||
const operation = this.getNodeParameter('operation', 0) as string;
|
const operation = this.getNodeParameter('operation', 0) as string;
|
||||||
|
|
||||||
const fullOperation = `${resource}/${operation}`;
|
|
||||||
|
|
||||||
for (let i = 0; i < items.length; i++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
//--------------------
|
|
||||||
// Field Operations
|
if (resource === 'customField') {
|
||||||
//--------------------
|
if (operation === 'create') {
|
||||||
if(resource === 'field') {
|
|
||||||
//---------
|
const label = this.getNodeParameter('label', i) as string;
|
||||||
// Update
|
|
||||||
//---------
|
responseData = await convertKitApiRequest.call(this, 'POST', '/custom_fields', { label }, qs);
|
||||||
if(operation === 'update') {
|
}
|
||||||
qs.label = this.getNodeParameter('label', i) as string;
|
if (operation === 'delete') {
|
||||||
|
|
||||||
const id = this.getNodeParameter('id', i) as string;
|
const id = this.getNodeParameter('id', i) as string;
|
||||||
|
|
||||||
method = 'PUT';
|
responseData = await convertKitApiRequest.call(this, 'DELETE', `/custom_fields/${id}`);
|
||||||
endpoint = `/custom_fields/${id}`;
|
}
|
||||||
//---------
|
if (operation === 'get') {
|
||||||
// Get All
|
|
||||||
//---------
|
|
||||||
} else if(operation === 'getAll') {
|
|
||||||
method = 'GET';
|
|
||||||
endpoint = '/custom_fields';
|
|
||||||
//---------
|
|
||||||
// Create
|
|
||||||
//---------
|
|
||||||
} else if(operation === 'create') {
|
|
||||||
qs.label = this.getNodeParameter('label', i) as string;
|
|
||||||
|
|
||||||
method = 'POST';
|
|
||||||
endpoint = '/custom_fields';
|
|
||||||
//---------
|
|
||||||
// Delete
|
|
||||||
//---------
|
|
||||||
} else if(operation === 'delete') {
|
|
||||||
const id = this.getNodeParameter('id', i) as string;
|
const id = this.getNodeParameter('id', i) as string;
|
||||||
|
|
||||||
method = 'DELETE';
|
responseData = await convertKitApiRequest.call(this, 'GET', `/custom_fields/${id}`);
|
||||||
endpoint = `/custom_fields/${id}`;
|
|
||||||
} else {
|
|
||||||
throw new Error(`The operation "${operation}" is not known!`);
|
|
||||||
}
|
}
|
||||||
//--------------------------------------------
|
if (operation === 'getAll') {
|
||||||
// Form, Sequence, and Tag Operations
|
|
||||||
//--------------------------------------------
|
|
||||||
} else if(['form', 'sequence', 'tag'].includes(resource)) {
|
|
||||||
//-----------------
|
|
||||||
// Add Subscriber
|
|
||||||
//-----------------
|
|
||||||
if(operation === 'addSubscriber') {
|
|
||||||
qs.email= this.getNodeParameter('email', i) as string;
|
|
||||||
const id = this.getNodeParameter('id', i);
|
|
||||||
|
|
||||||
const additionalParams = this.getNodeParameter('additionalFields', 0) as IDataObject;
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||||
|
|
||||||
if(additionalParams.firstName) {
|
responseData = await convertKitApiRequest.call(this, 'GET', `/custom_fields`);
|
||||||
qs.first_name = additionalParams.firstName;
|
|
||||||
|
responseData = responseData.custom_fields;
|
||||||
|
|
||||||
|
if (!returnAll) {
|
||||||
|
|
||||||
|
const limit = this.getNodeParameter('limit', i) as number;
|
||||||
|
|
||||||
|
responseData = responseData.slice(0, limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(additionalParams.fields !== undefined) {
|
|
||||||
const fields = {} as IDataObject;
|
|
||||||
const fieldsParams = additionalParams.fields as IDataObject;
|
|
||||||
const field = fieldsParams?.field as IDataObject[];
|
|
||||||
|
|
||||||
for(let j = 0; j < field.length; j++) {
|
|
||||||
const key = field[j].key as string;
|
|
||||||
const value = field[j].value as string;
|
|
||||||
|
|
||||||
fields[key] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
qs.fields = fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(resource === 'form') {
|
|
||||||
method = 'POST';
|
|
||||||
endpoint = `/forms/${id}/subscribe`;
|
|
||||||
} else if(resource === 'sequence') {
|
|
||||||
method = 'POST';
|
|
||||||
endpoint = `/sequences/${id}/subscribe`;
|
|
||||||
} else if(resource === 'tag') {
|
|
||||||
method = 'POST';
|
|
||||||
endpoint = `/tags/${id}/subscribe`;
|
|
||||||
}
|
|
||||||
//-----------------
|
|
||||||
// Get All
|
|
||||||
//-----------------
|
|
||||||
} else if(operation === 'getAll') {
|
|
||||||
method = 'GET';
|
|
||||||
if(resource === 'form') {
|
|
||||||
endpoint = '/forms';
|
|
||||||
} else if(resource === 'tag') {
|
|
||||||
endpoint = '/tags';
|
|
||||||
} else if(resource === 'sequence') {
|
|
||||||
endpoint = '/sequences';
|
|
||||||
}
|
|
||||||
//--------------------
|
|
||||||
// Get Subscriptions
|
|
||||||
//--------------------
|
|
||||||
} else if(operation === 'getSubscriptions') {
|
|
||||||
const id = this.getNodeParameter('id', i);
|
|
||||||
const additionalParams = this.getNodeParameter('additionalFields', 0) as IDataObject;
|
|
||||||
if(additionalParams.subscriberState) {
|
|
||||||
qs.subscriber_state = additionalParams.subscriberState;
|
|
||||||
}
|
|
||||||
|
|
||||||
method = 'GET';
|
|
||||||
if(resource === 'form') {
|
|
||||||
endpoint = `/forms/${id}/subscriptions`;
|
|
||||||
} else if(resource === 'tag') {
|
|
||||||
endpoint = `/tags/${id}/subscriptions`;
|
|
||||||
} else if(resource === 'sequence') {
|
|
||||||
endpoint = `/sequences/${id}/subscriptions`;
|
|
||||||
}
|
|
||||||
//------------
|
|
||||||
// Create Tag
|
|
||||||
//------------
|
|
||||||
} else if(operation === 'create') {
|
|
||||||
const name = this.getNodeParameter('name', i);
|
|
||||||
qs.tag = { name, };
|
|
||||||
|
|
||||||
method = 'POST';
|
|
||||||
endpoint = '/tags';
|
|
||||||
//------------
|
|
||||||
// Remove Tag
|
|
||||||
//------------
|
|
||||||
} else if(operation === 'removeSubscriber') {
|
|
||||||
const id = this.getNodeParameter('id', i);
|
|
||||||
|
|
||||||
qs.email = this.getNodeParameter('email', i);
|
|
||||||
|
|
||||||
method = 'POST';
|
|
||||||
endpoint = `/tags/${id}/unsubscribe`;
|
|
||||||
} else {
|
|
||||||
throw new Error(`The operation "${operation}" is not known!`);
|
|
||||||
}
|
}
|
||||||
} else {
|
if (operation === 'update') {
|
||||||
throw new Error(`The resource "${resource}" is not known!`);
|
|
||||||
|
const id = this.getNodeParameter('id', i) as string;
|
||||||
|
|
||||||
|
const label = this.getNodeParameter('label', i) as string;
|
||||||
|
|
||||||
|
responseData = await convertKitApiRequest.call(this, 'PUT', `/custom_fields/${id}`, { label });
|
||||||
|
|
||||||
|
responseData = { success: true };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
responseData = await convertKitApiRequest.call(this, method, endpoint, {}, qs);
|
if (resource === 'form') {
|
||||||
|
if (operation === 'addSubscriber') {
|
||||||
|
|
||||||
if(fullOperation === 'field/getAll') {
|
const email = this.getNodeParameter('email', i) as string;
|
||||||
responseData = responseData.custom_fields;
|
|
||||||
} else if(['form/addSubscriber', 'tag/addSubscriber', 'sequence/addSubscriber'].includes(fullOperation)) {
|
const formId = this.getNodeParameter('id', i) as string;
|
||||||
responseData = responseData.subscription;
|
|
||||||
} else if(fullOperation === 'form/getAll') {
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
responseData = responseData.forms;
|
|
||||||
} else if(['form/getSubscriptions', 'tag/getSubscriptions'].includes(fullOperation)) {
|
const body: IDataObject = {
|
||||||
responseData = responseData.subscriptions;
|
email,
|
||||||
} else if(fullOperation === 'tag/getAll') {
|
};
|
||||||
responseData = responseData.tags;
|
|
||||||
} else if(fullOperation === 'sequence/getAll') {
|
if (additionalFields.firstName) {
|
||||||
responseData = responseData.courses;
|
body.first_name = additionalFields.firstName as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalFields.tags) {
|
||||||
|
body.tags = additionalFields.tags as string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalFields.fieldsUi) {
|
||||||
|
const fieldValues = (additionalFields.fieldsUi as IDataObject).fieldsValues as IDataObject[];
|
||||||
|
if (fieldValues) {
|
||||||
|
body.fields = {};
|
||||||
|
for (const fieldValue of fieldValues) {
|
||||||
|
//@ts-ignore
|
||||||
|
body.fields[fieldValue.key] = fieldValue.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const { subscription } = await convertKitApiRequest.call(this, 'POST', `/forms/${formId}/subscribe`, body);
|
||||||
|
|
||||||
|
responseData = subscription;
|
||||||
|
}
|
||||||
|
if (operation === 'getAll') {
|
||||||
|
|
||||||
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||||
|
|
||||||
|
responseData = await convertKitApiRequest.call(this, 'GET', `/forms`);
|
||||||
|
|
||||||
|
responseData = responseData.forms;
|
||||||
|
|
||||||
|
if (!returnAll) {
|
||||||
|
|
||||||
|
const limit = this.getNodeParameter('limit', i) as number;
|
||||||
|
|
||||||
|
responseData = responseData.slice(0, limit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (operation === 'getSubscriptions') {
|
||||||
|
|
||||||
|
const formId = this.getNodeParameter('id', i) as string;
|
||||||
|
|
||||||
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||||
|
|
||||||
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
|
|
||||||
|
if (additionalFields.subscriberState) {
|
||||||
|
qs.subscriber_state = additionalFields.subscriberState as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
responseData = await convertKitApiRequest.call(this, 'GET', `/forms/${formId}/subscriptions`, {}, qs);
|
||||||
|
|
||||||
|
responseData = responseData.subscriptions;
|
||||||
|
|
||||||
|
if (!returnAll) {
|
||||||
|
|
||||||
|
const limit = this.getNodeParameter('limit', i) as number;
|
||||||
|
|
||||||
|
responseData = responseData.slice(0, limit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resource === 'sequence') {
|
||||||
|
if (operation === 'addSubscriber') {
|
||||||
|
|
||||||
|
const email = this.getNodeParameter('email', i) as string;
|
||||||
|
|
||||||
|
const sequenceId = this.getNodeParameter('id', i) as string;
|
||||||
|
|
||||||
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
|
|
||||||
|
const body: IDataObject = {
|
||||||
|
email,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (additionalFields.firstName) {
|
||||||
|
body.first_name = additionalFields.firstName as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalFields.tags) {
|
||||||
|
body.tags = additionalFields.tags as string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalFields.fieldsUi) {
|
||||||
|
const fieldValues = (additionalFields.fieldsUi as IDataObject).fieldsValues as IDataObject[];
|
||||||
|
if (fieldValues) {
|
||||||
|
body.fields = {};
|
||||||
|
for (const fieldValue of fieldValues) {
|
||||||
|
//@ts-ignore
|
||||||
|
body.fields[fieldValue.key] = fieldValue.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const { subscription } = await convertKitApiRequest.call(this, 'POST', `/sequences/${sequenceId}/subscribe`, body);
|
||||||
|
|
||||||
|
responseData = subscription;
|
||||||
|
}
|
||||||
|
if (operation === 'getAll') {
|
||||||
|
|
||||||
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||||
|
|
||||||
|
responseData = await convertKitApiRequest.call(this, 'GET', `/sequences`);
|
||||||
|
|
||||||
|
responseData = responseData.courses;
|
||||||
|
|
||||||
|
if (!returnAll) {
|
||||||
|
|
||||||
|
const limit = this.getNodeParameter('limit', i) as number;
|
||||||
|
|
||||||
|
responseData = responseData.slice(0, limit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (operation === 'getSubscriptions') {
|
||||||
|
|
||||||
|
const sequenceId = this.getNodeParameter('id', i) as string;
|
||||||
|
|
||||||
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||||
|
|
||||||
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
|
|
||||||
|
if (additionalFields.subscriberState) {
|
||||||
|
qs.subscriber_state = additionalFields.subscriberState as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
responseData = await convertKitApiRequest.call(this, 'GET', `/sequences/${sequenceId}/subscriptions`, {}, qs);
|
||||||
|
|
||||||
|
responseData = responseData.subscriptions;
|
||||||
|
|
||||||
|
if (!returnAll) {
|
||||||
|
|
||||||
|
const limit = this.getNodeParameter('limit', i) as number;
|
||||||
|
|
||||||
|
responseData = responseData.slice(0, limit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resource === 'tag') {
|
||||||
|
if (operation === 'create') {
|
||||||
|
|
||||||
|
const names = ((this.getNodeParameter('name', i) as string).split(',') as string[]).map((e) => ({ name: e }));
|
||||||
|
|
||||||
|
const body: IDataObject = {
|
||||||
|
tag: names
|
||||||
|
};
|
||||||
|
|
||||||
|
responseData = await convertKitApiRequest.call(this, 'POST', '/tags', body);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (operation === 'getAll') {
|
||||||
|
|
||||||
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||||
|
|
||||||
|
responseData = await convertKitApiRequest.call(this, 'GET', `/tags`);
|
||||||
|
|
||||||
|
responseData = responseData.tags;
|
||||||
|
|
||||||
|
if (!returnAll) {
|
||||||
|
|
||||||
|
const limit = this.getNodeParameter('limit', i) as number;
|
||||||
|
|
||||||
|
responseData = responseData.slice(0, limit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resource === 'tagSubscriber') {
|
||||||
|
|
||||||
|
if (operation === 'add') {
|
||||||
|
|
||||||
|
const tagId = this.getNodeParameter('tagId', i) as string;
|
||||||
|
|
||||||
|
const email = this.getNodeParameter('email', i) as string;
|
||||||
|
|
||||||
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
|
|
||||||
|
const body: IDataObject = {
|
||||||
|
email,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (additionalFields.firstName) {
|
||||||
|
body.first_name = additionalFields.firstName as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalFields.fieldsUi) {
|
||||||
|
const fieldValues = (additionalFields.fieldsUi as IDataObject).fieldsValues as IDataObject[];
|
||||||
|
if (fieldValues) {
|
||||||
|
body.fields = {};
|
||||||
|
for (const fieldValue of fieldValues) {
|
||||||
|
//@ts-ignore
|
||||||
|
body.fields[fieldValue.key] = fieldValue.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const { subscription } = await convertKitApiRequest.call(this, 'POST', `/tags/${tagId}/subscribe`, body);
|
||||||
|
|
||||||
|
responseData = subscription;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (operation === 'getAll') {
|
||||||
|
|
||||||
|
const tagId = this.getNodeParameter('tagId', i) as string;
|
||||||
|
|
||||||
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||||
|
|
||||||
|
responseData = await convertKitApiRequest.call(this, 'GET', `/tags/${tagId}/subscriptions`);
|
||||||
|
|
||||||
|
responseData = responseData.subscriptions;
|
||||||
|
|
||||||
|
if (!returnAll) {
|
||||||
|
|
||||||
|
const limit = this.getNodeParameter('limit', i) as number;
|
||||||
|
|
||||||
|
responseData = responseData.slice(0, limit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (operation === 'delete') {
|
||||||
|
|
||||||
|
const tagId = this.getNodeParameter('tagId', i) as string;
|
||||||
|
|
||||||
|
const email = this.getNodeParameter('email', i) as string;
|
||||||
|
|
||||||
|
responseData= await convertKitApiRequest.call(this, 'POST', `/tags/${tagId}>/unsubscribe`, { email });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(responseData)) {
|
if (Array.isArray(responseData)) {
|
||||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||||
} else if (responseData !== undefined) {
|
} else if (responseData !== undefined) {
|
||||||
returnData.push(responseData as IDataObject);
|
returnData.push(responseData as IDataObject);
|
||||||
} else {
|
|
||||||
if(method === 'GET') {
|
|
||||||
returnData.push( { } );
|
|
||||||
} else {
|
|
||||||
returnData.push( { success: true } );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import {
|
import {
|
||||||
INodeProperties
|
INodeProperties,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
export const fieldOperations = [
|
export const customFieldOperations = [
|
||||||
{
|
{
|
||||||
displayName: 'Operation',
|
displayName: 'Operation',
|
||||||
name: 'operation',
|
name: 'operation',
|
||||||
@@ -10,7 +10,7 @@ export const fieldOperations = [
|
|||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'field',
|
'customField',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -18,22 +18,22 @@ export const fieldOperations = [
|
|||||||
{
|
{
|
||||||
name: 'Create',
|
name: 'Create',
|
||||||
value: 'create',
|
value: 'create',
|
||||||
description: 'Create a field.',
|
description: 'Create a field',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Delete',
|
name: 'Delete',
|
||||||
value: 'delete',
|
value: 'delete',
|
||||||
description: 'Delete a field.',
|
description: 'Delete a field',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Get All',
|
name: 'Get All',
|
||||||
value: 'getAll',
|
value: 'getAll',
|
||||||
description: `List all of your account's custom fields.`,
|
description: 'Get all fields',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Update',
|
name: 'Update',
|
||||||
value: 'update',
|
value: 'update',
|
||||||
description: 'Update a field.',
|
description: 'Update a field',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
default: 'update',
|
default: 'update',
|
||||||
@@ -41,7 +41,7 @@ export const fieldOperations = [
|
|||||||
},
|
},
|
||||||
] as INodeProperties[];
|
] as INodeProperties[];
|
||||||
|
|
||||||
export const fieldFields = [
|
export const customFieldFields = [
|
||||||
{
|
{
|
||||||
displayName: 'Field ID',
|
displayName: 'Field ID',
|
||||||
name: 'id',
|
name: 'id',
|
||||||
@@ -50,7 +50,7 @@ export const fieldFields = [
|
|||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'field',
|
'customField',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'update',
|
'update',
|
||||||
@@ -69,7 +69,7 @@ export const fieldFields = [
|
|||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'field',
|
'customField',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'update',
|
'update',
|
||||||
@@ -80,4 +80,45 @@ export const fieldFields = [
|
|||||||
default: '',
|
default: '',
|
||||||
description: 'The label of the custom field.',
|
description: 'The label of the custom field.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Return All',
|
||||||
|
name: 'returnAll',
|
||||||
|
type: 'boolean',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'customField',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: false,
|
||||||
|
description: 'If all results should be returned or only up to a given limit.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Limit',
|
||||||
|
name: 'limit',
|
||||||
|
type: 'number',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'customField',
|
||||||
|
],
|
||||||
|
returnAll: [
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
typeOptions: {
|
||||||
|
minValue: 1,
|
||||||
|
maxValue: 500,
|
||||||
|
},
|
||||||
|
default: 100,
|
||||||
|
description: 'How many results to return.',
|
||||||
|
},
|
||||||
] as INodeProperties[];
|
] as INodeProperties[];
|
||||||
@@ -18,17 +18,17 @@ export const formOperations = [
|
|||||||
{
|
{
|
||||||
name: 'Add Subscriber',
|
name: 'Add Subscriber',
|
||||||
value: 'addSubscriber',
|
value: 'addSubscriber',
|
||||||
description: 'Add a subscriber.',
|
description: 'Add a subscriber',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Get All',
|
name: 'Get All',
|
||||||
value: 'getAll',
|
value: 'getAll',
|
||||||
description: 'Get a list of all the forms for your account.',
|
description: 'Get all forms',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Get Subscriptions',
|
name: 'Get Subscriptions',
|
||||||
value: 'getSubscriptions',
|
value: 'getSubscriptions',
|
||||||
description: 'List subscriptions to a form including subscriber data.',
|
description: 'List subscriptions to a form including subscriber data',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
default: 'addSubscriber',
|
default: 'addSubscriber',
|
||||||
@@ -38,7 +38,7 @@ export const formOperations = [
|
|||||||
|
|
||||||
export const formFields = [
|
export const formFields = [
|
||||||
{
|
{
|
||||||
displayName: 'Email Address',
|
displayName: 'Email',
|
||||||
name: 'email',
|
name: 'email',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
@@ -58,7 +58,10 @@ export const formFields = [
|
|||||||
{
|
{
|
||||||
displayName: 'Form ID',
|
displayName: 'Form ID',
|
||||||
name: 'id',
|
name: 'id',
|
||||||
type: 'string',
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getForms',
|
||||||
|
},
|
||||||
required: true,
|
required: true,
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
@@ -91,16 +94,9 @@ export const formFields = [
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
options: [
|
options: [
|
||||||
{
|
|
||||||
displayName: 'First Name',
|
|
||||||
name: 'firstName',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
description: `The subscriber's first name.`,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
displayName: 'Custom Fields',
|
displayName: 'Custom Fields',
|
||||||
name: 'fields',
|
name: 'fieldsUi',
|
||||||
placeholder: 'Add Custom Field',
|
placeholder: 'Add Custom Field',
|
||||||
description: 'Object of key/value pairs for custom fields (the custom field must exist before you can use it here).',
|
description: 'Object of key/value pairs for custom fields (the custom field must exist before you can use it here).',
|
||||||
type: 'fixedCollection',
|
type: 'fixedCollection',
|
||||||
@@ -110,7 +106,7 @@ export const formFields = [
|
|||||||
default: {},
|
default: {},
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'field',
|
name: 'fieldsValues',
|
||||||
displayName: 'Custom Field',
|
displayName: 'Custom Field',
|
||||||
values: [
|
values: [
|
||||||
{
|
{
|
||||||
@@ -133,8 +129,58 @@ export const formFields = [
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'First Name',
|
||||||
|
name: 'firstName',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: `The subscriber's first name.`,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Return All',
|
||||||
|
name: 'returnAll',
|
||||||
|
type: 'boolean',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
'getSubscriptions',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'form',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: false,
|
||||||
|
description: 'If all results should be returned or only up to a given limit.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Limit',
|
||||||
|
name: 'limit',
|
||||||
|
type: 'number',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
'getSubscriptions',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'form',
|
||||||
|
],
|
||||||
|
returnAll: [
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
typeOptions: {
|
||||||
|
minValue: 1,
|
||||||
|
maxValue: 500,
|
||||||
|
},
|
||||||
|
default: 100,
|
||||||
|
description: 'How many results to return.',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Additional Fields',
|
displayName: 'Additional Fields',
|
||||||
name: 'additionalFields',
|
name: 'additionalFields',
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ import {
|
|||||||
|
|
||||||
export async function convertKitApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IHookFunctions,
|
export async function convertKitApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IHookFunctions,
|
||||||
method: string, endpoint: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
method: string, endpoint: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||||
const credentials = this.getCredentials('convertKitApi');
|
|
||||||
|
const credentials = this.getCredentials('convertKitApi');
|
||||||
|
|
||||||
if (credentials === undefined) {
|
if (credentials === undefined) {
|
||||||
throw new Error('No credentials got returned!');
|
throw new Error('No credentials got returned!');
|
||||||
}
|
}
|
||||||
@@ -30,15 +32,29 @@ export async function convertKitApiRequest(this: IExecuteFunctions | IExecuteSin
|
|||||||
uri: uri ||`https://api.convertkit.com/v3${endpoint}`,
|
uri: uri ||`https://api.convertkit.com/v3${endpoint}`,
|
||||||
json: true,
|
json: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
options = Object.assign({}, options, option);
|
options = Object.assign({}, options, option);
|
||||||
|
|
||||||
if (Object.keys(options.body).length === 0) {
|
if (Object.keys(options.body).length === 0) {
|
||||||
delete options.body;
|
delete options.body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(options);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
qs.api_secret = credentials.apiSecret;
|
qs.api_secret = credentials.apiSecret;
|
||||||
|
|
||||||
return await this.helpers.request!(options);
|
return await this.helpers.request!(options);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`ConvertKit error response: ${error.message}`);
|
|
||||||
|
let errorMessage = error;
|
||||||
|
|
||||||
|
if (error.response && error.response.body && error.response.body.message) {
|
||||||
|
errorMessage = error.response.body.message;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(`ConvertKit error response: ${errorMessage}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
INodeProperties
|
INodeProperties,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
export const sequenceOperations = [
|
export const sequenceOperations = [
|
||||||
@@ -23,7 +23,7 @@ export const sequenceOperations = [
|
|||||||
{
|
{
|
||||||
name: 'Get All',
|
name: 'Get All',
|
||||||
value: 'getAll',
|
value: 'getAll',
|
||||||
description: 'Returns a list of sequences for the account.',
|
description: 'Get all sequences.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Get Subscriptions',
|
name: 'Get Subscriptions',
|
||||||
@@ -38,7 +38,7 @@ export const sequenceOperations = [
|
|||||||
|
|
||||||
export const sequenceFields = [
|
export const sequenceFields = [
|
||||||
{
|
{
|
||||||
displayName: 'Email Address',
|
displayName: 'Email',
|
||||||
name: 'email',
|
name: 'email',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
@@ -58,7 +58,10 @@ export const sequenceFields = [
|
|||||||
{
|
{
|
||||||
displayName: 'Sequence ID',
|
displayName: 'Sequence ID',
|
||||||
name: 'id',
|
name: 'id',
|
||||||
type: 'string',
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getSequences',
|
||||||
|
},
|
||||||
required: true,
|
required: true,
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
@@ -74,6 +77,49 @@ export const sequenceFields = [
|
|||||||
default: '',
|
default: '',
|
||||||
description: 'Sequence ID.',
|
description: 'Sequence ID.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Return All',
|
||||||
|
name: 'returnAll',
|
||||||
|
type: 'boolean',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
'getSubscriptions',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'sequence',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: false,
|
||||||
|
description: 'If all results should be returned or only up to a given limit.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Limit',
|
||||||
|
name: 'limit',
|
||||||
|
type: 'number',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
'getSubscriptions',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'sequence',
|
||||||
|
],
|
||||||
|
returnAll: [
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
typeOptions: {
|
||||||
|
minValue: 1,
|
||||||
|
maxValue: 500,
|
||||||
|
},
|
||||||
|
default: 100,
|
||||||
|
description: 'How many results to return.',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Additional Fields',
|
displayName: 'Additional Fields',
|
||||||
name: 'additionalFields',
|
name: 'additionalFields',
|
||||||
@@ -91,16 +137,9 @@ export const sequenceFields = [
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
options: [
|
options: [
|
||||||
{
|
|
||||||
displayName: 'First Name',
|
|
||||||
name: 'firstName',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
description: `The subscriber's first name.`,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
displayName: 'Custom Fields',
|
displayName: 'Custom Fields',
|
||||||
name: 'fields',
|
name: 'fieldsUi',
|
||||||
placeholder: 'Add Custom Field',
|
placeholder: 'Add Custom Field',
|
||||||
description: 'Object of key/value pairs for custom fields (the custom field must exist before you can use it here).',
|
description: 'Object of key/value pairs for custom fields (the custom field must exist before you can use it here).',
|
||||||
type: 'fixedCollection',
|
type: 'fixedCollection',
|
||||||
@@ -110,7 +149,7 @@ export const sequenceFields = [
|
|||||||
default: {},
|
default: {},
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'field',
|
name: 'fieldsValues',
|
||||||
displayName: 'Custom Field',
|
displayName: 'Custom Field',
|
||||||
values: [
|
values: [
|
||||||
{
|
{
|
||||||
@@ -133,6 +172,23 @@ export const sequenceFields = [
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'First Name',
|
||||||
|
name: 'firstName',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: `The subscriber's first name.`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Tag IDs',
|
||||||
|
name: 'tags',
|
||||||
|
type: 'multiOptions',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getTags',
|
||||||
|
},
|
||||||
|
default: [],
|
||||||
|
description: 'Tags',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
INodeProperties
|
INodeProperties,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
export const tagOperations = [
|
export const tagOperations = [
|
||||||
@@ -18,27 +18,12 @@ export const tagOperations = [
|
|||||||
{
|
{
|
||||||
name: 'Create',
|
name: 'Create',
|
||||||
value: 'create',
|
value: 'create',
|
||||||
description: 'Create a tag.',
|
description: 'Create a tag',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Get All',
|
name: 'Get All',
|
||||||
value: 'getAll',
|
value: 'getAll',
|
||||||
description: 'Returns a list of tags for the account.',
|
description: 'Get all tags',
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Get Subscriptions',
|
|
||||||
value: 'getSubscriptions',
|
|
||||||
description: 'List subscriptions to a tag including subscriber data.',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Remove Subscriber',
|
|
||||||
value: 'removeSubscriber',
|
|
||||||
description: 'Remove a tag from a subscriber.',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Add Subscriber',
|
|
||||||
value: 'addSubscriber',
|
|
||||||
description: 'Add a tag to a subscriber.',
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
default: 'create',
|
default: 'create',
|
||||||
@@ -63,142 +48,47 @@ export const tagFields = [
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Tag name.',
|
description: 'Tag name, multiple can be added separated by comma',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Email Address',
|
displayName: 'Return All',
|
||||||
name: 'email',
|
name: 'returnAll',
|
||||||
type: 'string',
|
type: 'boolean',
|
||||||
required: true,
|
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
resource: [
|
resource: [
|
||||||
'tag',
|
'tag',
|
||||||
],
|
],
|
||||||
operation: [
|
|
||||||
'addSubscriber',
|
|
||||||
'removeSubscriber',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: false,
|
||||||
description: 'Subscriber email address.',
|
description: 'If all results should be returned or only up to a given limit.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Tag ID',
|
displayName: 'Limit',
|
||||||
name: 'id',
|
name: 'limit',
|
||||||
type: 'string',
|
type: 'number',
|
||||||
required: true,
|
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
resource: [
|
resource: [
|
||||||
'tag',
|
'tag',
|
||||||
],
|
],
|
||||||
operation: [
|
returnAll: [
|
||||||
'addSubscriber',
|
false,
|
||||||
'removeSubscriber',
|
|
||||||
'getSubscriptions',
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
typeOptions: {
|
||||||
description: 'Tag ID.',
|
minValue: 1,
|
||||||
},
|
maxValue: 500,
|
||||||
{
|
|
||||||
displayName: 'Additional Fields',
|
|
||||||
name: 'additionalFields',
|
|
||||||
type: 'collection',
|
|
||||||
placeholder: 'Add Field',
|
|
||||||
default: {},
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
resource: [
|
|
||||||
'tag',
|
|
||||||
],
|
|
||||||
operation: [
|
|
||||||
'addSubscriber',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
options: [
|
default: 100,
|
||||||
{
|
description: 'How many results to return.',
|
||||||
displayName: 'First Name',
|
|
||||||
name: 'firstName',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
description: 'Subscriber first name.',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Custom Fields',
|
|
||||||
name: 'fields',
|
|
||||||
placeholder: 'Add Custom Field',
|
|
||||||
description: 'Object of key/value pairs for custom fields (the custom field must exist before you can use it here).',
|
|
||||||
type: 'fixedCollection',
|
|
||||||
typeOptions: {
|
|
||||||
multipleValues: true,
|
|
||||||
},
|
|
||||||
default: {},
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
name: 'field',
|
|
||||||
displayName: 'Custom Field',
|
|
||||||
values: [
|
|
||||||
{
|
|
||||||
displayName: 'Field Key',
|
|
||||||
name: 'key',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
placeholder: 'last_name',
|
|
||||||
description: `The field's key.`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Field Value',
|
|
||||||
name: 'value',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
placeholder: 'Doe',
|
|
||||||
description: 'Value of the field.',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Additional Fields',
|
|
||||||
name: 'additionalFields',
|
|
||||||
type: 'collection',
|
|
||||||
placeholder: 'Add Field',
|
|
||||||
default: {},
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
resource: [
|
|
||||||
'tag',
|
|
||||||
],
|
|
||||||
operation: [
|
|
||||||
'getSubscriptions',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
displayName: 'Subscriber State',
|
|
||||||
name: 'subscriberState',
|
|
||||||
type: 'options',
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
name: 'Active',
|
|
||||||
value: 'active',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Cancelled',
|
|
||||||
value: 'cancelled',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
default: 'active',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
description: 'Receive only active subscribers or cancelled subscribers.',
|
|
||||||
},
|
},
|
||||||
] as INodeProperties[];
|
] as INodeProperties[];
|
||||||
|
|||||||
219
packages/nodes-base/nodes/ConvertKit/TagSubscriberDescription.ts
Normal file
219
packages/nodes-base/nodes/ConvertKit/TagSubscriberDescription.ts
Normal file
@@ -0,0 +1,219 @@
|
|||||||
|
import {
|
||||||
|
INodeProperties,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
export const tagSubscriberOperations = [
|
||||||
|
{
|
||||||
|
displayName: 'Operation',
|
||||||
|
name: 'operation',
|
||||||
|
type: 'options',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'tagSubscriber',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Add',
|
||||||
|
value: 'add',
|
||||||
|
description: 'Add a tag to a subscriber',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Get All',
|
||||||
|
value: 'getAll',
|
||||||
|
description: 'List subscriptions to a tag including subscriber data',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Delete',
|
||||||
|
value: 'delete',
|
||||||
|
description: 'Delete a tag from a subscriber',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'create',
|
||||||
|
description: 'The operation to perform.',
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
||||||
|
|
||||||
|
export const tagSubscriberFields = [
|
||||||
|
{
|
||||||
|
displayName: 'Tag ID',
|
||||||
|
name: 'tagId',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getTags',
|
||||||
|
},
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'tagSubscriber',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'add',
|
||||||
|
'getAll',
|
||||||
|
'delete',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Email',
|
||||||
|
name: 'email',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'tagSubscriber',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'add',
|
||||||
|
'delete',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
description: 'Subscriber email address.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Additional Fields',
|
||||||
|
name: 'additionalFields',
|
||||||
|
type: 'collection',
|
||||||
|
placeholder: 'Add Field',
|
||||||
|
default: {},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'tagSubscriber',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'add',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'Custom Fields',
|
||||||
|
name: 'fields',
|
||||||
|
placeholder: 'Add Custom Field',
|
||||||
|
description: 'Object of key/value pairs for custom fields (the custom field must exist before you can use it here).',
|
||||||
|
type: 'fixedCollection',
|
||||||
|
typeOptions: {
|
||||||
|
multipleValues: true,
|
||||||
|
},
|
||||||
|
default: {},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'field',
|
||||||
|
displayName: 'Custom Field',
|
||||||
|
values: [
|
||||||
|
{
|
||||||
|
displayName: 'Field Key',
|
||||||
|
name: 'key',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
placeholder: 'last_name',
|
||||||
|
description: `The field's key.`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Field Value',
|
||||||
|
name: 'value',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
placeholder: 'Doe',
|
||||||
|
description: 'Value of the field.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'First Name',
|
||||||
|
name: 'firstName',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'Subscriber first name.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Return All',
|
||||||
|
name: 'returnAll',
|
||||||
|
type: 'boolean',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'tagSubscriber',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: false,
|
||||||
|
description: 'If all results should be returned or only up to a given limit.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Limit',
|
||||||
|
name: 'limit',
|
||||||
|
type: 'number',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'tagSubscriber',
|
||||||
|
],
|
||||||
|
returnAll: [
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
typeOptions: {
|
||||||
|
minValue: 1,
|
||||||
|
maxValue: 500,
|
||||||
|
},
|
||||||
|
default: 100,
|
||||||
|
description: 'How many results to return.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Additional Fields',
|
||||||
|
name: 'additionalFields',
|
||||||
|
type: 'collection',
|
||||||
|
placeholder: 'Add Field',
|
||||||
|
default: {},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'tagSubscriber',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'Subscriber State',
|
||||||
|
name: 'subscriberState',
|
||||||
|
type: 'options',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Active',
|
||||||
|
value: 'active',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Cancelled',
|
||||||
|
value: 'cancelled',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'active',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
description: 'Receive only active subscribers or cancelled subscribers.',
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
||||||
Reference in New Issue
Block a user