Skip to main content
Glama

whmcs_get_invoice

Retrieve detailed invoice information from WHMCS by providing the invoice ID. Use this tool to access billing details and manage client invoices.

Instructions

Get detailed information about a specific invoice

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
invoiceidYesThe invoice ID

Implementation Reference

  • The core handler function that makes the WHMCS API call to retrieve detailed invoice information using the 'GetInvoice' action.
    async getInvoice(params: { invoiceid: number }) { return this.call<WhmcsApiResponse & { invoiceid: number; invoicenum: string; userid: number; date: string; duedate: string; datepaid: string; status: string; paymentmethod: string; paymethodid: string | null; subtotal: string; credit: string; tax: string; tax2: string; total: string; balance: string; taxrate: string; taxrate2: string; currencycode: string; currencyprefix: string; currencysuffix: string; notes: string; ccgateway: boolean; items: { item: Array<{ id: number; type: string; relid: number; description: string; amount: string; taxed: number; }> }; transactions: { transaction: Array<{ id: number; userid: number; currency: number; gateway: string; date: string; description: string; amountin: string; amountout: string; rate: string; transid: string; invoiceid: number; refundid: number; }> }; }>('GetInvoice', params); }
  • src/index.ts:280-295 (registration)
    Registers the 'whmcs_get_invoice' tool with MCP server, including schema validation using Zod and the thin wrapper handler.
    server.registerTool( 'whmcs_get_invoice', { title: 'Get Invoice Details', description: 'Get detailed information about a specific invoice', inputSchema: { invoiceid: z.number().describe('The invoice ID'), }, }, async (params) => { const result = await whmcsClient.getInvoice(params); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; } );
  • Zod schema for input validation: requires invoiceid as a number.
    inputSchema: { invoiceid: z.number().describe('The invoice ID'), },
  • The generic API call method used by getInvoice to communicate with WHMCS API, including param flattening and error handling.
    async call<T extends WhmcsApiResponse>(action: string, params: Record<string, unknown> = {}): Promise<T> { const url = `${this.config.apiUrl.replace(/\/$/, '')}/includes/api.php`; const postData: Record<string, string> = { identifier: this.config.apiIdentifier, secret: this.config.apiSecret, action: action, responsetype: 'json', ...this.flattenParams(params) }; if (this.config.accessKey) { postData.accesskey = this.config.accessKey; } const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: new URLSearchParams(postData).toString(), }); if (!response.ok) { throw new Error(`WHMCS API request failed: ${response.status} ${response.statusText}`); } const data = await response.json() as T; if (data.result === 'error') { throw new Error(`WHMCS API error: ${data.message || 'Unknown error'}`); } return data; }

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/scarecr0w12/whmcs-mcp-server'

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