mirror of
https://github.com/n8n-io/n8n-nodes-starter.git
synced 2025-12-16 01:13:01 -06:00
Implement n8n node for Autosend API with support for: - Mail resource: Send single and bulk emails with template or custom content - Contact resource: Create/update contacts (upsert) and get contacts by ID or email - API key authentication - Declarative routing following n8n best practices - Full TypeScript support with proper typing - Passing all linting checks
142 lines
2.8 KiB
TypeScript
142 lines
2.8 KiB
TypeScript
import type { INodeProperties } from 'n8n-workflow';
|
|
|
|
export const upsertOperation: INodeProperties[] = [
|
|
{
|
|
displayName: 'Email',
|
|
name: 'email',
|
|
type: 'string',
|
|
required: true,
|
|
placeholder: 'contact@example.com',
|
|
default: '',
|
|
displayOptions: {
|
|
show: {
|
|
resource: ['contact'],
|
|
operation: ['upsert'],
|
|
},
|
|
},
|
|
routing: {
|
|
send: {
|
|
type: 'body',
|
|
property: 'email',
|
|
},
|
|
},
|
|
description: 'The email address of the contact',
|
|
},
|
|
{
|
|
displayName: 'User ID',
|
|
name: 'userId',
|
|
type: 'string',
|
|
default: '',
|
|
displayOptions: {
|
|
show: {
|
|
resource: ['contact'],
|
|
operation: ['upsert'],
|
|
},
|
|
},
|
|
routing: {
|
|
send: {
|
|
type: 'body',
|
|
property: 'userId',
|
|
},
|
|
},
|
|
description: 'External user ID from your system',
|
|
},
|
|
{
|
|
displayName: 'Additional Fields',
|
|
name: 'additionalFields',
|
|
type: 'collection',
|
|
placeholder: 'Add Field',
|
|
default: {},
|
|
displayOptions: {
|
|
show: {
|
|
resource: ['contact'],
|
|
operation: ['upsert'],
|
|
},
|
|
},
|
|
options: [
|
|
{
|
|
displayName: 'Company',
|
|
name: 'company',
|
|
type: 'string',
|
|
default: '',
|
|
routing: {
|
|
send: {
|
|
type: 'body',
|
|
property: 'company',
|
|
},
|
|
},
|
|
description: 'Company name',
|
|
},
|
|
{
|
|
displayName: 'Custom Fields (JSON)',
|
|
name: 'customFields',
|
|
type: 'json',
|
|
default: '{}',
|
|
routing: {
|
|
send: {
|
|
type: 'body',
|
|
property: 'customFields',
|
|
preSend: [
|
|
async function (this, requestOptions) {
|
|
const customFieldsStr = this.getNodeParameter(
|
|
'additionalFields.customFields',
|
|
'',
|
|
) as string;
|
|
if (customFieldsStr) {
|
|
try {
|
|
const customFields = JSON.parse(customFieldsStr);
|
|
requestOptions.body = requestOptions.body || {};
|
|
(requestOptions.body as Record<string, unknown>).customFields = customFields;
|
|
} catch {
|
|
throw new Error('Custom Fields must be valid JSON');
|
|
}
|
|
}
|
|
return requestOptions;
|
|
},
|
|
],
|
|
},
|
|
},
|
|
description: 'Additional custom fields as a JSON object',
|
|
},
|
|
{
|
|
displayName: 'First Name',
|
|
name: 'firstName',
|
|
type: 'string',
|
|
default: '',
|
|
routing: {
|
|
send: {
|
|
type: 'body',
|
|
property: 'firstName',
|
|
},
|
|
},
|
|
description: 'First name of the contact',
|
|
},
|
|
{
|
|
displayName: 'Last Name',
|
|
name: 'lastName',
|
|
type: 'string',
|
|
default: '',
|
|
routing: {
|
|
send: {
|
|
type: 'body',
|
|
property: 'lastName',
|
|
},
|
|
},
|
|
description: 'Last name of the contact',
|
|
},
|
|
{
|
|
displayName: 'Phone',
|
|
name: 'phone',
|
|
type: 'string',
|
|
default: '',
|
|
routing: {
|
|
send: {
|
|
type: 'body',
|
|
property: 'phone',
|
|
},
|
|
},
|
|
description: 'Phone number of the contact',
|
|
},
|
|
],
|
|
},
|
|
];
|