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.
This commit is contained in:
Don Bowman 2024-11-11 21:09:08 -05:00
parent c08d23c00f
commit 705d5d90b2
No known key found for this signature in database
GPG key ID: D21D0E75160D9894
2 changed files with 44 additions and 1 deletions

View file

@ -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 */
/* -------------------------------------------------------------------------- */

View file

@ -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);