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.6 KB
Raw Blame
import { createAction } from '@activepieces/pieces-framework';
import { helpScoutApiRequest } from '../common/api';
import { helpScoutAuth } from '../common/auth';
import { HttpMethod } from '@activepieces/pieces-common';
import { customerIdDropdown, customerProperties } from '../common/props';
import { isNil } from '@activepieces/pieces-framework';

export const updateCustomerProperties = createAction({
  auth: helpScoutAuth,
  name: 'update_customer_properties',
  classification: 'WRITE',
  displayName: 'Update Customer Properties',
  description: `Updates customer's properties.`,
  audience: 'both',
  aiMetadata: {
    description:
      "Updates a Help Scout customer's editable property fields (the supplied fields are replaced) for the customer identified by customer ID. Use to modify an existing customer's attributes; only non-empty fields are applied. Repeating the call with the same values is safe and converges to the same state.",
    idempotent: true,
  },
  props: {
    customerId: customerIdDropdown,
    fields: customerProperties,
  },
  async run({ auth, propsValue }) {
    const { customerId } = propsValue;
    const fields = propsValue.fields ?? {};

    const updates = [];

    for (const [key, value] of Object.entries(fields)) {
      if (isNil(value) || value === '') continue;

      updates.push({ op: 'replace', value: value, path: `/${key}` });
    }

    const response = await helpScoutApiRequest({
      method: HttpMethod.PATCH,
      url: `/customers/${customerId}/properties`,
      auth,
      body: updates,
    });

    return {
      success: response.status === 204 ? true : false,
    };
  },
});