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 { createAction, Property } from '@activepieces/pieces-framework';
import { wayfrontAuth } from '../auth';
import {
  flattenTicket,
  wayfrontApiClient,
  WayfrontAuthType,
  WayfrontListResponse,
  WayfrontTicket,
} from '../common';

export const listTicketsAction = createAction({
  auth: wayfrontAuth,
  name: 'list_tickets',
  displayName: 'List Tickets',
  description: 'Returns a list of tickets from your Wayfront workspace, sorted by most recent first.',
  audience: 'both',
  aiMetadata: {
    description:
      'Retrieves a page of support tickets from the Wayfront workspace, newest first, with configurable page size and page number for pagination. Use to browse, scan, or look up recent tickets. Read-only and idempotent: it returns current data without modifying anything.',
    idempotent: true,
  },
  props: {
    limit: Property.Number({
      displayName: 'Limit',
      description: 'Maximum number of tickets to return per page. Defaults to 20.',
      required: false,
      defaultValue: 20,
    }),
    page: Property.Number({
      displayName: 'Page',
      description: 'Page number to retrieve when results span multiple pages. Starts at 1.',
      required: false,
      defaultValue: 1,
    }),
  },
  async run(context) {
    const auth = context.auth as unknown as WayfrontAuthType;
    const p = context.propsValue;

    const queryParams: Record<string, string> = {
      limit: String(p.limit ?? 20),
      page: String(p.page ?? 1),
    };

    const response = await wayfrontApiClient(auth.workspaceUrl, auth.apiToken).get<
      WayfrontListResponse<WayfrontTicket>
    >('/tickets', queryParams);

    return response.body.data.map(flattenTicket);
  },
});