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 person to an existing customer in WHMCS. If the type is not specified, a random contact is created. |
apply_credit | apply credit to invoice | Applies the customer's available balance (credit) to pay a specific unpaid invoice. If the payment settles the debt, traffic overage is cleared. |
create_addfunds | create add funds invoice | Creates an invoice in WHMCS for topping up the customer's balance. 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 or generating a new one. |
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. The viewpdf parameter allows displaying the file in an inline viewer or downloading it as an attachment. |
generate_due_invoice | generate due invoice | Generates the next invoice for a server in WHMCS, provided the current billing cycle was completed more than 30 days ago and there are no unpaid invoices. |
get_billing_data | get server billing data | Returns detailed information about billing settings and the current status of a specific server (equipment). |
get_cancellation_requests | get cancellation requests list | Returns a list of active service cancellation requests for a specific server or user, with filtering by date, type, and payment 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 from WHMCS for the specified location. |
get_contacts | get client additional contacts | Returns a list of contacts (subcontacts) associated with a customer in WHMCS. If an email is specified, it returns only those contacts that have the corresponding access rights. |
get_invoice | get invoice data | Returns detailed information about an invoice from WHMCS, including status, items, and client data. |
get_invoices | get client invoices list | Returns a list of all invoices associated with a customer in WHMCS for the specified billing location. |
get_related_invoices | get related invoices | Returns a list of invoices associated with a specific server or account. |
getcredits | get credits | Returns information about available credits on the customer's balance in the specified WHMCS location. |
getpaymentgw | get payment gateways | Returns a list of available payment methods (payment gateways) for a specific invoice with processed payment links. |
mass_pay | mass pay invoices | Allows bulk payment of several invoices simultaneously by creating one combined invoice for payment. |
request_cancellation | request order/subscription cancellation | Initiates the process of canceling an order or subscription. It checks for active licenses, invoice payment status, and the possibility of an automatic refund depending on the service type and contract terms. |
request_subscription_cancellation | request subscription cancellation | Sends a request to JIRA to cancel a server's bank subscription. It checks for active orders, payment status, and any open tickets regarding this operation. |
reset_password | reset password | Allows initiating the password reset process for a client. If no token is provided, a link is sent via email. If the token is valid, the password is changed or a 2FA code is requested. |
transactions | get client transactions | Returns a list of financial transactions for the user associated with an invoice or a specific transaction. |
update_client | update client data | Updates customer information in WHMCS, including personal data (name, email, phone), address details, and custom fields. Supports email uniqueness validation and change verification. |
update_contact | update contact | Updates additional contact data (first name, last name, email, phone) for an existing customer in WHMCS. |
whmcs/add_contact¶
Adds an additional contact person to 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 person's first name |
| profile_data[lastname] | ❌ | string | Contact person's last name |
| profile_data[email] | ✅ | string | Contact person's email |
| 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": 123,
"firstname": "John",
"lastname": "Doe",
"email": "[email protected]"
}
Failure response
``` { "code": -1, "message": "fill_required_fields" }
```
whmcs/apply_credit¶
Applies the customer's available balance (credit) to pay a specific unpaid invoice. If the payment settles the debt, traffic overage is 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 to the invoice |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "WHMCS ApplyCredit failed: {\"result\":\"error\",\"error\":\"...\"}" }
```
whmcs/create_addfunds¶
Creates an invoice in WHMCS for topping up the customer's balance. If the subscribe option is enabled, automatic renewal is activated.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: create_addfunds |
| amount | ✅ | number | Top-up amount. Minimum amount is 20 (if auto-renewal is not enabled) |
| description | ❌ | string | Payment description |
| subscribe | ❌ | boolean | Enable automatic renewal (auto-payment) |
| 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 or generating a new one.
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 |
| contact_id | ✅ | int | Contact ID to delete |
| location | ❌ | string | Billing location (WHMCS location) |
| token | ✅ | string | API authentication token |
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. The viewpdf parameter allows displaying the file in an inline viewer or downloading it as an attachment.
HTTP Method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| token | ✅ | string | Authorization token |
| invoice_id | ✅ | int | Invoice ID for download |
| proforma_invoice | ❌ | int | Proforma invoice 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 invoice for a server in WHMCS, provided the current billing cycle was completed more than 30 days ago and there are no unpaid invoices.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: generate_due_invoice |
| id | ✅ | int | Server ID |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "next_invoice_blocked_by_upgrade" }
```
whmcs/get_billing_data¶
Returns detailed information about billing settings and the current status of a specific server (equipment).
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_billing_data |
| id | ✅ | int | Equipment ID (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": "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 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 | Cancellation type for filtering (e.g., 'End of Billing Period') |
| billing_status | ❌ | string | Invoice payment status for filtering |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
{
"result": "OK",
"message": [
{
"relid": 123,
"cr_date": "2024-05-20 14:30:00",
"cr_reason": "User requested cancellation",
"cr_type": "End of Billing Period",
"due_date": "2024-06-20",
"name_client": "John Doe",
"billing": "whmcs_ru",
"account_id": 55,
"status": "Active",
"corporate": "N",
"customer_id": 101
}
]
}
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 tags.
HTTP Method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_client |
| token | ✅ | string | Authorization token |
| full | ❌ | boolean | If true, returns extended data (including contacts and groups) |
| client | ✅ | string | client parameter (detected in code) |
| billing_location | ✅ | string | billing_location parameter (detected in code) |
| groupdata | ✅ | string | groupdata parameter (detected in code) |
| internal | ✅ | string | internal parameter (detected in code) |
Example Request
Example of a successful response
{
"result": "OK",
"action": "get_client",
"client": {
"id": 123,
"email": "[email protected]",
"firstname": "John",
"lastname": "Doe",
"fullname": "John Doe",
"companyname": "Company LLC",
"countrycode": "US",
"currency_code": "USD",
"status": "Active",
"groupid": 1,
"corporate": 0
},
"billing_location": "whmcs_com",
"internal": {
"id": 456,
"email": "[email protected]",
"active_since": "2023-01-15"
},
"groupdata": null
}
Failure response
``` { "code": -1, "message": "Request failed for 123@whmcs_com: client not found" }
```
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 location (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 contacts (subcontacts) associated with a customer in WHMCS. If an email is specified, it returns only those contacts that have the corresponding access rights.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_contacts |
| ❌ | string | Email for filtering contacts (used to check subcontact permissions) | |
| full | ❌ | boolean | If true, returns extended information from WHMCS along with API data |
| token | ✅ | string | API authentication token |
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 status, items, and client data.
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 flag (1 — yes) |
Example Request
Example of a successful response
{
"result": "OK",
"billing": "whmcs_ru",
"currencycode": "USD",
"status": "Paid",
"items": {
"item": [
{
"inv_id": 123,
"type": "Hosting",
"amount": 50.0
}
]
},
"customer": {
"client": {
"firstname": "John",
"lastname": "Doe",
"email": "[email protected]"
}
}
}
Failure response
``` { "code": -1, "message": "invalid invoice id 0 at whmcs_ru" }
```
whmcs/get_invoices¶
Returns a list of all invoices associated with a customer in WHMCS for the specified billing location.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_invoices |
| token | ✅ | string | Authorization token |
| location | ❌ | string | Billing location (extracted from session context/auth_check) |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "failed to retrive invoices: error message" }
```
whmcs/get_related_invoices¶
Returns a list of invoices associated with a specific server or account.
HTTP Method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_related_invoices |
| account_id | ❌ | int | Account ID to search for invoices |
| token | ✅ | string | Authorization token |
| id | ❌ | int | Server ID (relid) |
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 a customer's balance in the specified WHMCS location.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: getcredits |
| server_id | ❌ | int | Server ID (optional) |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "failed to retrive account history at WHMCS_LOCATION, please contact support - [WHMCS_ERROR]" }
```
whmcs/getpaymentgw¶
Returns a list of available payment methods (payment gateways) for a specific invoice with processed payment links.
HTTP Method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: getpaymentgw |
| token | ✅ | string | Authorization token |
| invoice_id | ✅ | integer | Invoice ID to get available gateways |
Example Request
Example of a successful response
{
"result": "OK",
"methods": {
"paymaster": {
"call": "https://invapi.hostkey.com/modules/gateways/paymaster.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'><p data-intl='please_wire_funds_in_favor'>Please wire funds in favor of: </p>https://invapi.hostkey.com?invoice_id=123</span>"
}
}
}
Failure response
``` { "code": -1, "message": "failed to retrive payment gw list: error message" }
```
whmcs/mass_pay¶
Allows bulk payment of several invoices simultaneously by creating one combined invoice for payment.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: mass_pay |
| invoices[] | ✅ | array<int> | Array of invoice IDs for bulk payment. Must contain at least 2 values. |
| token | ✅ | string | API authentication token |
Example Request
Failure response
``` { "code": -1, "message": "mass_pay_requires_2_invoices" }
```
whmcs/request_cancellation¶
Initiates the process of canceling an order or subscription. It checks for active licenses, invoice payment status, and the possibility of an automatic refund depending on the service type and contract terms.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Action name |
| token | ✅ | string | Authorization token |
| id | ✅ | integer | Server or order ID |
| cancellation_type | ❌ | integer | Cancellation type (1 for immediate with refund) |
| cancellation_reason | ❌ | string | Reason for cancellation |
| refund | ✅ | float | Refund amount |
| currency | ✅ | string | Currency |
| service_price | ❌ | float | Service cost for calculation |
| refund_message | ✅ | string | Refund message (RU/EN) |
| refund_message_short | ✅ | string | Short refund message |
| clientid | ✅ | integer | Client ID in WHMCS |
| billing | ✅ | string | Billing location (e.g., whmcs_ru) |
| ✅ | string | Client's email for notification | |
| last_invoice | ✅ | integer | Last invoice item ID |
| prev_invoice_id | ❌ | integer | Previous invoice ID to account for overpayment |
| relid | ✅ | integer | Related ID (account_id) |
| vat_msg | ❌ | string | Tax/VAT message |
| rec_before_tax | ❌ | float | Amount before taxes |
| d_deploy_time | ❌ | string | Deployment date (from tags) |
| d_bill_time | ❌ | string | Current request time |
| d_reccuring | ❌ | string | Recurring payment (from tags) |
| d_period | ❌ | string | Billing period (from tags) |
| cbp_adjusted | ❌ | string | CBP adjustment message |
Example Request
curl -s "https://invapi.hostkey.com/whmcs.php" -X POST \
--data "action=request_cancellation" \
--data "token=YOUR_TOKEN" \
--data "id=12345" \
--data "refund=50.00" \
--data "currency=USD" \
--data "refund_message=Refund processed successfully" \
--data "refund_message_short=Refund OK" \
--data "clientid=9876" \
--data "billing=whmcs_ru" \
--data "[email protected]" \
--data "last_invoice=554433" \
--data "relid=1001"
Failure response
``` { "code": -3, "message": "whmcs_server_exceded_traffic" }
```
whmcs/request_subscription_cancellation¶
Sends a request to JIRA to cancel a server's bank subscription. It checks for active orders, payment status, and any open tickets regarding this operation.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: request_subscription_cancellation |
| id | ✅ | integer | 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
{
"result": "OK",
"data": {
"account_id": "int",
"amount": "float",
"billing": "string",
"cancellation_reason": "string",
"cancellation_type": "string",
"clientid": "int",
"created": "string",
"currency": "string",
"customfields": "array",
"dc_location": "string",
"description": "string",
"displayid": "string",
"email": "string",
"hwconfig": "array",
"invoiceid": "int",
"last_inv_id": "int",
"prev_inv_id": "int",
"relid": "int",
"service_price": "float"
}
}
Failure response
``` { "code": -1, "message": "sub_cancel_jira_error" }
```
whmcs/reset_password¶
Allows initiating the password reset process for a client. If no token is provided, a link is sent via email. If the token is valid, the password is changed or a 2FA code is requested.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: reset_password |
| token | ❌ | string | Request authorization token (auth token) |
| ✅ | string | User's email for sending the password reset link | |
| location | ❌ | string | Billing location (default Auto) |
| reset_token | ❌ | string | Specific token for database record lookup |
| pass | ❌ | string | New password (used if a valid token is present) |
| code | ❌ | string | Two-factor authentication (2FA) code |
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 password reset token, please try again." }
```
whmcs/transactions¶
Returns a list of financial transactions for the user associated with an invoice or a specific transaction.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: transactions |
| transaction_id | ❌ | string | Specific transaction ID for filtering |
| invoice_id | ❌ | integer | Invoice ID to get all associated 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 customer information in WHMCS, including personal data (name, email, phone), address details, and custom fields. Supports email uniqueness validation and change verification.
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_ru) |
| profile_data[billing_email] | ❌ | string | New customer email address |
| 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 (requires verification) |
| profile_data[ips] | ❌ | string | List of IP addresses for ACL, separated by comma/space |
| profile_data[co_customertype] | ❌ | string | Customer type (Individual / Company) |
Example Request
curl -s "https://invapi.hostkey.com/whmcs.php" -X POST \
--data "action=update_client" \
--data "token=HOSTKEY_TOKEN" \
--data "profile_data[client_id]=12345" \
--data "profile_data[location]=whmcs_ru" \
--data "profile_data[billing_email][email protected]"
Failure response
``` { "-1": "invalid profile data: billing_email can't be empty" }
```
whmcs/update_contact¶
Updates additional contact data (first name, last name, email, phone) for an existing customer in WHMCS.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: update_contact |
| params[contact_id] | ✅ | int | Contact ID to update |
| params[email] | ✅ | string | Contact email (required) |
| params[firstname] | ✅ | string | Contact first name |
| params[lastname] | ❌ | string | Contact last name |
| params[phonenumber] | ❌ | string | Phone number (passes validation and transliteration) |
| params[password1] | ❌ | string | New password 1 |
| params[password2] | ❌ | string | New password 2 (for password change) |
| token | ✅ | string | API authentication token |
Example Request
Failure response
``` { "code": -1, "message": "fill_required_fields" }