mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 12:57:29 -08:00
⚡ Add custom fields to Mautic: contact:create & contact:update (#1311)
This commit is contained in:
parent
5ba66fb081
commit
1a68303319
|
@ -304,6 +304,42 @@ export const contactFields = [
|
|||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Custom Fields',
|
||||
name: 'customFieldsUi',
|
||||
placeholder: 'Add Custom Fields',
|
||||
description: 'Adds a custom fields to set also values which have not been predefined.',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
name: 'customFieldValues',
|
||||
displayName: 'Field',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Field ID',
|
||||
name: 'fieldId',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getContactFields',
|
||||
},
|
||||
default: '',
|
||||
description: 'ID of the field to set.',
|
||||
},
|
||||
{
|
||||
displayName: 'Field Value',
|
||||
name: 'fieldValue',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Value of the field to set.',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Fax',
|
||||
name: 'fax',
|
||||
|
@ -617,6 +653,42 @@ export const contactFields = [
|
|||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Custom Fields',
|
||||
name: 'customFieldsUi',
|
||||
placeholder: 'Add Custom Fields',
|
||||
description: 'Adds a custom fields to set also values which have not been predefined.',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
name: 'customFieldValues',
|
||||
displayName: 'Field',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Field ID',
|
||||
name: 'fieldId',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getContactFields',
|
||||
},
|
||||
default: '',
|
||||
description: 'ID of the field to set.',
|
||||
},
|
||||
{
|
||||
displayName: 'Field Value',
|
||||
name: 'fieldValue',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Value of the field to set.',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Email',
|
||||
name: 'email',
|
||||
|
|
|
@ -180,6 +180,19 @@ export class Mautic implements INodeType {
|
|||
}
|
||||
return returnData;
|
||||
},
|
||||
// Get all the available contact fields to display them to user so that he can
|
||||
// select them easily
|
||||
async getContactFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const fields = await mauticApiRequestAllItems.call(this, 'fields', 'GET', '/fields/contact');
|
||||
for (const field of fields) {
|
||||
returnData.push({
|
||||
name: field.label,
|
||||
value: field.alias,
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -327,6 +340,13 @@ export class Mautic implements INodeType {
|
|||
body.twitter = socialMediaValues.twitter as string;
|
||||
}
|
||||
}
|
||||
if (additionalFields.customFieldsUi) {
|
||||
const customFields = (additionalFields.customFieldsUi as IDataObject).customFieldValues as IDataObject[];
|
||||
if (customFields) {
|
||||
const data = customFields.reduce((obj, value) => Object.assign(obj, { [`${value.fieldId}`]: value.fieldValue }), {});
|
||||
Object.assign(body, data);
|
||||
}
|
||||
}
|
||||
if (additionalFields.b2bOrb2c) {
|
||||
body.b2b_or_b2c = additionalFields.b2bOrb2c as string;
|
||||
}
|
||||
|
@ -429,6 +449,13 @@ export class Mautic implements INodeType {
|
|||
body.twitter = socialMediaValues.twitter as string;
|
||||
}
|
||||
}
|
||||
if (updateFields.customFieldsUi) {
|
||||
const customFields = (updateFields.customFieldsUi as IDataObject).customFieldValues as IDataObject[];
|
||||
if (customFields) {
|
||||
const data = customFields.reduce((obj, value) => Object.assign(obj, { [`${value.fieldId}`]: value.fieldValue }), {});
|
||||
Object.assign(body, data);
|
||||
}
|
||||
}
|
||||
if (updateFields.b2bOrb2c) {
|
||||
body.b2b_or_b2c = updateFields.b2bOrb2c as string;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue