UNPKG

@oxheberg/whmcs-api

Version:

A fully featured and type-safe TypeScript client for the WHMCS API. Includes all official endpoints, modular design, helpful errors, and built with modern developer experience in mind.

1,610 lines (1,603 loc) 103 kB
// src/modules/addons.ts var createAddonsModule = (callApi) => ({ /** * Updates a client addon with new status, dates, or other properties. * * @param params - Addon ID and properties to update including status, dates, and notes * @returns Promise resolving to success confirmation * * @example * ```typescript * await client.addons.updateClientAddon({ * id: 1, * status: 'Active', * nextduedate: '2024-12-01', * notes: 'Updated addon configuration' * }); * ``` * * @see https://developers.whmcs.com/api-reference/updateclientaddon/ */ updateClientAddon: (params) => callApi("UpdateClientAddon", params) }); // src/modules/affiliates.ts function createAffiliatesModule(callApi) { return { /** * Activate affiliate referrals for a specified client * * @param params - Parameters for activating affiliate * @param params.userid - The client ID to activate affiliate status for * @returns Promise resolving to success response * * @example * ```typescript * const result = await client.affiliates.activateAffiliate({ * userid: 1 * }); * console.log(result.result); // 'success' * ``` * * @see https://developers.whmcs.com/api-reference/affiliateactivate/ */ activateAffiliate: (params) => callApi("AffiliateActivate", params), /** * Retrieve a list of affiliates * * @param params - Optional parameters for filtering affiliates * @param params.limitstart - The offset for the returned affiliate data (default: 0) * @param params.limitnum - The number of records to return (default: 25) * @param params.userid - Obtain affiliate data for a specific client account * @param params.visitors - Provide affiliates that match a specific visitor count * @param params.paytype - Provide affiliates matching the paytype provided * @param params.payamount - Provide affiliates matching a specific overridden payout amount * @param params.onetime - Provide affiliates configured to receive one time affiliates * @param params.balance - Provide affiliates that have this balance * @param params.withdrawn - Provide affiliates that have withdrawn this amount * @returns Promise resolving to affiliates data * * @example * ```typescript * // Get all affiliates * const affiliates = await client.affiliates.getAffiliates(); * * // Get affiliates for specific client * const clientAffiliates = await client.affiliates.getAffiliates({ * userid: 1 * }); * * // Get affiliates with pagination * const paginatedAffiliates = await client.affiliates.getAffiliates({ * limitstart: 0, * limitnum: 10 * }); * ``` * * @see https://developers.whmcs.com/api-reference/getaffiliates/ */ getAffiliates: (params = {}) => callApi("GetAffiliates", params) }; } // src/modules/authentication.ts var createAuthenticationModule = (callApi) => ({ /** * Creates a new OAuth credential for API access or single sign-on. * * @param params - Grant type, scope, and optional configuration for the OAuth credential * @returns Promise resolving to new credential details including client ID and secret * * @example * ```typescript * const response = await client.authentication.createOAuthCredential({ * grantType: 'single_sign_on', * scope: 'clientarea:sso clientarea:billing_info', * serviceId: 1, * description: 'SSO for billing portal' * }); * console.log(response.clientIdentifier, response.clientSecret); * ``` * * @see https://developers.whmcs.com/api-reference/createoauthcredential/ */ createOAuthCredential: (params) => callApi("CreateOAuthCredential", params), /** * Creates a single-use SSO token for client or user authentication. * * @param params - Optional client/user ID, destination, and service context * @returns Promise resolving to access token and redirect URL * * @example * ```typescript * const response = await client.authentication.createSsoToken({ * client_id: 123, * destination: 'clientarea:product_details', * service_id: 1 * }); * console.log(response.access_token, response.redirect_url); * ``` * * @see https://developers.whmcs.com/api-reference/createssotoken/ */ createSsoToken: (params = {}) => callApi("CreateSsoToken", params), /** * Permanently deletes an OAuth credential record. * * @param params - Credential ID to delete * @returns Promise resolving to confirmation with deleted credential ID * * @example * ```typescript * const response = await client.authentication.deleteOAuthCredential({ * credentialId: 1 * }); * console.log('Deleted credential:', response.credentialId); * ``` * * @see https://developers.whmcs.com/api-reference/deleteoauthcredential/ */ deleteOAuthCredential: (params) => callApi("DeleteOAuthCredential", params), /** * Retrieves a list of OAuth credentials matching specified criteria. * * @param params - Optional filtering, sorting, and pagination parameters * @returns Promise resolving to list of OAuth credentials with details * * @example * ```typescript * const response = await client.authentication.listOAuthCredentials({ * grantType: 'single_sign_on', * limit: 10 * }); * console.log(response.clients); * ``` * * @see https://developers.whmcs.com/api-reference/listoauthcredentials/ */ listOAuthCredentials: (params = {}) => callApi("ListOAuthCredentials", params), /** * Updates an existing OAuth credential configuration. * * @param params - Credential ID/identifier and properties to update * @returns Promise resolving to updated credential details * * @example * ```typescript * const response = await client.authentication.updateOAuthCredential({ * credentialId: 1, * name: 'Updated Credential Name', * resetSecret: true * }); * console.log('New secret:', response.newClientSecret); * ``` * * @see https://developers.whmcs.com/api-reference/updateoauthcredential/ */ updateOAuthCredential: (params) => callApi("UpdateOAuthCredential", params), /** * Validates user login credentials and creates an authentication session. * * @param params - Email address and password to validate * @returns Promise resolving to user ID, password hash, and 2FA status * * @example * ```typescript * const response = await client.authentication.validateLogin({ * email: 'user@example.com', * password2: 'userpassword' * }); * console.log('User ID:', response.userid); * if (response.passwordhash) { * console.log('Session token:', response.passwordhash); * } * ``` * * @see https://developers.whmcs.com/api-reference/validatelogin/ */ validateLogin: (params) => callApi("ValidateLogin", params) }); // src/modules/billing.ts var createBillingModule = (callApi) => ({ /** * Accept a quote and convert it to an invoice * * @param params - The parameters for accepting a quote * @returns Promise that resolves when the quote is accepted * * @example * ```typescript * await client.billing.acceptQuote({ * quoteid: 123 * }); * ``` * * @see https://developers.whmcs.com/api-reference/acceptquote */ acceptQuote: (params) => callApi("AcceptQuote", params), /** * Add a billable item to a client's account * * @param params - The parameters for adding a billable item * @returns Promise that resolves when the billable item is added * * @example * ```typescript * await client.billing.addBillableItem({ * clientid: 1, * description: 'Additional Service', * amount: 50.00, * invoiceaction: 'nextinvoice', * duedate: '2024-12-31' * }); * ``` * * @see https://developers.whmcs.com/api-reference/addbillableitem */ addBillableItem: (params) => callApi("AddBillableItem", params), /** * Add credit to a client's account * * @param params - The parameters for adding credit * @returns Promise that resolves with the new credit balance * * @example * ```typescript * const result = await client.billing.addCredit({ * clientid: 1, * description: 'Refund for overpayment', * amount: 25.00, * type: 'add' * }); * console.log(`New balance: ${result.newbalance}`); * ``` * * @see https://developers.whmcs.com/api-reference/addcredit */ addCredit: (params) => callApi("AddCredit", params), /** * Add a payment to an invoice * * @param params - The parameters for adding a payment * @returns Promise that resolves when the payment is added * * @example * ```typescript * await client.billing.addInvoicePayment({ * invoiceid: 123, * transid: 'TXN_123456', * gateway: 'paypal', * date: '2024-01-15 14:30:00', * amount: 100.00, * fees: 3.50 * }); * ``` * * @see https://developers.whmcs.com/api-reference/addinvoicepayment */ addInvoicePayment: (params) => callApi("AddInvoicePayment", params), /** * Add a payment method to a client's account * * @param params - The parameters for adding a payment method * @returns Promise that resolves when the payment method is added * * @example * ```typescript * await client.billing.addPayMethod({ * clientid: 1, * type: 'bankaccount', * description: 'Primary Bank Account', * bank_name: 'Example Bank', * account_number: '123456789', * routing_number: '987654321', * set_as_default: true * }); * ``` * * @see https://developers.whmcs.com/api-reference/addpaymethod */ addPayMethod: (params) => callApi("AddPayMethod", params), /** * Add a transaction record * * @param params - The parameters for adding a transaction * @returns Promise that resolves when the transaction is added * * @example * ```typescript * await client.billing.addTransaction({ * gateway: 'paypal', * date: '2024-01-15 14:30:00', * description: 'Payment for Invoice #123', * amountin: 100.00, * fees: 3.50, * transid: 'TXN_123456', * invoiceid: 123 * }); * ``` * * @see https://developers.whmcs.com/api-reference/addtransaction */ addTransaction: (params) => callApi("AddTransaction", params), /** * Apply credit to an invoice * * @param params - The parameters for applying credit * @returns Promise that resolves with credit application details * * @example * ```typescript * const result = await client.billing.applyCredit({ * invoiceid: 123, * amount: 50.00, * noemail: false * }); * console.log(`Applied ${result.amount} credit to invoice ${result.invoiceid}`); * ``` * * @see https://developers.whmcs.com/api-reference/applycredit */ applyCredit: (params) => callApi("ApplyCredit", params), /** * Capture payment for an invoice * * @param params - The parameters for capturing payment * @returns Promise that resolves when payment is captured * * @example * ```typescript * await client.billing.capturePayment({ * invoiceid: 123 * }); * ``` * * @see https://developers.whmcs.com/api-reference/capturepayment */ capturePayment: (params) => callApi("CapturePayment", params), /** * Create a new invoice * * @param params - The parameters for creating an invoice * @returns Promise that resolves with the new invoice ID * * @example * ```typescript * const result = await client.billing.createInvoice({ * userid: 1, * date: '2024-01-15', * duedate: '2024-02-15', * itemdescription1: 'Web Hosting Service', * itemamount1: 50.00, * itemtaxed1: true, * sendinvoice: true * }); * console.log(`Invoice created with ID: ${result.invoiceid}`); * ``` * * @see https://developers.whmcs.com/api-reference/createinvoice */ createInvoice: (params) => callApi("CreateInvoice", params), /** * Create a new quote * * @param params - The parameters for creating a quote * @returns Promise that resolves with the new quote ID * * @example * ```typescript * const result = await client.billing.createQuote({ * userid: 1, * subject: 'Website Development Quote', * stage: 'Draft', * validuntil: '2024-03-15', * lineitems: [ * { * description: 'Web Design', * qty: 1, * up: 1500.00, * taxable: true * }, * { * description: 'Domain Registration', * qty: 1, * up: 15.00, * taxable: false * } * ] * }); * console.log(`Quote created with ID: ${result.quoteid}`); * ``` * * @see https://developers.whmcs.com/api-reference/createquote */ createQuote: (params) => callApi("CreateQuote", params), /** * Delete a payment method * * @param params - The parameters for deleting a payment method * @returns Promise that resolves when the payment method is deleted * * @example * ```typescript * await client.billing.deletePayMethod({ * paymethodid: 123 * }); * ``` * * @see https://developers.whmcs.com/api-reference/deletepaymethod */ deletePayMethod: (params) => callApi("DeletePayMethod", params), /** * Delete a quote * * @param params - The parameters for deleting a quote * @returns Promise that resolves when the quote is deleted * * @example * ```typescript * await client.billing.deleteQuote({ * quoteid: 123 * }); * ``` * * @see https://developers.whmcs.com/api-reference/deletequote */ deleteQuote: (params) => callApi("DeleteQuote", params), /** * Generate invoices for recurring services * * @param params - Optional parameters for invoice generation * @returns Promise that resolves with the number of invoices created * * @example * ```typescript * const result = await client.billing.genInvoices({ * noemail: false, * clientid: 1 * }); * console.log(`Generated ${result.numcreated} invoices`); * ``` * * @see https://developers.whmcs.com/api-reference/geninvoices */ genInvoices: (params = {}) => callApi("GenInvoices", params), /** * Retrieve credit entries * * @param params - Optional parameters for filtering credits * @returns Promise that resolves with the list of credits * * @example * ```typescript * const result = await client.billing.getCredits({ * clientid: 1, * limitstart: 0, * limitnum: 25 * }); * console.log(`Found ${result.totalresults} credit entries`); * ``` * * @see https://developers.whmcs.com/api-reference/getcredits */ getCredits: (params = {}) => callApi("GetCredits", params), /** * Retrieve details of a specific invoice * * @param params - The parameters for retrieving an invoice * @returns Promise that resolves with the invoice details * * @example * ```typescript * const result = await client.billing.getInvoice({ * invoiceid: 123 * }); * console.log(`Invoice #${result.invoicenum} - Total: ${result.total}`); * ``` * * @see https://developers.whmcs.com/api-reference/getinvoice */ getInvoice: (params) => callApi("GetInvoice", params), /** * Retrieve a list of invoices * * @param params - Optional parameters for filtering invoices * @returns Promise that resolves with the list of invoices * * @example * ```typescript * const result = await client.billing.getInvoices({ * limitstart: 0, * limitnum: 25, * userid: 1, * status: 'Unpaid' * }); * console.log(`Found ${result.totalresults} invoices`); * ``` * * @see https://developers.whmcs.com/api-reference/getinvoices */ getInvoices: (params = {}) => callApi("GetInvoices", params), /** * Retrieve payment methods for a client * * @param params - The parameters for retrieving payment methods * @returns Promise that resolves with the list of payment methods * * @example * ```typescript * const result = await client.billing.getPayMethods({ * clientid: 1 * }); * result.paymethods.paymethod.forEach(method => { * console.log(`${method.description} (${method.payment_type})`); * }); * ``` * * @see https://developers.whmcs.com/api-reference/getpaymethods */ getPayMethods: (params) => callApi("GetPayMethods", params), /** * Retrieve a list of quotes * * @param params - Optional parameters for filtering quotes * @returns Promise that resolves with the list of quotes * * @example * ```typescript * const result = await client.billing.getQuotes({ * limitstart: 0, * limitnum: 25, * userid: 1, * stage: 'Sent' * }); * console.log(`Found ${result.totalresults} quotes`); * ``` * * @see https://developers.whmcs.com/api-reference/getquotes */ getQuotes: (params = {}) => callApi("GetQuotes", params), /** * Retrieve transaction records * * @param params - Optional parameters for filtering transactions * @returns Promise that resolves with the list of transactions * * @example * ```typescript * const result = await client.billing.getTransactions({ * clientid: 1, * limitstart: 0, * limitnum: 25 * }); * console.log(`Found ${result.totalresults} transactions`); * ``` * * @see https://developers.whmcs.com/api-reference/gettransactions */ getTransactions: (params = {}) => callApi("GetTransactions", params), /** * Send a quote to the client * * @param params - The parameters for sending a quote * @returns Promise that resolves when the quote is sent * * @example * ```typescript * await client.billing.sendQuote({ * quoteid: 123 * }); * ``` * * @see https://developers.whmcs.com/api-reference/sendquote */ sendQuote: (params) => callApi("SendQuote", params), /** * Update an existing invoice * * @param params - The parameters for updating an invoice * @returns Promise that resolves when the invoice is updated * * @example * ```typescript * await client.billing.updateInvoice({ * invoiceid: 123, * itemdescription: ['Updated Service Description'], * itemamount: [75.00], * itemtaxed: [true], * duedate: '2024-03-15', * notes: 'Updated invoice terms' * }); * ``` * * @see https://developers.whmcs.com/api-reference/updateinvoice */ updateInvoice: (params) => callApi("UpdateInvoice", params), /** * Update a payment method * * @param params - The parameters for updating a payment method * @returns Promise that resolves when the payment method is updated * * @example * ```typescript * await client.billing.updatePayMethod({ * paymethodid: 123, * description: 'Updated Payment Method', * set_as_default: true * }); * ``` * * @see https://developers.whmcs.com/api-reference/updatepaymethod */ updatePayMethod: (params) => callApi("UpdatePayMethod", params), /** * Update an existing quote * * @param params - The parameters for updating a quote * @returns Promise that resolves when the quote is updated * * @example * ```typescript * await client.billing.updateQuote({ * quoteid: 123, * subject: 'Updated Quote Subject', * stage: 'Sent', * validuntil: '2024-04-15', * lineitems: [ * { * id: 1, * description: 'Updated Service', * qty: 2, * up: 100.00 * } * ] * }); * ``` * * @see https://developers.whmcs.com/api-reference/updatequote */ updateQuote: (params) => callApi("UpdateQuote", params), /** * Update a transaction record * * @param params - The parameters for updating a transaction * @returns Promise that resolves when the transaction is updated * * @example * ```typescript * await client.billing.updateTransaction({ * transactionid: 123, * description: 'Updated Payment Description', * amountin: 110.00, * fees: 4.00 * }); * ``` * * @see https://developers.whmcs.com/api-reference/updatetransaction */ updateTransaction: (params) => callApi("UpdateTransaction", params) }); // src/modules/client.ts var createClientModule = (callApi) => ({ /** * Add a new client to the system * * @param params - The parameters for creating a client * @returns Promise that resolves with the new client ID * * @example * ```typescript * const result = await client.client.addClient({ * firstname: 'John', * lastname: 'Doe', * email: 'john.doe@example.com', * address1: '123 Main Street', * city: 'New York', * state: 'NY', * postcode: '10001', * country: 'US', * phonenumber: '+1-555-123-4567', * password2: 'securepassword123', * currency: 1, * notes: 'VIP client - requires priority support' * }); * console.log(`Client created with ID: ${result.clientid}`); * ``` * * @see https://developers.whmcs.com/api-reference/addclient */ addClient: (params) => callApi("AddClient", params), /** * Add a contact to an existing client * * @param params - The parameters for creating a contact * @returns Promise that resolves with the new contact ID * * @example * ```typescript * const result = await client.client.addContact({ * clientid: 1, * firstname: 'Jane', * lastname: 'Doe', * email: 'jane.doe@example.com', * address1: '123 Main Street', * city: 'New York', * state: 'NY', * postcode: '10001', * country: 'US', * phonenumber: '+1-555-123-4568', * permissions: 'profile,contacts,products,tickets' * }); * console.log(`Contact created with ID: ${result.contactid}`); * ``` * * @see https://developers.whmcs.com/api-reference/addcontact */ addContact: (params) => callApi("AddContact", params), /** * Close a client account * * @param params - The parameters for closing a client * @returns Promise that resolves when the client is closed * * @example * ```typescript * await client.client.closeClient({ * clientid: 123 * }); * ``` * * @see https://developers.whmcs.com/api-reference/closeclient */ closeClient: (params) => callApi("CloseClient", params), /** * Delete a client from the system * * @param params - The parameters for deleting a client * @returns Promise that resolves when the client is deleted * * @example * ```typescript * await client.client.deleteClient({ * clientid: 123, * deleteusers: true, * deletetransactions: false * }); * ``` * * @see https://developers.whmcs.com/api-reference/deleteclient */ deleteClient: (params) => callApi("DeleteClient", params), /** * Delete a contact from a client * * @param params - The parameters for deleting a contact * @returns Promise that resolves when the contact is deleted * * @example * ```typescript * await client.client.deleteContact({ * contactid: 123 * }); * ``` * * @see https://developers.whmcs.com/api-reference/deletecontact */ deleteContact: (params) => callApi("DeleteContact", params), /** * Retrieve cancelled packages for clients * * @param params - Optional parameters for filtering cancelled packages * @returns Promise that resolves with the list of cancelled packages * * @example * ```typescript * const result = await client.client.getCancelledPackages({ * limitstart: 0, * limitnum: 25, * clientid: 1 * }); * console.log(`Found ${result.totalresults} cancelled packages`); * ``` * * @see https://developers.whmcs.com/api-reference/getcancelledpackages */ getCancelledPackages: (params = {}) => callApi("GetCancelledPackages", params), /** * Retrieve client groups * * @param params - Optional parameters for filtering client groups * @returns Promise that resolves with the list of client groups * * @example * ```typescript * const result = await client.client.getClientGroups({ * limitstart: 0, * limitnum: 25 * }); * console.log(`Found ${result.totalresults} client groups`); * ``` * * @see https://developers.whmcs.com/api-reference/getclientgroups */ getClientGroups: (params = {}) => callApi("GetClientGroups", params), /** * Retrieve a client's password * * @param params - The parameters for retrieving client password * @returns Promise that resolves with the client password * * @example * ```typescript * const result = await client.client.getClientPassword({ * userid: 1 * }); * console.log(`Client password: ${result.password}`); * ``` * * @see https://developers.whmcs.com/api-reference/getclientpassword */ getClientPassword: (params) => callApi("GetClientPassword", params), /** * Retrieve a list of clients * * @param params - Optional parameters for filtering clients * @returns Promise that resolves with the list of clients * * @example * ```typescript * const result = await client.client.getClients({ * limitstart: 0, * limitnum: 25, * search: 'john', * status: 'Active' * }); * console.log(`Found ${result.totalresults} clients`); * ``` * * @see https://developers.whmcs.com/api-reference/getclients */ getClients: (params = {}) => callApi("GetClients", params), /** * Retrieve addons for a client * * @param params - The parameters for retrieving client addons * @returns Promise that resolves with the list of client addons * * @example * ```typescript * const result = await client.client.getClientsAddons({ * clientid: 1, * limitstart: 0, * limitnum: 25 * }); * console.log(`Found ${result.totalresults} addons`); * ``` * * @see https://developers.whmcs.com/api-reference/getclientsaddons */ getClientsAddons: (params) => callApi("GetClientsAddons", params), /** * Retrieve detailed information about a client * * @param params - The parameters for retrieving client details * @returns Promise that resolves with the client details * * @example * ```typescript * const result = await client.client.getClientsDetails({ * clientid: 1, * stats: true * }); * console.log(`Client: ${result.client.firstname} ${result.client.lastname} (${result.client.email})`); * ``` * * @see https://developers.whmcs.com/api-reference/getclientsdetails */ getClientsDetails: async (params) => { const response = await callApi("GetClientsDetails", params); return { result: response.result, client: { id: response.client.id, owner_user_id: response.client.owner_user_id, uuid: response.client.uuid, firstname: response.client.firstname, lastname: response.client.lastname, fullname: response.client.fullname, companyname: response.client.companyname, email: response.client.email, address1: response.client.address1, address2: response.client.address2, city: response.client.city, state: response.client.state, postcode: response.client.postcode, countrycode: response.client.countrycode, country: response.client.country, phonenumber: response.client.phonenumber, tax_id: response.client.tax_id, email_preferences: { general: Boolean(response.client.email_preferences.general), invoice: Boolean(response.client.email_preferences.invoice), support: Boolean(response.client.email_preferences.support), product: Boolean(response.client.email_preferences.product), domain: Boolean(response.client.email_preferences.domain), affiliate: Boolean(response.client.email_preferences.affiliate) }, countryname: response.client.countryname, phonecc: response.client.phonecc, phonenumberformatted: response.client.phonenumberformatted, billingcid: response.client.billingcid, notes: response.client.notes, currency: response.client.currency, currency_code: response.client.currency_code, defaultgateway: response.client.defaultgateway, groupid: response.client.groupid, status: response.client.status, credit: response.client.credit, taxexempt: response.client.taxexempt, latefeeoveride: response.client.latefeeoveride, overideduenotices: response.client.overideduenotices, separateinvoices: response.client.separateinvoices, disableautocc: response.client.disableautocc, emailoptout: response.client.emailoptout, marketing_emails_opt_in: response.client.marketing_emails_opt_in, overrideautoclose: response.client.overrideautoclose, allowSingleSignOn: Boolean(response.client.allowSingleSignOn), email_verified: response.client.email_verified, language: response.client.language, tax_state: response.client.tax_state, tax_countrycode: response.client.tax_countrycode, lastlogin: response.client.lastlogin, customfields: response.client.customfields }, users: response.users.user, stats: response.stats }; }, /** * Retrieve domains for a client * * @param params - The parameters for retrieving client domains * @returns Promise that resolves with the list of client domains * * @example * ```typescript * const result = await client.client.getClientsDomains({ * clientid: 1, * limitstart: 0, * limitnum: 25, * status: 'Active' * }); * console.log(`Found ${result.totalresults} domains`); * ``` * * @see https://developers.whmcs.com/api-reference/getclientsdomains */ getClientsDomains: (params) => callApi("GetClientsDomains", params), /** * Retrieve products/services for a client * * @param params - The parameters for retrieving client products * @returns Promise that resolves with the list of client products * * @example * ```typescript * const result = await client.client.getClientsProducts({ * clientid: 1, * limitstart: 0, * limitnum: 25, * status: 'Active', * productid: 5 * }); * console.log(`Found ${result.totalresults} products`); * ``` * * @see https://developers.whmcs.com/api-reference/getclientsproducts */ getClientsProducts: (params) => callApi("GetClientsProducts", params), /** * Retrieve contacts for a client * * @param params - The parameters for retrieving contacts * @returns Promise that resolves with the list of contacts * * @example * ```typescript * const result = await client.client.getContacts({ * limitstart: 0, * limitnum: 25, * userid: 1, * firstname: 'John' * }); * console.log(`Found ${result.totalresults} contacts`); * ``` * * @see https://developers.whmcs.com/api-reference/getcontacts */ getContacts: (params = {}) => callApi("GetContacts", params), /** * Retrieve emails sent to clients * * @param params - The parameters for retrieving emails * @returns Promise that resolves with the list of emails * * @example * ```typescript * const result = await client.client.getEmails({ * limitstart: 0, * limitnum: 25, * clientid: 1, * subject: 'Invoice' * }); * console.log(`Found ${result.totalresults} emails`); * ``` * * @see https://developers.whmcs.com/api-reference/getemails */ getEmails: (params = {}) => callApi("GetEmails", params), /** * Update an existing client * * @param params - The parameters for updating a client * @returns Promise that resolves with the updated client ID * * @example * ```typescript * const result = await client.client.updateClient({ * clientid: 1, * firstname: 'Jane', * lastname: 'Smith', * email: 'jane.smith@example.com', * phonenumber: '+1-555-987-6543', * notes: 'Updated contact information' * }); * console.log(`Updated client with ID: ${result.clientid}`); * ``` * * @see https://developers.whmcs.com/api-reference/updateclient */ updateClient: (params) => callApi("UpdateClient", params), /** * Update an existing contact * * @param params - The parameters for updating a contact * @returns Promise that resolves with the updated contact ID * * @example * ```typescript * const result = await client.client.updateContact({ * contactid: 123, * firstname: 'Jane', * lastname: 'Smith', * email: 'jane.smith@example.com', * phonenumber: '+1-555-987-6543', * permissions: 'profile,contacts,products,domains,tickets' * }); * console.log(`Updated contact with ID: ${result.contactid}`); * ``` * * @see https://developers.whmcs.com/api-reference/updatecontact */ updateContact: (params) => callApi("UpdateContact", params) }); // src/modules/domains.ts var createDomainsModule = (callApi) => ({ /** * Creates or updates a Top-Level Domain (TLD) configuration with pricing. * * @param params - TLD extension and configuration including pricing, features, and registrar settings * @returns Promise resolving to TLD configuration and pricing details * * @example * ```typescript * const response = await client.domains.createOrUpdateTLD({ * extension: '.com', * id_protection: true, * dns_management: true, * auto_registrar: 'enom', * register: { 1: 10.00, 2: 20.00 } * }); * console.log(response.extension); * ``` * * @see https://developers.whmcs.com/api-reference/createorupdatetld/ */ createOrUpdateTLD: (params) => callApi("CreateOrUpdateTLD", params), /** * Retrieves the current locking status of a domain from the registrar. * * @param params - Domain ID to check locking status for * @returns Promise resolving to current lock status * * @example * ```typescript * const response = await client.domains.domainGetLockingStatus({ * domainid: 123 * }); * console.log(response.lockstatus); * ``` * * @see https://developers.whmcs.com/api-reference/domaingetlockingstatus/ */ domainGetLockingStatus: (params) => callApi("DomainGetLockingStatus", params), /** * Retrieves the current nameservers for a domain from the registrar. * * @param params - Domain ID to get nameservers for * @returns Promise resolving to current nameserver configuration * * @example * ```typescript * const response = await client.domains.domainGetNameservers({ * domainid: 123 * }); * console.log(response.ns1, response.ns2); * ``` * * @see https://developers.whmcs.com/api-reference/domaingetnameservers/ */ domainGetNameservers: (params) => callApi("DomainGetNameservers", params), /** * Retrieves WHOIS information for a domain from the registrar. * * @param params - Domain ID to get WHOIS information for * @returns Promise resolving to WHOIS data * * @example * ```typescript * const response = await client.domains.domainGetWhoisInfo({ * domainid: 123 * }); * console.log(response.whois); * ``` * * @see https://developers.whmcs.com/api-reference/domaingetwhoisinfo/ */ domainGetWhoisInfo: (params) => callApi("DomainGetWhoisInfo", params), /** * Sends a registration command to the registrar for a domain. * * @param params - Domain ID and optional registrar specification * @returns Promise resolving to success confirmation * * @example * ```typescript * await client.domains.domainRegister({ * domainid: 123, * registrar: 'enom' * }); * ``` * * @see https://developers.whmcs.com/api-reference/domainregister/ */ domainRegister: (params) => callApi("DomainRegister", params), /** * Releases a domain to a new tag/registrar (UK domains). * * @param params - Domain ID and new tag for release * @returns Promise resolving to success confirmation * * @example * ```typescript * await client.domains.domainRelease({ * domainid: 123, * newtag: 'NEWTAG' * }); * ``` * * @see https://developers.whmcs.com/api-reference/domainrelease/ */ domainRelease: (params) => callApi("DomainRelease", params), /** * Sends a renewal command to the registrar for a domain. * * @param params - Domain ID and optional registration period * @returns Promise resolving to success confirmation * * @example * ```typescript * await client.domains.domainRenew({ * domainid: 123, * regperiod: 1 * }); * ``` * * @see https://developers.whmcs.com/api-reference/domainrenew/ */ domainRenew: (params) => callApi("DomainRenew", params), /** * Requests the EPP (auth) code for a domain from the registrar. * * @param params - Domain ID to request EPP code for * @returns Promise resolving to success confirmation * * @example * ```typescript * await client.domains.domainRequestEPP({ * domainid: 123 * }); * ``` * * @see https://developers.whmcs.com/api-reference/domainrequestepp/ */ domainRequestEPP: (params) => callApi("DomainRequestEPP", params), /** * Toggles ID protection (privacy) for a domain at the registrar. * * @param params - Domain ID and optional protection enable/disable flag * @returns Promise resolving to success confirmation * * @example * ```typescript * await client.domains.domainToggleIdProtect({ * domainid: 123, * protectenable: true * }); * ``` * * @see https://developers.whmcs.com/api-reference/domaintoggleidprotect/ */ domainToggleIdProtect: (params) => callApi("DomainToggleIdProtect", params), /** * Initiates a domain transfer command at the registrar. * * @param params - Domain ID, transfer secret, and optional registrar * @returns Promise resolving to success confirmation * * @example * ```typescript * await client.domains.domainTransfer({ * domainid: 123, * transfersecret: 'EPP_CODE_HERE', * registrar: 'enom' * }); * ``` * * @see https://developers.whmcs.com/api-reference/domaintransfer/ */ domainTransfer: (params) => callApi("DomainTransfer", params), /** * Updates the locking status of a domain at the registrar. * * @param params - Domain ID and optional lock status flag * @returns Promise resolving to success confirmation * * @example * ```typescript * await client.domains.domainUpdateLockingStatus({ * domainid: 123, * lockstatus: true * }); * ``` * * @see https://developers.whmcs.com/api-reference/domainupdatelockingstatus/ */ domainUpdateLockingStatus: (params) => callApi("DomainUpdateLockingStatus", params), /** * Updates the nameservers for a domain at the registrar. * * @param params - Domain ID/name and nameserver configuration (ns1, ns2 required) * @returns Promise resolving to success confirmation * * @example * ```typescript * await client.domains.domainUpdateNameservers({ * domainid: 123, * ns1: 'ns1.example.com', * ns2: 'ns2.example.com' * }); * ``` * * @see https://developers.whmcs.com/api-reference/domainupdatenameservers/ */ domainUpdateNameservers: (params) => callApi("DomainUpdateNameservers", params), /** * Updates WHOIS contact information for a domain at the registrar. * * @param params - Domain ID and contact information to update * @returns Promise resolving to success confirmation * * @example * ```typescript * await client.domains.domainUpdateWhoisInfo({ * domainid: 123, * firstname: 'John', * lastname: 'Doe', * email: 'john@example.com' * }); * ``` * * @see https://developers.whmcs.com/api-reference/domainupdatewhoisinfo/ */ domainUpdateWhoisInfo: (params) => callApi("DomainUpdateWhoisInfo", params), /** * Performs a WHOIS lookup for any domain name. * * @param params - Domain name to perform WHOIS lookup on * @returns Promise resolving to WHOIS information and status * * @example * ```typescript * const response = await client.domains.domainWhois({ * domain: 'example.com' * }); * console.log(response.whois, response.status); * ``` * * @see https://developers.whmcs.com/api-reference/domainwhois/ */ domainWhois: (params) => callApi("DomainWhois", params), /** * Retrieves a list of active registrars configured in WHMCS. * * @returns Promise resolving to list of available registrars * * @example * ```typescript * const response = await client.domains.getRegistrars(); * console.log(response.registrars); * ``` * * @see https://developers.whmcs.com/api-reference/getregistrars/ */ getRegistrars: () => callApi("GetRegistrars"), /** * Retrieves TLD pricing information for registration, transfer, and renewal. * * @param params - Optional client ID and currency ID for pricing context * @returns Promise resolving to comprehensive TLD pricing data * * @example * ```typescript * const response = await client.domains.getTLDPricing({ * clientid: 123, * currencyid: 1 * }); * console.log(response.pricing); * ``` * * @see https://developers.whmcs.com/api-reference/gettldpricing/ */ getTLDPricing: (params = {}) => callApi("GetTLDPricing", params), /** * Updates client domain properties including status, dates, and configuration. * * @param params - Domain ID and properties to update * @returns Promise resolving to updated domain ID * * @example * ```typescript * const response = await client.domains.updateClientDomain({ * domainid: 123, * status: 'Active', * nextduedate: '2024-12-01', * dnsmanagement: true * }); * console.log(response.domainid); * ``` * * @see https://developers.whmcs.com/api-reference/updateclientdomain/ */ updateClientDomain: (params) => callApi("UpdateClientDomain", params) }); // src/modules/modules.ts function createModulesModule(callApi) { return { /** * Activate a WHMCS module * * @param params - Parameters for activating module * @param params.moduleType - The module type to be activated * @param params.moduleName - The module name to be activated * @param params.parameters - An array of configuration parameters to set for the given module * @returns Promise resolving to success response * * @example * ```typescript * // Activate a payment gateway * await client.modules.activateModule({ * moduleType: 'gateway', * moduleName: 'paypal', * parameters: { * email: 'merchant@example.com', * forcesubscriptions: true * } * }); * * // Activate a provisioning module * await client.modules.activateModule({ * moduleType: 'server', * moduleName: 'cpanel' * }); * ``` * * @see https://developers.whmcs.com/api-reference/activatemodule/ */ activateModule: (params) => callApi("ActivateModule", params), /** * Deactivate a WHMCS module * * @param params - Parameters for deactivating module * @param params.moduleType - The module type to be deactivated * @param params.moduleName - The module name to be deactivated * @param params.newGateway - The Gateway to switch respective entities to when deactivating a Gateway Module * @returns Promise resolving to success response * * @example * ```typescript * // Deactivate a payment gateway * await client.modules.deactivateModule({ * moduleType: 'gateway', * moduleName: 'paypal' * }); * * // Deactivate gateway and switch to another * await client.modules.deactivateModule({ * moduleType: 'gateway', * moduleName: 'paypal', * newGateway: 'stripe' * }); * ``` * * @see https://developers.whmcs.com/api-reference/deactivatemodule/ */ deactivateModule: (params) => callApi("DeactivateModule", params), /** * Get configuration parameters for a module * * @param params - Parameters for getting module configuration * @param params.moduleType - The module type to get parameters for * @param params.moduleName - The module name to get parameters for * @returns Promise resolving to module configuration parameters * * @example * ```typescript * // Get PayPal gateway configuration parameters * const config = await client.modules.getModuleConfigurationParameters({ * moduleType: 'gateway', * moduleName: 'paypal' * }); * * console.log('Available parameters:', config.parameters); * // Use parameters for activation * await client.modules.activateModule({ * moduleType: 'gateway', * moduleName: 'paypal', * parameters: { * email: 'merchant@example.com' * } * }); * ``` * * @see https://developers.whmcs.com/api-reference/getmoduleconfigurationparameters/ */ getModuleConfigurationParameters: (params) => callApi("GetModuleConfigurationParameters", params), /** * Get module queue for incomplete failed actions * * @param params - Optional parameters for filtering module queue * @param params.relatedId - The id of the service to load. Used in conjunction with serviceType * @param params.serviceType - The type of service to load ('domain', 'service', 'addon' or '') * @param params.moduleName - The module name to obtain the queue for in system format * @param params.moduleAction - The module action to obtain the queue for * @param params.since - The date/time since to obtain the items. Format Y-m-d Can include H:i:s * @returns Promise resolving to module queue data * * @example * ```typescript * // Get all queue items * const queue = await client.modules.getModuleQueue(); * * // Get queue for specific service * const serviceQueue = await client.modules.getModuleQueue({ * relatedId: 1, * serviceType: 'service' * }); * * // Get queue for specific module * const moduleQueue = await client.modules.getModuleQueue({ * moduleName: 'cpanel', * moduleAction: 'CreateAccount' * }); * ``` * * @see https://developers.whmcs.com/api-reference/getmodulequeue/ */ getModuleQueue: (params = {}) => callApi("GetModuleQueue", params), /** * Update configuration for an already activated module * * @param params - Parameters for updating module configuration * @param params.moduleType - The module type to be updated * @param params.moduleName - The module name to be updated * @param params.parameters - An array of configuration parameters to set for the given module * @returns Promise resolving to success response * * @example * ```typescript * // Update PayPal gateway configuration * await client.modules.updateModuleConfiguration({ * moduleType: 'gateway', * moduleName: 'paypal', * parameters: { * email: 'newemail@example.com', * sandbox: false * } * }); * ``` * * @see https://developers.whmcs.com/api-reference/updatemoduleconfiguration/ */ updateModuleConfiguration: (params) => callApi("UpdateModuleConfiguration", params) }; } // src/modules/orders.ts var createOrdersModule = (callApi) => ({ /** * Accept a pending order * * @param params - The parameters for accepting an order * @returns Promise that resolves when the order is accepted * * @example * ```typescript * await client.orders.acceptOrder({ * orderid: 123, * serverid: 1, * serviceusername: 'user123', * servicepassword: 'password123', * sendregistrar: true, * autosetup: true, * sendemail: true * }); * ``` * * @see https://developers.whmcs.com/api-reference/acceptorder */ acceptOrder: (params) => callApi("AcceptOrder", params), /** * Add a new order to the system * * @param params - The parameters for creating an order * @returns Promise that resolves with the new order details * * @example * ```typescript * const result = await client.orders.addOrder({ * clientid: 1, * productid: 2, * paymentmethod: 'paypal', * domain: 'example.com', * billingcycle: 'monthly', * domaintype: 'register', * regperiod: 1 * }); * console.log(`Order created with ID: ${result.orderid}`); * ``` * * @see https://developers.whmcs.com/api-reference/addorder */ addOrder: (params) => callApi("AddOrder", params), /** * Cancel a pending order * * @param params - The parameters for cancelling an order * @returns Promise that resolves when the order is cancelled * * @example * ```typescript * await client.orders.cancelOrder({ * orderid: 123, * cancelsub: true, * noemail: false * }); * ``` * * @see https://developers.whmcs.com/api-reference/cancelorder */ cancelOrder: (params) => callApi("CancelOrder", params), /** * Delete an order from the system * * @param params - The parameters for deleting an order * @returns Promise