Skip to main content
Glama

create_invoice

Create an invoice for a subscription by providing customer, payment method, currency, gateway, line items, and due/period dates.

Instructions

Create an invoice. POST /invoices. Required: companyCurrencyId, companyGatewayId, customerId, paymentMethodId, detail (array, at least one line item), dateDue, dateFrom, dateTo. Optional: billingAddress, shippingAddress (when provided: contactName, street1, city, zip, countryCode (ISO 3166-1 alpha-2), type residential|commercial), customerEmail (max 45), customerName (max 45), customerPhone (max 45), paymentType (offlinePaymentProvider|thirdPartyPaymentProvider|walletPaymentProvider|otherPayment), shippingAmount (CENTS), terms (max 200), comments (max 200). Detail: amount can be '41.00' (dollars) or 4100 (cents). Tool always sends cents to publicAPI.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
companyCurrencyIdYesCompany currency ID (required)
companyGatewayIdYesCompany gateway ID (required)
detailYesLine items (required, at least one). Each: amount as '41.00' (dollars) or 4100 (cents). Tool always sends cents to publicAPI. description (max 255), qty
customerIdYesCustomer ID (required)
customerEmailNoCustomer email (max 45)
customerNameNoCustomer name (max 45)
customerPhoneNoCustomer phone (max 45)
paymentMethodIdYesPayment method ID (required)
customerPaymentMethodIdNoCustomer payment method ID
paymentTypeNoofflinePaymentProvider, thirdPartyPaymentProvider, walletPaymentProvider, or otherPayment
dateDueYesDue date (valid date). Required.
dateFromYesPeriod from (valid date). Required.
dateToYesPeriod to (valid date). Required.
billingAddressNoOptional. If provided: contactName, street1, city, zip, countryCode (ISO 3166-1 alpha-2 country code, e.g. ES, AR, MX), type (residential|commercial)
shippingAddressNoOptional. Same shape as billingAddress
shippingAmountNoShipping amount in CENTS
termsNoTerms (max 200)
commentsNoComments (max 200)

Implementation Reference

  • Main handler function for create_invoice. Parses input via Zod schema, normalizes amounts to cents, maps addresses, and calls invoiceService.createInvoice.
    async function handler(client: Client, args: Record<string, unknown> | undefined) {
      const parsed = schema.safeParse(args);
      if (!parsed.success) {
        return errorResult(formatValidationErrors(parsed.error));
      }
      const raw = parsed.data;
      const { customerPaymentMethodId: _customerPaymentMethodId, ...rest } = raw;
      const detail = raw.detail.map((item) => ({
        ...item,
        amount: normalizeAmountToCents(item.amount),
      }));
    
      let billingAddress: invoiceService.InvoiceAddressInput | undefined;
      let shippingAddress: invoiceService.InvoiceAddressInput | undefined;
      if (raw.billingAddress) {
        billingAddress = await mapShippingAddressInputToApiShippingAddress(client, raw.billingAddress);
      }
      if (raw.shippingAddress) {
        shippingAddress = await mapShippingAddressInputToApiShippingAddress(client, raw.shippingAddress);
      }
    
      const body: invoiceService.CreateInvoiceBody = {
        ...rest,
        detail,
        billingAddress,
        shippingAddress,
      };
      return handleToolCall(() => invoiceService.createInvoice(client, body));
    }
  • Zod input validation schema for create_invoice. Defines required fields (companyCurrencyId, companyGatewayId, customerId, paymentMethodId, detail, dateDue, dateFrom, dateTo) and optional fields (billingAddress, shippingAddress, etc.).
    const schema = z
      .object({
      companyCurrencyId: z.number().int().positive("companyCurrencyId is required"),
      companyGatewayId: z.number().int().positive("companyGatewayId is required"),
      customerId: z.number().int().positive("customerId is required"),
      paymentMethodId: z.number().int().positive("paymentMethodId is required"),
      detail: z.array(detailItemSchema).min(1, "detail must have at least one line item"),
      customerEmail: z.string().max(45).optional(),
      customerName: z.string().max(45).optional(),
      customerPhone: z.string().max(45).optional(),
      customerPaymentMethodId: z.number().int().optional(),
      paymentType: z.enum(paymentTypeEnum).optional(),
        dateDue: z
          .string({ required_error: "dateDue is required" })
          .min(1, "dateDue is required"),
        dateFrom: z
          .string({ required_error: "dateFrom is required" })
          .min(1, "dateFrom is required"),
        dateTo: z
          .string({ required_error: "dateTo is required" })
          .min(1, "dateTo is required"),
      billingAddress: z.preprocess(stripEmptyAddress, addressSchema.optional()),
      shippingAddress: z.preprocess(stripEmptyAddress, addressSchema.optional()),
      shippingAmount: z.number().int().min(0).optional(),
      terms: z.string().max(200).optional(),
      comments: z.string().max(200).optional(),
      });
  • TypeScript interface CreateInvoiceBody that defines the shape of the body sent to the POST /invoices API endpoint.
    export interface CreateInvoiceBody {
      companyCurrencyId: number;
      companyGatewayId: number;
      customerId: number;
      paymentMethodId: number;
      detail: InvoiceDetailItemInput[];
      customerEmail?: string;
      customerName?: string;
      customerPhone?: string;
      customerPaymentMethodId?: number;
      paymentType?: "offlinePaymentProvider" | "thirdPartyPaymentProvider" | "walletPaymentProvider" | "otherPayment";
      dateDue?: string;
      dateFrom?: string;
      dateTo?: string;
      billingAddress?: InvoiceAddressInput;
      shippingAddress?: InvoiceAddressInput;
      /** shippingAmount in CENTS */
      shippingAmount?: number;
      terms?: string;
      comments?: string;
      [k: string]: unknown;
    }
  • Registration of createInvoiceTool in the registerInvoiceTools() function that returns all invoice tools.
        createInvoiceTool,
        updateInvoiceTool,
        deleteInvoiceTool,
        chargeInvoiceTool,
        chargeInvoiceExternalTool,
        voidInvoiceTool,
      ];
    }
    
    export { listInvoicesTool } from "./listInvoices.js";
    export { getInvoiceTool } from "./getInvoice.js";
    export { createInvoiceTool } from "./createInvoice.js";
  • Helper functions moneyStringToCents and normalizeAmountToCents that convert dollar strings (e.g. '41.00') or integer cents to cents for the API.
    function moneyStringToCents(input: string): number {
      const s = input.trim();
      // If there's a decimal separator, treat as dollars with up to 2 decimals.
      if (s.includes(".")) {
        if (!/^\d+(\.\d{1,2})$/.test(s)) {
          throw new Error(
            `Invalid amount string "${input}". Expected a number like "41.00" (up to 2 decimals).`
          );
        }
        const [whole, frac] = s.split(".");
        const cents = Number(whole) * 100 + Number((frac + "00").slice(0, 2));
        return cents;
      }
      // No decimal point: treat as already-in-cents (backward compatibility with old behavior).
      if (!/^\d+$/.test(s)) {
        throw new Error(`Invalid amount string "${input}". Expected "41.00" or integer cents like "4100".`);
      }
      return Number(s);
    }
    
    function normalizeAmountToCents(amount: unknown): number {
      if (typeof amount === "number") {
        if (!Number.isInteger(amount) || amount < 0) throw new Error("amount must be a non-negative integer (cents)");
        return amount;
      }
      if (typeof amount === "string") {
        return moneyStringToCents(amount);
      }
      throw new Error("amount must be a number (cents) or string (e.g. '41.00' or '4100')");
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are present, so description carries full burden. It discloses the POST endpoint and that detail amount can be in dollars or cents (tool converts to cents). However, it omits side effects (e.g., auto-emailing), error handling, or idempotency. Adequate but not thorough for a creation action.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-organized: first sentence, then required, then optional, then detail specifics. It packs useful information but could be slightly more concise by not repeating max lengths already in schema. Still efficient and front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With 18 parameters and nested objects, the description covers required and optional fields thoroughly. However, it lacks output schema or any mention of the return value (e.g., invoice ID). This gap reduces completeness for a creation tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, but the description adds value by explaining allowed values for paymentType enum, sub-fields of billingAddress/shippingAddress, the dual amount format for detail, and the tool's conversion to cents. This goes beyond the schema's basic descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'Create an invoice.' and lists required/optional fields. It distinguishes from sibling tools like charge_invoice, update_invoice, void_invoice, and delete_invoice by focusing on creation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description enumerates required and optional parameters but does not specify when to use this tool vs alternatives (e.g., prerequisites like existing customer/currency) or when not to use it. No explicit usage context is provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rhinosaas/rebillia-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server