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

2.8 KB
Raw Blame
import { pipedriveAuth } from '../auth';
import { createAction, Property } from '@activepieces/pieces-framework';
import { activityCommonProps } from '../common/props';
import { pipedriveApiCall } from '../common';
import { HttpMethod } from '@activepieces/pieces-common';
import dayjs from 'dayjs';
import { updateActivityActionOutputSchema } from '../output-schemas';

export const updateActivityAction = createAction({
    auth: pipedriveAuth,
    name: 'update-activity',
    outputSchema: updateActivityActionOutputSchema,
    classification: 'WRITE',
    displayName: 'Update Activity',
    description: 'Updates an existing activity.',
    audience: 'both',
    aiMetadata: {
        description:
            'Updates fields on an existing activity identified by its activity ID, such as subject, type, due date/time, owner, done state, and linked records; only supplied fields change. Use to reschedule or mark an activity done (use Create Activity to add a new one). Idempotent: repeating the same update converges to the same activity state.',
        idempotent: true,
    },
    props: {
        activityId: Property.Number({
            displayName: 'Activity ID', 
            required: true,
        }),
        subject: Property.ShortText({
            displayName: 'Subject',
            required: false,
        }),
        ...activityCommonProps, 
    },
    async run(context) {
        const {
            activityId,
            subject,
            organizationId,
            personId,
            dealId,
            leadId,
            assignTo, // This is the user ID for the assignee
            type,
            dueDate,
            dueTime,
            duration,
            isDone, 
            busy, 
            note,
            publicDescription,
        } = context.propsValue;

        const activityPayload: Record<string, any> = {
            subject,
            org_id: organizationId, 
            deal_id: dealId,       
            lead_id: leadId,      
            note,
            public_description: publicDescription,
            type,
            owner_id: assignTo,
            due_time: dueTime,
            duration,
            done: isDone, 
        };

        
        if (personId) {
            activityPayload.participants = [{ person_id: personId, primary: true }];
        }

         if (busy) {
			activityPayload.busy = busy === 'busy' ? true : false;
		}

        if (dueDate) {
            
            activityPayload.due_date = dayjs(dueDate).format('YYYY-MM-DD');
        }

       
        const response = await pipedriveApiCall({
            accessToken: context.auth.access_token,
            apiDomain: context.auth.data['api_domain'],
            method: HttpMethod.PATCH, 
            resourceUri: `/v2/activities/${activityId}`,
            body: activityPayload,
        });

        return response;
    },
});