whmcs_apply_credit
Apply credit to WHMCS invoices by specifying invoice ID and amount. Optionally disable email notifications for the transaction.
Instructions
Apply credit to an invoice
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| invoiceid | Yes | Invoice ID | |
| amount | Yes | Amount of credit to apply | |
| noemail | No | Do not send email |
Implementation Reference
- src/whmcs-client.ts:570-576 (handler)Core implementation of the applyCredit functionality: calls the WHMCS API 'ApplyCredit' action with the provided parameters.async applyCredit(params: { invoiceid: number; amount: number; noemail?: boolean; }) { return this.call<WhmcsApiResponse & { invoiceid: number }>('ApplyCredit', params); }
- src/index.ts:373-389 (registration)Registers the 'whmcs_apply_credit' tool in the MCP server, providing input schema validation and a thin handler wrapper that delegates to WhmcsApiClient.applyCredit and formats the response.'whmcs_apply_credit', { title: 'Apply Credit', description: 'Apply credit to an invoice', inputSchema: { invoiceid: z.number().describe('Invoice ID'), amount: z.number().describe('Amount of credit to apply'), noemail: z.boolean().optional().describe('Do not send email'), }, }, async (params) => { const result = await whmcsClient.applyCredit(params); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; } );
- src/index.ts:377-381 (schema)Zod input schema for the whmcs_apply_credit tool defining required invoiceid, amount, and optional noemail parameters.inputSchema: { invoiceid: z.number().describe('Invoice ID'), amount: z.number().describe('Amount of credit to apply'), noemail: z.boolean().optional().describe('Do not send email'), },
- src/whmcs-client.ts:29-63 (helper)Generic helper method used by all API actions including applyCredit to make authenticated POST requests to the WHMCS API endpoint.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; }