* 👕 Enable `consistent-type-imports` for nodes-base * 👕 Apply to nodes-base * ⏪ Undo unrelated changes * 🚚 Move to `.eslintrc.js` in nodes-base * ⏪ Revert "Enable `consistent-type-imports` for nodes-base" This reverts commit 529ad72b051478fa1633aaf84b2864f2fdc7613c. * 👕 Fix severity
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import type { IExecuteFunctions } from 'n8n-core';
|
|
|
|
import type { IDataObject, INodeExecutionData } from 'n8n-workflow';
|
|
|
|
import { apiRequest } from '../../../transport';
|
|
|
|
export async function createContact(
|
|
this: IExecuteFunctions,
|
|
index: number,
|
|
): Promise<INodeExecutionData[]> {
|
|
const id = this.getNodeParameter('customerId', index) as IDataObject;
|
|
const email = this.getNodeParameter('email', index) as IDataObject;
|
|
const { address, notes, phone, name } = this.getNodeParameter('additionalFields', index);
|
|
|
|
const qs = {} as IDataObject;
|
|
const requestMethod = 'POST';
|
|
const endpoint = 'contacts';
|
|
let body = {} as IDataObject;
|
|
let addressData = address as IDataObject;
|
|
|
|
if (addressData) {
|
|
addressData = addressData.addressFields as IDataObject;
|
|
addressData.address1 = addressData.address;
|
|
}
|
|
|
|
body = {
|
|
...addressData,
|
|
customer_id: id,
|
|
email,
|
|
name,
|
|
notes,
|
|
phone,
|
|
};
|
|
|
|
const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
|
|
|
|
return this.helpers.returnJsonArray(responseData);
|
|
}
|