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.4 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { moonclerkAuth } from '../common/auth';
import { HttpMethod, httpClient } from '@activepieces/pieces-common';
export const retrivePlan = createAction({
  auth: moonclerkAuth,
  name: 'retrivePlan',
  displayName: 'Retrieve Plan',
  description: 'Retrieve a customer plan from MoonClerk using the customer ID',
  audience: 'both',
  aiMetadata: { description: 'Look up a MoonClerk customer by their customer ID and return the subscription plan attached to that customer. Use to fetch plan/pricing details (amount, interval, currency) for a known customer. Requires a valid customer ID; returns nothing if the customer has no subscription. Read-only and safe to repeat.', idempotent: true },
  props: {
    customerId: Property.ShortText({
      displayName: 'Customer ID',
      description: 'The ID of the customer to retrieve the plan for',
      required: true,
    }),
  },
  async run(context) {
    const { customerId } = context.propsValue;
    const apiKey = context.auth.secret_text;

    const response = await httpClient.sendRequest({
      method: HttpMethod.GET,
      url: `https://api.moonclerk.com/customers/${customerId}`,
      headers: {
        Authorization: `Token token=${apiKey}`,
        Accept: 'application/vnd.moonclerk+json;version=1',
      },
    });

    const plan = response.body.customer?.subscription?.plan;

    return plan;
  },
});