Get Tickets
whmcs_get_ticketsRetrieve support tickets with optional filters for department, client, status, or subject to manage inquiries efficiently.
Instructions
Get support tickets with optional filtering
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limitstart | No | Starting offset | |
| limitnum | No | Number of results | |
| deptid | No | Filter by department ID | |
| clientid | No | Filter by client ID | |
| No | Filter by email | ||
| status | No | Filter by status | |
| subject | No | Filter by subject |
Implementation Reference
- src/index.ts:414-435 (registration)Registration of the 'whmcs_get_tickets' MCP tool with input schema and handler that delegates to whmcsClient.getTickets()
server.registerTool( 'whmcs_get_tickets', { title: 'Get Tickets', description: 'Get support tickets with optional filtering', inputSchema: { limitstart: z.number().optional().describe('Starting offset'), limitnum: z.number().optional().describe('Number of results'), deptid: z.number().optional().describe('Filter by department ID'), clientid: z.number().optional().describe('Filter by client ID'), email: z.string().optional().describe('Filter by email'), status: z.string().optional().describe('Filter by status'), subject: z.string().optional().describe('Filter by subject'), }, }, async (params) => { const result = await whmcsClient.getTickets(params); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; } ); - src/index.ts:419-428 (schema)Input schema definition for whmcs_get_tickets using Zod validation - defines optional parameters for filtering tickets (limitstart, limitnum, deptid, clientid, email, status, subject)
inputSchema: { limitstart: z.number().optional().describe('Starting offset'), limitnum: z.number().optional().describe('Number of results'), deptid: z.number().optional().describe('Filter by department ID'), clientid: z.number().optional().describe('Filter by client ID'), email: z.string().optional().describe('Filter by email'), status: z.string().optional().describe('Filter by status'), subject: z.string().optional().describe('Filter by subject'), }, }, - src/whmcs-client.ts:611-649 (handler)The actual handler implementation - getTickets() method on WhmcsApiClient that calls the WHMCS API 'GetTickets' action with typed parameters and return shape
/** * Get support tickets */ async getTickets(params: { limitstart?: number; limitnum?: number; deptid?: number; clientid?: number; email?: string; status?: string; subject?: string; ignore_dept_assignments?: boolean; } = {}) { return this.call<WhmcsApiResponse & { totalresults: number; startnumber: number; numreturned: number; tickets: { ticket: Array<{ id: number; tid: string; deptid: number; deptname: string; userid: number; name: string; email: string; cc: string; c: string; date: string; subject: string; status: string; priority: string; admin: string; attachment: string; lastreply: string; flag: number; service: string; }> }; }>('GetTickets', params); } - src/whmcs-client.ts:29-63 (helper)Generic API call helper method used by getTickets() - handles authentication, POST request to WHMCS API, and error checking
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; }