From 705d5d90b2e5a10b3cd8c1d5edb12b18b9b51eb5 Mon Sep 17 00:00:00 2001 From: Don Bowman Date: Mon, 11 Nov 2024 21:09:08 -0500 Subject: [PATCH] feat(Mautic Node): add get contact by email Many workflows have the user email but not the unique mautic ID, allow looking up the user by email. --- .../nodes/Mautic/ContactDescription.ts | 23 ++++++++++++++++++- .../nodes-base/nodes/Mautic/Mautic.node.ts | 22 ++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/packages/nodes-base/nodes/Mautic/ContactDescription.ts b/packages/nodes-base/nodes/Mautic/ContactDescription.ts index 76d8c34d9d..66d92fb936 100644 --- a/packages/nodes-base/nodes/Mautic/ContactDescription.ts +++ b/packages/nodes-base/nodes/Mautic/ContactDescription.ts @@ -42,6 +42,12 @@ export const contactOperations: INodeProperties[] = [ description: 'Get data of a contact', action: 'Get a contact', }, + { + name: 'Get By Email', + value: 'getByEmail', + description: 'Get data of a contact via email key', + action: 'Get a contact via email key', + }, { name: 'Get Many', value: 'getAll', @@ -473,6 +479,7 @@ export const contactFields: INodeProperties[] = [ }, default: '', }, + { displayName: 'JSON Parameters', name: 'jsonParameters', @@ -1111,7 +1118,21 @@ export const contactFields: INodeProperties[] = [ }, default: '', }, - + /* -------------------------------------------------------------------------- */ + /* contact:getByEmail */ + /* -------------------------------------------------------------------------- */ + { + displayName: 'Contact Email', + name: 'contactEmail', + type: 'string', + displayOptions: { + show: { + operation: ['getByEmail'], + resource: ['contact'], + }, + }, + default: '', + }, /* -------------------------------------------------------------------------- */ /* contact:getAll */ /* -------------------------------------------------------------------------- */ diff --git a/packages/nodes-base/nodes/Mautic/Mautic.node.ts b/packages/nodes-base/nodes/Mautic/Mautic.node.ts index 25a1aad381..ded241c5e3 100644 --- a/packages/nodes-base/nodes/Mautic/Mautic.node.ts +++ b/packages/nodes-base/nodes/Mautic/Mautic.node.ts @@ -828,6 +828,28 @@ export class Mautic implements INodeType { responseData = responseData.map((item) => item.fields.all); } } + //https://developer.mautic.org/?php#get-contact + if (operation === 'getByEmail') { + const options = this.getNodeParameter('options', i); + const email = this.getNodeParameter('contactEmail', i) as string; + const qs = { + 'where[0][col]': 'email', + 'where[0][expr]': 'eq', + 'where[0][val]': email, + }; + // const query = `where[0][col]=email&where[0][expr]=eq&where[0][val]=${email}&minimal=0`; + responseData = await mauticApiRequest.call(this, 'GET', '/contacts', {}, qs); + let result; + for (const key in responseData.contacts) { + result = responseData.contacts[key]; + break; + } + responseData = [result]; + if (options.rawData === false) { + responseData = responseData.map((item) => item.fields.all); + } + } + //https://developer.mautic.org/?php#list-contacts if (operation === 'getAll') { const returnAll = this.getNodeParameter('returnAll', i);