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.5 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { stripeAuth } from '../..';
import { stripeCommon } from '../common';
import { httpClient, HttpMethod } from '@activepieces/pieces-common';

import { customerSearchOutputSchema } from '../output-schemas';
export const stripeSearchCustomer = createAction({
  name: 'search_customer',
  classification: 'SEARCH',
  auth: stripeAuth,
  displayName: 'Find Customer by Email',
  description: 'Find customers whose email matches exactly.',
  audience: 'human',
  aiMetadata: {
    description:
      'Looks up Stripe customers matching a given email address. Use to find an existing customer record before creating, updating, or charging one, to avoid duplicates. Read-only and idempotent; matches on the exact email.',
    idempotent: true,
  },
  props: {
    email: Property.ShortText({
      displayName: 'Email',
      placeholder: '[email protected]',
      required: true,
    }),
  },
  outputSchema: customerSearchOutputSchema,
  async run(context) {
    const email = context.propsValue.email
      .replace(/\\/g, '\\\\')
      .replace(/'/g, "\\'");
    const response = await httpClient.sendRequest({
      method: HttpMethod.GET,
      url: `${stripeCommon.baseUrl}/customers/search`,
      headers: {
        Authorization: 'Bearer ' + context.auth.secret_text,
        'Stripe-Version': '2026-02-25.clover',
      },
      queryParams: {
        query: `email:'${email}'`,
      },
    });
    return response.body;
  },
});