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.5 KB
Raw Blame
import { createAction } from '@activepieces/pieces-framework';
import { HttpMethod } from '@activepieces/pieces-common';
import { salesforceAuth } from '../..';
import { callSalesforceApi, salesforcesCommon } from '../common';
import { sobjectCreateResponseOutputSchema } from '../output-schemas';

export const addContactToCampaign = createAction({
    auth: salesforceAuth,
    name: 'add_contact_to_campaign',
    classification: 'WRITE',
    displayName: 'Add Contact to Campaign',
    description: 'Adds a contact to a campaign with a member status.',
    audience: 'human',
    aiMetadata: { description: 'Add a Contact to a Campaign by creating a CampaignMember linking the two, with an optional member status. Not idempotent — re-adding the same contact to the same campaign errors on the existing membership.', idempotent: false },
    outputSchema: sobjectCreateResponseOutputSchema,
    props: {
        campaign_id: salesforcesCommon.campaign,
        contact_id: salesforcesCommon.contact,
        status: salesforcesCommon.status,
    },
    async run(context) {
        const { campaign_id, contact_id, status } = context.propsValue;

        const body = {
            CampaignId: campaign_id,
            ContactId: contact_id,
            Status: status,
        };

        const response = await callSalesforceApi(
            HttpMethod.POST,
            context.auth,
            '/services/data/v56.0/sobjects/CampaignMember',
            body
        );

        return response.body;
    },
});