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 { HttpMethod } from '@activepieces/pieces-common';
import { Property, createAction } from '@activepieces/pieces-framework';

import { elasticEmailAuth } from '../auth';
import { elasticEmailRequest } from '../common/client';
import { DEFAULT_LIMIT } from '../common/constants';

export const listCampaignsAction = createAction({
  name: 'list_campaigns',
  displayName: 'List Campaigns',
  description: 'Fetch a paginated list of campaigns from Elastic Email.',
  audience: 'both',
  aiMetadata: {
    description:
      'Retrieves a paginated list of campaigns from Elastic Email; leave the search field empty to return all campaigns, or set it to filter by campaign name. Use to look up campaigns or find a campaign name before updating it. Read-only and idempotent.',
    idempotent: true,
  },
  auth: elasticEmailAuth,
  props: {
    search: Property.ShortText({
      displayName: 'Search',
      description: 'Filter campaigns by name.',
      required: false,
    }),
    limit: Property.Number({
      displayName: 'Limit',
      description: 'Maximum number of campaigns to return (max 100).',
      required: false,
      defaultValue: DEFAULT_LIMIT,
    }),
    offset: Property.Number({
      displayName: 'Offset',
      description: 'Number of campaigns to skip.',
      required: false,
      defaultValue: 0,
    }),
  },
  async run({ auth, propsValue }) {
    const queryParams: Record<string, string> = {};
    if (propsValue.search) {
      queryParams['search'] = propsValue.search;
    }
    if (propsValue.limit !== undefined) {
      queryParams['limit'] = String(propsValue.limit);
    }
    if (propsValue.offset !== undefined) {
      queryParams['offset'] = String(propsValue.offset);
    }
    return elasticEmailRequest({
      apiKey: auth.secret_text,
      method: HttpMethod.GET,
      path: '/campaigns',
      queryParams,
    });
  },
});