whmcs.php¶
WHMCS integration module for managing customers, invoices, credit, order cancellations, and server billing data.
API Methods¶
| Method | Action | Description |
|---|---|---|
add_contact | add contact | Adds a new additional contact for a customer in WHMCS. If the request type is not specified, a random contact with a random email is created. |
apply_credit | apply credit to invoice | Applies the customer's available balance (credit) to pay a selected unpaid invoice. If the credit amount exceeds the invoice total, only the required portion is applied. |
create_addfunds | create add funds invoice | Creates an invoice in WHMCS for topping up the customer's balance (Add Funds). Supports automatic auto-renewal enablement with a minimum amount. |
delete_cancellation_request | delete cancellation request | Deletes an existing service cancellation request for a specific server, allowing the process to be restored or the pending status to be cleared. |
delete_contact | delete contact | Removes an additional customer contact from the WHMCS system and clears associated data in InvAPI. |
download_invoice | download invoice | Returns a PDF invoice file in base64 format for viewing or downloading. |
generate_due_invoice | generate due invoice | Generates the next due invoice for a server, considering the current billing cycle and active add-ons. |
get_billing_data | get server billing data | Returns detailed billing information for a specific server, including customer data and EU withdrawal status. |
get_cancellation_requests | get cancellation requests | Returns a list of active service cancellation requests for a specific server or user, with filtering by date, type, and billing status. |
get_client | get client information | Returns detailed information about the authenticated client, including data from WHMCS and internal system tags. |
get_clientgroups | get groups | Returns a list of available customer groups in WHMCS for the specified billing location. |
get_contacts | get client contacts | Returns a list of additional contacts linked to the client in WHMCS. If an email subaccount is specified, only contacts with corresponding access rights are returned. |
get_invoice | get invoice data | Returns detailed information about an invoice from WHMCS, including customer data and payment status. |
get_invoices | get client invoices list | Returns a list of all invoices associated with the customer's account in WHMCS. |
get_related_invoices | get related invoices | Returns a list of invoices associated with a specific server (via account_id) |
getcredits | get credits | Returns the user's balance (credits) information in WHMCS for the specified location. |
getpaymentgw | get available payment gateways for invoice | Returns a list of available payment methods (gateways) for a specific invoice, supporting link formatting and HTML call code. |
mass_pay | mass pay invoices | Creates one combined invoice to pay multiple selected customer invoices. |
request_cancellation | request cancellation | Initiates the order/server cancellation process in WHMCS, including refund condition checks and JIRA ticket creation. |
request_subscription_cancellation | request subscription cancellation | Initiates the bank subscription cancellation process for a server. Creates a JIRA ticket and attaches a request tag to the server. |
reset_password | reset password | Allows resetting the client's password. If no token is provided, a link is sent via email. If the token is known, 2FA verification and password change are performed. |
transactions | get client transactions | Returns a list of financial transactions for the user by a specified invoice ID or specific transaction. |
update_client | update client data | Updates personal customer data (name, email, phone), 2FA settings, company information, and custom fields in WHMCS. |
update_contact | update contact | Updates additional contact data (first name, last name, email, phone) for an existing customer in WHMCS. Supports email uniqueness check and phone number verification. |
whmcs/add_contact¶
Adds a new additional contact for a customer in WHMCS. If the request type is not specified, a random contact with a random email is created.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: add_contact |
| type | ❌ | integer | Request type (0 - create random contact) |
| profile_data[firstname] | ✅ | string | Contact first name |
| profile_data[lastname] | ❌ | string | Contact last name |
| profile_data[email] | ✅ | string | Contact email (must be unique) |
| profile_data[password1] | ✅ | string | Contact password 1 |
| profile_data[password2] | ✅ | string | Contact password 2 (confirmation) |
| profile_data[phonenumber] | ❌ | string | Contact phone number |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
{
"result": "OK",
"clientid": 12345,
"firstname": "John",
"lastname": "Doe",
"email": "[email protected]",
"status": "success"
}
Failure response
``` { "code": -1, "message": "fill_required_fields" }
```
whmcs/apply_credit¶
Applies the customer's available balance (credit) to pay a selected unpaid invoice. If the credit amount exceeds the invoice total, only the required portion is applied.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| invoice_id | ✅ | int | Unpaid invoice ID to be paid |
| amount | ❌ | number | Credit amount to apply (automatically limited by customer balance and invoice total) |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "invalid invoice id 123 at whmcs_location" }
```
whmcs/create_addfunds¶
Creates an invoice in WHMCS for topping up the customer's balance (Add Funds). Supports automatic auto-renewal enablement with a minimum amount.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: create_addfunds |
| token | ✅ | string | Authorization token |
| amount | ✅ | number | Top-up amount |
| description | ❌ | string | Payment description |
| subscribe | ❌ | boolean | Enable automatic renewal (auto-payment) |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "minimal payment amount is 10.00" }
```
whmcs/delete_cancellation_request¶
Deletes an existing service cancellation request for a specific server, allowing the process to be restored or the pending status to be cleared.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: delete_cancellation_request |
| id | ✅ | integer | Server ID (relid) for which the cancellation request should be deleted |
| token | ✅ | string | Authorization token |
Example Request
Failure response
``` { "code": -1, "message": "Server $id doesn't have a relid data" }
```
whmcs/delete_contact¶
Removes an additional customer contact from the WHMCS system and clears associated data in InvAPI.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: delete_contact |
| token | ✅ | string | Authorization token |
| contact_id | ✅ | int | Contact ID to delete |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "verification failed, subcontact not found" }
```
whmcs/download_invoice¶
Returns a PDF invoice file in base64 format for viewing or downloading.
HTTP-method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: download_invoice |
| token | ✅ | string | Authorization token |
| invoice_id | ✅ | int | Invoice ID |
| proforma_invoice | ❌ | int | Proforma flag (0 or 1) |
| viewpdf | ❌ | int | Display mode: 1 - inline (in browser), 0 - attachment (download) |
Example Request
Failure response
``` { "code": -1, "message": "Invalid invoice id or invalid billing location" }
```
whmcs/generate_due_invoice¶
Generates the next due invoice for a server, considering the current billing cycle and active add-ons.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: generate_due_invoice |
| id | ✅ | int | Server ID (entity id) |
| token | ✅ | string | Authorization token |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "next_invoice_blocked_by_upgrade" }
```
whmcs/get_billing_data¶
Returns detailed billing information for a specific server, including customer data and EU withdrawal status.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_billing_data |
| id | ✅ | int | Server ID |
| token | ✅ | string | Authorization token |
Example Request
Example of a successful response
{
"result": "OK",
"module": "whmcs",
"action": "get_billing_data",
"customer": {
"id": 1,
"email": "[email protected]",
"firstname": "John",
"lastname": "Doe",
"companyname": "Company",
"address1": "Address",
"address2": "",
"city": "City",
"state": "State",
"countrycode": "US",
"postcode": "123456",
"phonenumber": "79001234567",
"clientid": 1,
"account_id": 1,
"billing": "whmcs_us",
"corporate": 0,
"currency": "USD",
"email_verified": "verified"
},
"location": "US-East",
"customer_name": "John Doe",
"eu_withdrawal": 1
}
Failure response
``` { "code": -1, "message": "invalid request" }
```
whmcs/get_cancellation_requests¶
Returns a list of active service cancellation requests for a specific server or user, with filtering by date, type, and billing status.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_cancellation_requests |
| id | ❌ | int | Server ID to get requests for a specific resource. If -1, search is performed by user. |
| period_from | ❌ | string | Start date of the period (format YYYY-MM-DD) |
| period_to | ❌ | string | End date of the period (format YYYY-MM-DD) |
| cancellation_type | ❌ | string | Filter by cancellation type |
| billing_status | ❌ | string | Filter by billing status (e.g., Paid, Unpaid) |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "Invalid billing location $location" }
```
whmcs/get_client¶
Returns detailed information about the authenticated client, including data from WHMCS and internal system tags.
HTTP-method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_client |
| token | ✅ | string | Authorization token |
| ❌ | string | Client email for search (used in some scenarios) | |
| full | ❌ | boolean | Flag to get full data (including passwords and extended fields) |
Example Request
Example of a successful response
{
"result": "OK|success",
"client": {
"id": 123,
"firstname": "John",
"lastname": "Doe",
"email": "[email protected]",
"companyname": "Example Corp",
"countrycode": "US",
"currency_code": "USD",
"status": "Active",
"corporate": 0,
"inn": "",
"contractnum": ""
},
"billing_location": "whmcs_us",
"internal": {
"id": 123,
"email": "[email protected]",
"corporate": 0,
"active_since": "2024-01-15"
},
"groupdata": {
"id": 1,
"groupname": "Premium Customers"
}
}
Failure response
``` { "code": -1, "message": "Request failed for client@location: error_message" }
```
whmcs/get_clientgroups¶
Returns a list of available customer groups in WHMCS for the specified billing location.
HTTP-method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_clientgroups |
| location | ✅ | string | Location (billing location) to get groups for |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "Billing error: WHMCS connection failed" }
```
whmcs/get_contacts¶
Returns a list of additional contacts linked to the client in WHMCS. If an email subaccount is specified, only those contacts with corresponding access rights are returned.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_contacts |
| token | ✅ | string | Authorization token |
| ❌ | string | Subaccount email to filter contacts (if not specified, all client contacts are returned) |
Example Request
Example of a successful response
{
"result": "OK",
"permission_contacts_granted": true,
"contacts": [
{
"id": 123,
"email": "[email protected]",
"firstname": "John",
"lastname": "Doe",
"permissions": "contacts"
}
]
}
Failure response
``` { "code": -1, "message": "fail to get contacts list" }
```
whmcs/get_invoice¶
Returns detailed information about an invoice from WHMCS, including customer data and payment status.
HTTP-method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_invoice |
| token | ✅ | string | Authorization token |
| invoice_id | ✅ | int | Invoice ID |
| load_client_data | ❌ | int | Load client data with the invoice (1 - yes, 0 - no) |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "invalid invoice id 0 at whmcs_location" }
```
whmcs/get_invoices¶
Returns a list of all invoices associated with the customer's account in WHMCS.
HTTP-method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_invoices |
| token | ✅ | string | Authorization token |
| id | ❌ | integer | Client ID (used as client_id for whmcs_get_invoices) |
Example Request
Example of a successful response
Failure response
``` { "result": -1, "error": "Invalid client id" }
```
whmcs/get_related_invoices¶
Returns a list of invoices associated with a specific server (via account_id)
HTTP-method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_related_invoices |
| account_id | ❌ | int | WHMCS account ID. If not specified, it is determined automatically by the server id |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "server $id are not linked to the billing" }
```
whmcs/getcredits¶
Returns the user's balance (credits) information in WHMCS for the specified location.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: getcredits |
| token | ✅ | string | Authorization token |
Example Request
Failure response
``` { "code": -1, "message": "failed to retrive account history at LOC, please contact support - error_message" }
```
whmcs/getpaymentgw¶
Returns a list of available payment methods (gateways) for a specific invoice, supporting link formatting and HTML call code.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method name: getpaymentgw |
| token | ✅ | string | Authorization token |
| invoice_id | ✅ | int | Invoice ID |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "failed to retrive payment gw list: error message" }
```
whmcs/mass_pay¶
Creates one combined invoice to pay multiple selected customer invoices.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: mass_pay |
| invoices[] | ✅ | array | Array of invoice IDs to pay. Minimum 2 values. |
| token | ✅ | string | API authentication token |
Example Request
Failure response
``` { "code": -1, "message": "mass_pay_requires_2_invoices" }
```
whmcs/request_cancellation¶
Initiates the order/server cancellation process in WHMCS, including refund condition checks and JIRA ticket creation.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | ✅ | int | Server ID for cancellation |
| cancellation_type | ❌ | string | Cancellation type (1 - immediate) |
| cancellation_reason | ❌ | string | Reason for cancellation |
| refund | ❌ | number | Refund amount |
| currency | ❌ | string | Refund currency |
| service_price | ❌ | number | Service cost for calculation |
| refund_message | ❌ | string | Refund message (RU/EN) |
| refund_message_short | ❌ | string | Short refund message |
| last_invoice | ✅ | int | Last invoice item ID for calculation |
| prev_invoice_id | ❌ | int | Previous invoice ID |
| relid | ✅ | int | Related ID (account_id) |
| vat_extra | ❌ | boolean | Whether VAT is included in the refund amount |
| rec_before_tax | ❌ | number | Amount before taxes |
| d_deploy_time | ❌ | string | Deployment date (for calculation) |
| d_reccuring | ❌ | string | Payment frequency |
| cbp_adjusted | ❌ | string | CBP adjustment message |
| token | ✅ | string | API authentication token |
Example Request
Failure response
``` { "code": -3, "message": "whmcs_immediate_cancellation_no_invoices" }
```
whmcs/request_subscription_cancellation¶
Initiates the bank subscription cancellation process for a server. Creates a JIRA ticket and attaches a request tag to the server.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: request_subscription_cancellation |
| id | ✅ | int | Server ID for subscription cancellation |
| cancellation_type | ❌ | string | Cancellation type (e.g., 1) |
| cancellation_reason | ❌ | string | Reason for subscription cancellation |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "sub_cancel_jira_error" }
```
whmcs/reset_password¶
Allows resetting the client's password. If no token is provided, a link is sent via email. If the token is known, 2FA verification and password change are performed.
HTTP-method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Action name (reset_password) |
| token | ❌ | string | Token for password reset |
| ✅ | string | User email | |
| location | ❌ | string | Billing location (default Auto) |
| pass | ❌ | string | New password (to complete reset via token) |
| code | ❌ | string | 2FA code to confirm the operation |
Example Request
curl -s "https://invapi.hostkey.com/whmcs.php" -X POST \
--data "action=reset_password" \
--data "[email protected]"
Example of a successful response
Failure response
``` { "code": -1, "message": "Invalid request or password reset failed" }
```
whmcs/transactions¶
Returns a list of financial transactions for the user by a specified invoice ID or specific transaction.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: transactions |
| transaction_id | ❌ | string | Specific transaction ID |
| invoice_id | ❌ | integer | Invoice ID to filter transactions |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "failed to retrive transactions - error_message" }
```
whmcs/update_client¶
Updates personal customer data (name, email, phone), 2FA settings, company information, and custom fields in WHMCS.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| token | ✅ | string | Authorization token |
| profile_data[client_id] | ✅ | integer | Client ID in WHMCS |
| profile_data[location] | ✅ | string | Billing location (e.g., whmcs_us) |
| profile_data[billing_email] | ❌ | string | New client email |
| profile_data[billing_firstname] | ❌ | string | First name in billing |
| profile_data[billing_lastname] | ❌ | string | Last name in billing |
| profile_data[co_smsnum] | ❌ | string | Phone number for SMS verification |
| profile_data[ips] | ❌ | string | List of IP addresses (separated by space) for ACL |
| profile_data[co_secret] | ❌ | string | Profile secret word |
| profile_data[billing_twofaenabled] | ❌ | boolean | Whether two-factor authentication is enabled |
| profile_data[co_customertype] | ❌ | string | Customer type (Individual/Company) |
Example Request
curl -s "https://invapi.hostkey.com/whmcs.php" -X POST \
--data "token=HOSTKEY_TOKEN" \
--data "profile_data[client_id]=12345" \
--data "profile_data[location]=whmcs_us" \
--data "profile_data[billing_email][email protected]"
Example of a successful response
{
"result": "OK",
"clientid": 12345,
"location": "whmcs_us",
"billing_email": "[email protected]"
}
Failure response
``` { "code": -1, "message": "invalid profile data: billing_firstname can't be empty" }
```
whmcs/update_contact¶
Updates additional contact data (first name, last name, email, phone) for an existing customer in WHMCS. Supports email uniqueness check and phone number verification.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: update_contact |
| contact_id | ✅ | int | Contact ID to update |
| ✅ | string | Contact email (checked for uniqueness and validity) | |
| firstname | ✅ | string | Contact first name |
| lastname | ❌ | string | Contact last name |
| phonenumber | ❌ | string | Phone number (verified via Twilio) |
| profile_data[password1] | ❌ | string | New contact password |
| profile_data[password2] | ❌ | string | Password confirmation |
| token | ✅ | string | API authentication token |
Example Request
curl -s "https://invapi.hostkey.com/whmcs.php" -X POST \
--data "action=update_contact" \
--data "contact_id=10" \
--data "[email protected]"
--data "firstname=John"
--data "lastname=Doe"
--data "token=HOSTKEY_TOKEN"
Example of a successful response
{
"result": "OK",
"clientid": 12345,
"location": "whmcs_us",
"contact_data": {
"result": "success",
"contactid": 10,
"firstname": "John",
"lastname": "Doe",
"email": "[email protected]"
}
}
Failure response
``` { "code": -1, "message": "fill_required_fields" }