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 { getOrderOutputSchema } from '../output-schemas';

export const wooGetOrder = createAction({
  name: 'Get Order',
  classification: 'READ',
  displayName: 'Get Order',
  description: 'Retrieve a single order by its ID',
  audience: 'human',
  aiMetadata: {
    description:
      'Retrieves one order from a WooCommerce store by its numeric order ID, including line items, billing and shipping addresses, totals, and status. Use when an agent already has an order ID and needs the full order record. Read-only and idempotent.',
    idempotent: true,
  },
  auth: wooAuth,
  outputSchema: getOrderOutputSchema,
  props: {
    id: Property.ShortText({
      displayName: 'Order ID',
      description: 'The number after # in WooCommerce > Orders.',
      placeholder: '123',
      required: true,
    }),
  },
  async run(configValue) {
    const trimmedBaseUrl = configValue.auth.props.baseUrl.replace(/\/$/, '');
    const orderId = configValue.propsValue['id'];

    const request: HttpRequest = {
      method: HttpMethod.GET,
      url: `${trimmedBaseUrl}/wp-json/wc/v3/orders/${wooPathId.encode({ id: orderId, label: 'Order ID' })}`,
      authentication: {
        type: AuthenticationType.BASIC,
        username: configValue.auth.props.consumerKey,
        password: configValue.auth.props.consumerSecret,
      },
    };

    const res = await httpClient.sendRequest(request);

    return res.body;
  },
});