Skip to main content
Glama

update_invoice

Update an invoice with status 'posted' or 'requestPayment' by modifying optional fields: customer details, dates, payment type, shipping address, and line items.

Instructions

Update an invoice. PUT /invoices/{invoiceId}. Only invoices with status 'posted' or 'requestPayment' can be updated. All body fields optional. Accepted: companyGatewayId, customerId, customerEmail, customerName, customerPhone (max 45), customerPaymentMethodId, dateDue, dateFrom, dateTo, comments, paymentType (offlinePaymentProvider|thirdPartyPaymentProvider|walletPaymentProvider), paymentMethodId, shippingAddress (when provided: contactName, street1, city, zip, countryCode (ISO 3166-1 alpha-2), type residential|commercial), shippingAmount (cents), shippingServiceId, detail (line items: amount as '41.00' dollars or 4100 cents; tool sends cents). Note: billingAddress is not accepted on update. Invoice must have customer and customerPaymentMethod set to avoid server error.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
invoiceIdYesInvoice ID (required)
companyGatewayIdNoCompany gateway ID
customerIdNoCustomer ID
customerEmailNoCustomer email (max 45)
customerNameNoCustomer name (max 45)
customerPhoneNoCustomer phone (max 45)
customerPaymentMethodIdNoCustomer payment method ID
dateDueNoDue date (valid date)
dateFromNoPeriod from (valid date)
dateToNoPeriod to (valid date)
commentsNoComments
paymentTypeNoofflinePaymentProvider, thirdPartyPaymentProvider, or walletPaymentProvider
paymentMethodIdNoPayment method ID
shippingAddressNoWhen provided: contactName, street1, city, zip, countryCode (ISO 3166-1 alpha-2 country code, e.g. ES, AR, MX), type (residential|commercial)
shippingAmountNoShipping amount in CENTS
shippingServiceIdNoShipping service ID
detailNoLine items: each { amount: '41.00' (dollars) or 4100 (cents), description?, qty? }

Implementation Reference

  • The handler function that parses args, transforms amounts to cents, maps shipping address, and calls the service layer's updateInvoice.
    async function handler(client: Client, args: Record<string, unknown> | undefined) {
      const parsed = schema.safeParse(args);
      if (!parsed.success) {
        return errorResult(parsed.error.errors.map((e) => e.message).join("; "));
      }
      const { invoiceId, shippingAddress: rawShipping, ...rest } = parsed.data;
      let shippingAddress: invoiceService.InvoiceAddressInput | undefined;
      if (rawShipping) {
        shippingAddress = await mapShippingAddressInputToApiShippingAddress(client, rawShipping);
      }
      const detail = rest.detail
        ? rest.detail.map((item) => ({
            ...item,
            amount: normalizeAmountToCents(item.amount),
          }))
        : undefined;
    
      const body: invoiceService.UpdateInvoiceBody = {
        ...rest,
        detail,
        shippingAddress,
      };
      return handleToolCall(() => invoiceService.updateInvoice(client, invoiceId, body));
    }
  • Zod validation schema for the update_invoice tool's input parameters.
    const schema = z.object({
      invoiceId: z.string().min(1, "invoiceId is required"),
      companyGatewayId: z.number().int().positive().optional(),
      customerId: z.number().int().positive().optional(),
      customerEmail: z.string().max(45).optional(),
      customerName: z.string().max(45).optional(),
      customerPhone: z.string().max(45).optional(),
      customerPaymentMethodId: z.number().int().optional(),
      dateDue: z.string().optional(),
      dateFrom: z.string().optional(),
      dateTo: z.string().optional(),
      comments: z.string().optional(),
      paymentType: z.enum(paymentTypeEnum).optional(),
      paymentMethodId: z.number().int().optional(),
      shippingAddress: addressSchema.optional(),
      shippingAmount: z.number().int().min(0).optional(),
      shippingServiceId: z.string().optional(),
      detail: z.array(detailItemSchema).optional(),
    });
  • TypeScript interface for the update invoice request body passed to the service layer.
    export interface UpdateInvoiceBody {
      companyGatewayId?: number;
      customerId?: number;
      customerEmail?: string;
      customerName?: string;
      customerPhone?: string;
      customerPaymentMethodId?: number;
      dateDue?: string;
      dateFrom?: string;
      dateTo?: string;
      comments?: string;
      paymentType?: "offlinePaymentProvider" | "thirdPartyPaymentProvider" | "walletPaymentProvider";
      paymentMethodId?: number;
      shippingAddress?: InvoiceAddressInput;
      shippingAmount?: number;
      shippingServiceId?: string;
      detail?: InvoiceDetailItemInput[];
      [k: string]: unknown;
    }
  • Registration of updateInvoiceTool alongside all other invoice tools.
    export function registerInvoiceTools(): Tool[] {
      return [
        listInvoicesTool,
        getInvoiceTool,
        createInvoiceTool,
        updateInvoiceTool,
        deleteInvoiceTool,
        chargeInvoiceTool,
        chargeInvoiceExternalTool,
        voidInvoiceTool,
      ];
    }
  • Service-layer helper that performs the PUT /invoices/{invoiceId} HTTP call.
    export async function updateInvoice(
      client: Client,
      invoiceId: string,
      body: UpdateInvoiceBody
    ): Promise<unknown> {
      const payload = Object.fromEntries(
        Object.entries(body).filter(([, v]) => v !== undefined)
      ) as UpdateInvoiceBody;
      // Always send a JSON body; some server paths expect it and may throw getId() on null when body is missing
      return client.put<unknown>(`/invoices/${invoiceId}`, Object.keys(payload).length ? payload : {});
    }
Behavior4/5

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

With no annotations, the description covers important behavioral traits: which statuses are required, that billingAddress is not accepted, and that customer and customerPaymentMethod must be set to avoid server error. It also lists constraints on certain fields. However, side effects beyond the update are not addressed.

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 fairly long but well-organized, front-loading the key purpose and status condition. It enumerates fields and constraints systematically. A minor improvement would be to separate constraints into bullet points for clarity, but it remains concise for the amount of detail provided.

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

Completeness4/5

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

Given the complexity (17 parameters, nested objects, no output schema), the description covers essential constraints like allowed statuses, optionality, and field formats. It warns about the server error condition. It could be more complete by describing return behavior, but it adequately supports agent decision-making.

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%, so schema already describes parameters. The description adds value by noting that all fields are optional, the allowed values for paymentType, the structure of shippingAddress and detail, and the restriction on billingAddress. This enriches agent understanding beyond bare schema.

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?

Description clearly states 'Update an invoice' and identifies the HTTP method and path. It distinguishes from other invoice-related tools like charge_invoice or void_invoice by specifying the allowed invoice statuses and update-specific fields.

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

Usage Guidelines4/5

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

Specifies that only invoices with status 'posted' or 'requestPayment' can be updated, and that all body fields are optional. However, it does not explicitly compare with sibling tools like charge_invoice or void_invoice to guide when to use this tool vs alternatives.

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