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 {
  AuthenticationType,
  HttpMethod,
  HttpRequest,
  httpClient,
} from '@activepieces/pieces-common';

import { wooAuth } from '../auth';
import { wooPathId } from '../common/path-id';
import { getCustomerOutputSchema } from '../output-schemas';

export const wooGetCustomer = createAction({
  name: 'Get Customer',
  classification: 'READ',
  displayName: 'Get Customer',
  description: 'Retrieve a single customer by their ID',
  audience: 'human',
  aiMetadata: {
    description:
      'Retrieves one customer from a WooCommerce store by their numeric customer ID, including billing and shipping addresses. Use when an agent has a customer ID rather than an email address; Find Customer searches by email instead. Read-only and idempotent.',
    idempotent: true,
  },
  auth: wooAuth,
  outputSchema: getCustomerOutputSchema,
  props: {
    id: Property.ShortText({
      displayName: 'Customer ID',
      description:
        'Find it in WooCommerce under Customers, or from Find Customer.',
      placeholder: '123',
      required: true,
    }),
  },
  async run(configValue) {
    const trimmedBaseUrl = configValue.auth.props.baseUrl.replace(/\/$/, '');
    const customerId = wooPathId.encode({ id: configValue.propsValue['id'], label: 'Customer ID' });

    const request: HttpRequest = {
      method: HttpMethod.GET,
      url: `${trimmedBaseUrl}/wp-json/wc/v3/customers/${customerId}`,
      authentication: {
        type: AuthenticationType.BASIC,
        username: configValue.auth.props.consumerKey,
        password: configValue.auth.props.consumerSecret,
      },
    };

    const res = await httpClient.sendRequest(request);

    return res.body;
  },
});