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.8 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { HttpMethod } from '@activepieces/pieces-common';
import { omnisendAuth } from '../auth';
import { omnisendRequest } from '../common/client';

export const listContactsAction = createAction({
  auth: omnisendAuth,
  name: 'list_contacts',
  displayName: 'List Contacts',
  description: 'Retrieve a paginated list of contacts from Omnisend.',
  audience: 'both',
  aiMetadata: {
    description:
      'List contacts from Omnisend with limit/offset pagination. Leave the email filter empty to browse all contacts, or set it to look up a specific contact by email address (use this rather than Get Contact when you only have an email, not a contact ID). Read-only and idempotent.',
    idempotent: true,
  },
  props: {
    limit: Property.Number({
      displayName: 'Limit',
      description: 'Number of contacts to return (max 250).',
      required: false,
      defaultValue: 50,
    }),
    offset: Property.Number({
      displayName: 'Offset',
      description: 'Number of contacts to skip for pagination.',
      required: false,
      defaultValue: 0,
    }),
    email: Property.ShortText({
      displayName: 'Filter by Email',
      description: 'Filter contacts by email address.',
      required: false,
    }),
  },
  async run(context) {
    const { limit, offset, email } = context.propsValue;

    const queryParams: Record<string, string> = {};
    if (limit !== undefined && limit !== null) queryParams['limit'] = String(limit);
    if (offset !== undefined && offset !== null) queryParams['offset'] = String(offset);
    if (email) queryParams['email'] = email;

    return omnisendRequest(
      HttpMethod.GET,
      '/contacts',
      context.auth.secret_text,
      undefined,
      queryParams,
    );
  },
});