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 an additional contact user for an existing customer in WHMCS. If the type is not specified, a random contact is created. |
apply_credit | apply credit to invoice | Applies a credit amount (balance) to pay a specific invoice in WHMCS. If the invoice status changes to 'Paid', traffic overage tags are automatically cleared. |
create_addfunds | create add funds invoice | Creates an invoice in WHMCS to top up the customer's balance by the specified amount. If the subscribe option is enabled, automatic renewal is activated. |
delete_cancellation_request | delete cancellation request | Deletes a cancellation request for a specific server, restoring the invoice status or allowing a new one to be created. |
delete_contact | delete contact | Deletes an additional contact associated with a customer in WHMCS. |
download_invoice | download invoice | Returns a PDF file of the invoice in base64 format for downloading or viewing. |
generate_due_invoice | generate due invoice | Generates the next invoice for a server in WHMCS, considering the current billing cycle and active add-ons. It is blocked if the customer has unpaid invoices or if the next payment date has not yet arrived. |
get_billing_data | get billing data | Returns detailed information about the billing data of a specific server (synchronized data from WHMCS). |
get_cancellation_requests | get cancellation requests | Returns a list of active cancellation requests for a specific server or user, with filtering by date, type, and payment status. |
get_client | get client info | Returns detailed information about the authenticated client, including data from WHMCS and internal system data (tags, verification). Supports extended data retrieval via the full parameter. |
get_clientgroups | get groups | Returns a list of available customer groups from WHMCS for the specified location. |
get_contacts | get client additional contacts | Returns a list of additional contacts associated with a customer in WHMCS. If an email 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 in the selected WHMCS location. |
get_related_invoices | get related invoices | Returns a list of all invoices associated with a specific server (via account_id). |
getcredits | get balance (credits) | Returns information about available credits on the user's account in WHMCS. |
getpaymentgw | get payment gateways | Returns a list of available payment methods (gateways) for a specific invoice with processed payment links. |
mass_pay | mass pay invoices | Allows bulk payment of several customer invoices in a single transaction. A minimum of 2 invoices is required. |
request_cancellation | request subscription/server cancellation | Initiates the order or subscription cancellation process. It checks for active licenses, invoice payment status, and calculates the refund amount considering actual time used and traffic limits. |
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 a user's password. If reset_token is not provided, a link is sent via email. If the token is known, 2FA verification and password change are performed. |
transactions | get transactions | Returns a list of user transactions for a specific invoice or transaction ID. |
update_client | update client data | Updates the customer profile in WHMCS, including personal data (name, email), contact information, 2FA settings, and custom fields. Supports updating legal data for companies. |
update_contact | update contact data | Updates additional contact information (first name, last name, email, phone) for a customer in WHMCS. Supports email uniqueness check and phone number verification. |
whmcs/add_contact¶
Adds an additional contact user for an existing customer in WHMCS. If the type is not specified, a random contact is created.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: add_contact |
| type | ❌ | integer | Operation type (0 - create new 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 | Password for the new contact |
| profile_data[password2] | ✅ | string | Password confirmation |
| profile_data[phonenumber] | ❌ | string | Phone number (SMS support is checked) |
Example Request
Example of a successful response
{
"result": "OK",
"clientid": 12345,
"firstname": "John",
"lastname": "Doe",
"email": "[email protected]"
}
Failure response
``` { "code": -1, "message": "fill_required_fields" }
```
whmcs/apply_credit¶
Applies a credit amount (balance) to pay a specific invoice in WHMCS. If the invoice status changes to 'Paid', traffic overage tags are automatically cleared.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: apply_credit |
| invoice_id | ✅ | int | Invoice ID for payment |
| amount | ✅ | number | Credit amount to apply |
| token | ✅ | string | API authentication token |
Example Request
Failure response
``` { "code": -1, "message": "invalid invoice id at whmcs_location" }
```
whmcs/create_addfunds¶
Creates an invoice in WHMCS to top up the customer's balance by the specified amount. If the subscribe option is enabled, automatic renewal is activated.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| amount | ✅ | number | Top-up amount. If not specified, the minimum payment is $20. |
| description | ❌ | string | Payment description for the invoice |
| subscribe | ❌ | boolean | Enable automatic renewal (autopay) |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "minimal payment amount is $20." }
```
whmcs/delete_cancellation_request¶
Deletes a cancellation request for a specific server, restoring the invoice status or allowing a new one to be created.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: delete_cancellation_request |
| id | ✅ | int | Server ID |
| token | ❌ | string | Authorization token |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "server $id doesn't have a relid data" }
```
whmcs/delete_contact¶
Deletes an additional contact associated with a customer in WHMCS.
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
Failure response
``` { "code": -1, "message": "verification failed, subcontact not found" }
```
whmcs/download_invoice¶
Returns a PDF file of the invoice in base64 format for downloading or viewing.
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 billing location or invalid invoice id" }
```
whmcs/generate_due_invoice¶
Generates the next invoice for a server in WHMCS, considering the current billing cycle and active add-ons. It is blocked if the customer has unpaid invoices or if the next payment date has not yet arrived.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | ✅ | int | Server ID (equipment ID) |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
Failure response
``` { "-1": { "result": -1, "error": "next_invoice_blocked_by_upgrade" }, "-2": { "result": -1, "error": "next_invoice_blocked_by_due_date" }, "-3": { "result": -1, "error": "next_invoice_unpaid_exists" } }
```
whmcs/get_billing_data¶
Returns detailed information about the billing data of a specific server (synchronized data from WHMCS).
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_billing_data |
| id | ✅ | int | Server ID |
| token | ✅ | string | Authorization token |
| customer_name | ✅ | string | customer_name parameter (detected in code) |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "Server not found" }
```
whmcs/get_cancellation_requests¶
Returns a list of active cancellation requests for a specific server or user, with filtering by date, type, and payment 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 not specified, 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 payment status (e.g., Paid, Unpaid) |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "server $id doesn't have a relid data" }
```
whmcs/get_client¶
Returns detailed information about the authenticated client, including data from WHMCS and internal system data (tags, verification). Supports extended data retrieval via the full parameter.
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 | If true, returns an extended set of client data |
Example Request
Example of a successful response
{
"result": "OK",
"client": {
"id": 123,
"email": "[email protected]",
"firstname": "John",
"lastname": "Doe",
"fullname": "John Doe",
"companyname": "Example Corp",
"countrycode": "US",
"currency_code": "USD",
"status": "Active",
"ip": "192.168.1.1",
"billing_location": "whmcs_com",
"groupdata": {
"id": 5,
"groupname": "Premium Customers"
},
"internal": {
"id": 123,
"email": "[email protected]",
"corporate": 0,
"active_since": "2024-01-15"
}
}
}
Failure response
``` { "code": -1, "message": "Request failed for client@domain.com: error_message" }
```
whmcs/get_clientgroups¶
Returns a list of available customer groups from WHMCS for the specified location.
HTTP-method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_clientgroups |
| token | ✅ | string | Authorization token |
| location | ✅ | string | WHMCS billing location |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "Invalid token or access denied" }
```
whmcs/get_contacts¶
Returns a list of additional contacts associated with a customer in WHMCS. If an email is specified, only 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 | Email for filtering contacts (used to check access rights under a sub-account) | |
| full | ❌ | boolean | If true, returns extended data from WHMCS along with the response |
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
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_invoice |
| token | ✅ | string | Authorization token |
| invoice_id | ✅ | integer | Invoice ID |
| load_client_data | ❌ | boolean | Load client data with the invoice (1 — to load) |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "invalid invoice id 0 at whmcs.com" }
```
whmcs/get_invoices¶
Returns a list of all invoices associated with the customer in the selected WHMCS location.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_invoices |
| token | ✅ | string | Authorization token |
| location | ❌ | string | Billing location (WHMCS location) |
Example Request
Example of a successful response
Failure response
``` { "result": "-1", "error": "Invalid client id" }
```
whmcs/get_related_invoices¶
Returns a list of all 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 Server ID |
| token | ✅ | string | Authorization token |
| id | ❌ | int | Server ID (used as product_id in the function) |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "server $id are not linked to the billing" }
```
whmcs/getcredits¶
Returns information about available credits on the user's account in WHMCS.
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 WHMCS_LOCATION, please contact support" }
```
whmcs/getpaymentgw¶
Returns a list of available payment methods (gateways) for a specific invoice with processed payment links.
HTTP-method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Action name (getpaymentgw) |
| token | ❌ | string | Authorization token |
| invoice_id | ✅ | integer | Invoice ID to get available payment methods |
Example Request
Example of a successful response
{
"result": "OK",
"methods": {
"paymaster": {
"call": "https://bill.hostkey.com/modules/gateways/paymaster/index.php?id=123"
},
"bitpaycheckout": {
"call": "<input type=\"submit\" class=\"btn btn-xl btn-block btn-outline-dark rounded btn-sm\" value=\"Pay Now\" />"
},
"banktransfer": {
"call": "<span style='text-align:left'>Please wire funds in favor of: Bank Details...</span>"
}
}
}
Failure response
``` { "code": -1, "message": "failed to retrive payment gw list: error message", "details": {} }
```
whmcs/mass_pay¶
Allows bulk payment of several customer invoices in a single transaction. A minimum of 2 invoices is required.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: mass_pay |
| invoices[] | ✅ | array<int> | Array of invoice IDs for payment. Accepts multiple values: invoices[]=1&invoices[]=2 |
| token | ✅ | string | API authentication token |
Example Request
Failure response
``` { "code": -1, "message": "mass_pay_requires_2_invoices" }
```
whmcs/request_cancellation¶
Initiates the order or subscription cancellation process. It checks for active licenses, invoice payment status, and calculates the refund amount considering actual time used and traffic limits.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | ✅ | int | Server ID for cancellation |
| cancellation_type | ❌ | int | Cancellation type (1 — immediate with refund) |
| cancellation_reason | ❌ | string | Order cancellation reason |
| token | ✅ | string | Authorization token |
| billing | ✅ | string | Billing location |
| clientid | ✅ | int | Client ID in WHMCS |
| ✅ | string | User email for notification | |
| refund | ❌ | float | Refund amount |
| currency | ❌ | string | Refund currency |
| service_price | ❌ | float | Service price for calculation |
| refund_message | ❌ | string | Refund message text |
| refund_message_short | ❌ | string | Short refund message text |
| refund_message_inv | ❌ | string | Message text for the invoice |
| last_invoice | ✅ | int | Last invoice ID |
| prev_invoice_id | ❌ | int | Previous invoice ID |
| relid | ✅ | int | Account ID (Relid) |
| vat_msg | ❌ | string | Tax/VAT message |
| rec_before_tax | ❌ | float | Amount before taxes |
| total_with_tax | ❌ | float | Total amount including tax |
Example Request
curl -s "https://invapi.hostkey.com/whmcs.php" -X POST \
--data "id=123" \
--data "token=YOUR_TOKEN" \
--data "billing=location_name" \
--data "clientid=456" \
--data "[email protected]" \
--data "last_invoice=789" \
--data "relid=1011"
Failure response
``` { "code": -3, "message": "whmcs_server_exceded_traffic (traffic limit exceeded)" }
```
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 | Subscription cancellation reason |
| 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 a user's password. If reset_token is not provided, a link is sent via email. If the token is known, 2FA verification and password change are performed.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: reset_password |
| token | ✅ | string | Auth token for request authorization |
| ✅ | string | User email for password reset | |
| reset_token | ❌ | string | Token to complete the reset process (if email was already requested) |
| pass | ❌ | string | New user password |
| code | ❌ | string | Two-factor authentication (2FA) code |
Example Request
curl -s "https://invapi.hostkey.com/whmcs.php" -X POST \
--data "action=reset_password" \
--data "token=HOSTKEY_TOKEN"
--data "[email protected]"
Example of a successful response
Failure response
``` { "code": -1, "message": "Invalid password reset token, please try again." }
```
whmcs/transactions¶
Returns a list of user transactions for a specific invoice or transaction ID.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: transactions |
| transaction_id | ❌ | string | Specific transaction ID |
| invoice_id | ❌ | integer | Invoice ID for filtering |
| 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 the customer profile in WHMCS, including personal data (name, email), contact information, 2FA settings, and custom fields. Supports updating legal data for companies.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: update_client |
| token | ✅ | string | Authorization token |
| profile_data[client_id] | ✅ | integer | Client ID in WHMCS |
| profile_data[location] | ✅ | string | Billing location (e.g., whmcs_com) |
| profile_data[billing_email] | ❌ | string | New customer email address |
| profile_data[billing_firstname] | ❌ | string | Customer first name |
| profile_data[billing_lastname] | ❌ | string | Customer last name |
| profile_data[co_customertype] | ❌ | string | Customer type (Individual / Company) |
| profile_data[ips] | ❌ | string | List of allowed IP addresses separated by a delimiter |
| profile_data[co_smsnum] | ❌ | string | Phone number for SMS (requires verification) |
| profile_data[billing_country] | ❌ | string | Country of residence/registration |
| profile_data[password2] | ❌ | string | New customer password |
| profile_data[co_inn] | ❌ | string | Tax ID (for companies) |
| profile_data[co_kpp] | ❌ | string | KPP code (for companies) |
Example Request
Example of a successful response
{
"result": "OK",
"clientid": 12345,
"location": "whmcs_com",
"billing_email": "[email protected]",
"firstname": "John",
"lastname": "Doe",
"customfields": "base64_encoded_string"
}
Failure response
``` { "code": -1, "message": "invalid profile data: billing_email can't be empty" }
```
whmcs/update_contact¶
Updates additional contact information (first name, last name, email, phone) for a 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 |
| token | ✅ | string | Authorization token |
| profile_data[contact_id] | ✅ | int | Contact ID to update |
| profile_data[email] | ✅ | string | Contact email (uniqueness is checked) |
| profile_data[firstname] | ✅ | string | Contact first name |
| profile_data[lastname] | ❌ | string | Contact last name |
| profile_data[phonenumber] | ❌ | string | Phone number (undergoes verification) |
| profile_data[password1] | ❌ | string | New password 1 |
| profile_data[password2] | ❌ | string | New password 2 (for password change) |
Example Request
curl -s "https://invapi.hostkey.com/whmcs.php" -X POST \
--data "action=update_contact" \
--data "token=HOSTKEY_TOKEN"
--data "profile_data[contact_id]=67890" \
--data "profile_data[email][email protected]" \
--data "profile_data[firstname]=John"
Example of a successful response
{
"result": "OK",
"clientid": 12345,
"location": "whmcs_com",
"contactid": 67890,
"email": "[email protected]",
"firstname": "John",
"lastname": "Doe"
}
Failure response
``` { "code": -1, "message": "fill_required_fields" }