Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

1.7 KB
Raw Blame
import { activeCampaignAuth } from '../../auth';
import { Property, createAction } from '@activepieces/pieces-framework';
import { activecampaignCommon, makeClient } from '../../common';
import { CreateContactRequest } from '../../common/types';

export const createContactAction = createAction({
	auth: activeCampaignAuth,
	name: 'activecampaign_create_contact',
	classification: 'WRITE',
	displayName: 'Create Contact',
	description: 'Creates a new contact.',
	audience: 'both',
	aiMetadata: { description: 'Creates a new ActiveCampaign contact from an email (required) plus optional first name, last name, phone, and custom field values. Use when adding a new person to the CRM. Not idempotent: each call creates a contact and does not look up or merge by email, so repeated calls can create duplicates.', idempotent: false },
	props: {
		email: Property.ShortText({
			displayName: 'Email',
			required: true,
		}),
		firstName: Property.ShortText({
			displayName: 'First Name',
			required: false,
		}),
		lastName: Property.ShortText({
			displayName: 'Last Name',
			required: false,
		}),
		phone: Property.ShortText({
			displayName: 'Phone',
			required: false,
		}),
		contactCustomFields: activecampaignCommon.contactCustomFields,
	},
	async run(context) {
		const { email, firstName, lastName, phone, contactCustomFields } = context.propsValue;

		const createContactParams: CreateContactRequest = {
			email,
			firstName,
			lastName,
			phone,
			fieldValues: [],
		};

		Object.entries(contactCustomFields).forEach(([key, value]) => {
			createContactParams.fieldValues.push({ field: key, value: value });
		});

		const client = makeClient(context.auth.props);
		return await client.createContact(createContactParams);
	},
});