Activate Affiliate
whmcs_activate_affiliateActivate a client as an affiliate by providing their client ID to enable affiliate tracking and commissions.
Instructions
Activate a client as an affiliate
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| userid | Yes | Client ID |
Implementation Reference
- src/index.ts:1183-1198 (registration)Registration of the 'whmcs_activate_affiliate' tool with MCP server, defining its input schema (userid) and delegating to whmcsClient.affiliateActivate()
server.registerTool( 'whmcs_activate_affiliate', { title: 'Activate Affiliate', description: 'Activate a client as an affiliate', inputSchema: { userid: z.number().describe('Client ID'), }, }, async (params) => { const result = await whmcsClient.affiliateActivate(params); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; } ); - src/whmcs-client.ts:1373-1375 (handler)Handler function that calls the WHMCS 'AffiliateActivate' API action with the provided userid parameter, returning an affiliateid upon success
async affiliateActivate(params: { userid: number }) { return this.call<WhmcsApiResponse & { affiliateid: number }>('AffiliateActivate', params); } - src/index.ts:1188-1191 (schema)Input validation schema for the tool - requires a single 'userid' (number) field representing the client ID to activate as an affiliate
inputSchema: { userid: z.number().describe('Client ID'), }, }, - src/whmcs-client.ts:29-63 (helper)Generic API request helper used by affiliateActivate to call the WHMCS API with authentication 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; }