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 { HttpMethod } from '@activepieces/pieces-common';
import { createAction, Property } from '@activepieces/pieces-framework';
import { streakAuth } from '../common/auth';
import { streakApiCall } from '../common/client';
import { flattenStreakBox } from '../common/flatten';
import { boxDropdown, pipelineDropdown, stageDropdown } from '../common/props';
import { StreakBox } from '../common/types';

export const updateBoxAction = createAction({
  auth: streakAuth,
  name: 'update_box',
  classification: 'WRITE',
  displayName: 'Update Box',
  description:
    'Update the name, notes, stage, assignees, or custom fields on an existing box.',
  audience: 'both',
  aiMetadata: {
    description:
      'Update fields on an existing box identified by its box key, setting any of name, stage, notes, assignee emails, or custom fields (only provided fields change). Use when an agent needs to modify or advance an existing Streak record, such as moving a deal to a new stage. Idempotent: re-applying the same values leaves the box in the same state.',
    idempotent: true,
  },
  props: {
    pipelineKey: pipelineDropdown,
    boxKey: boxDropdown,
    name: Property.ShortText({
      displayName: 'New Name',
      description: 'Leave empty to keep the existing name.',
      required: false,
    }),
    stageKey: stageDropdown,
    notes: Property.LongText({
      displayName: 'Notes',
      description: 'Replaces the existing notes. Leave empty to keep them unchanged.',
      required: false,
    }),
    assignedToEmails: Property.Array({
      displayName: 'Assigned To (Emails)',
      description:
        'Replaces the current assignees with these emails. Leave empty to keep assignees unchanged.',
      required: false,
    }),
    fields: Property.Object({
      displayName: 'Custom Fields',
      description:
        'Map of custom field key to value (e.g. {"1007": "Closed", "1039": 42}). Find the field keys in Streak under Pipeline Settings → Fields.',
      required: false,
    }),
  },
  async run(context) {
    const { boxKey, name, stageKey, notes, assignedToEmails, fields } =
      context.propsValue;

    const body: Record<string, unknown> = {};
    if (name) body['name'] = name;
    if (stageKey) body['stageKey'] = stageKey;
    if (notes) body['notes'] = notes;
    if (assignedToEmails && assignedToEmails.length > 0) {
      body['assignedToSharingEntries'] = (assignedToEmails as string[]).map(
        (email) => ({ email }),
      );
    }
    if (fields && Object.keys(fields).length > 0) {
      body['fields'] = fields;
    }

    const response = await streakApiCall<StreakBox>({
      apiKey: context.auth.secret_text,
      method: HttpMethod.POST,
      path: `/api/v1/boxes/${boxKey}`,
      contentType: 'application/json',
      body,
    });

    return flattenStreakBox(response.body);
  },
});