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 is created. |
apply_credit | apply credit to invoice | Applies the customer's available balance (credit) to pay a selected invoice. If the credit amount is greater than the invoice amount, 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). If the subscribe option is enabled, automatic renewal is activated. |
delete_cancellation_request | delete cancellation request | Deletes an active service cancellation request for a specific server. If the server was linked to WHMCS, the operation may initiate the unmounting process. |
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 viewing or downloading. |
generate_due_invoice | generate due invoice | Generates the next due invoice for the server. It is blocked if the customer has unpaid invoices or if the current billing cycle is not completed. |
get_billing_data | get server billing data | Returns detailed information about a specific server's billing data, including EU B2C status and refund data (if applicable). |
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 payment status. |
get_client | get client information | Returns detailed customer information from WHMCS, including profile data, contact details, and assigned groups. |
get_clientgroups | get groups | Returns a list of available customer groups from WHMCS for the specified location. |
get_contacts | get contacts | Returns a list of additional contacts for the specified customer or checks access rights to them. |
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 a customer in WHMCS for the specified location. |
get_related_invoices | get related invoices | Returns a list of invoices associated with a specific server or account in WHMCS. |
getcredits | get credits | Returns information about the user's available balance (credits) in WHMCS for the specified location. |
getpaymentgw | get available payment methods | Returns a list of payment gateways available for a specific invoice, considering the customer's currency and regional restrictions. |
mass_pay | mass pay invoices | Creates one combined invoice to pay several selected customer invoices. |
request_cancellation | request cancellation | Initiates the order or service cancellation process. It checks for active licenses, invoice payment status, and automatic refund eligibility (including EU B2C rules). If there are traffic debts, they are taken into account when calculating the refund amount. |
request_subscription_cancellation | request subscription cancellation | Sends a request to cancel a bank subscription by creating a ticket in JIRA. It checks for active subscriptions and payment status. |
reset_password | reset password | Initiates the password reset process. If no token is provided, a link is sent via email. If the token is valid, it verifies 2FA and updates the password. |
transactions | get client transactions | Returns a list of user financial transactions from WHMCS based on filters. |
update_client | update client data | Updates the customer profile in WHMCS, including personal data (name, email), contact information, and custom fields. Supports email uniqueness check and verification via SMS/2FA. |
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 validation. |
whmcs/add_contact¶
Adds a new additional contact for a customer in WHMCS. If the request type is not specified, a random contact is created.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| type | ❌ | int | Operation 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 | Password for the new contact |
| profile_data[password2] | ✅ | string | Password confirmation |
| profile_data[phonenumber] | ❌ | string | Contact phone number (undergoes verification) |
| token | ✅ | string | API authentication token |
Example Request
curl -s "https://invapi.hostkey.com/whmcs.php" -X POST \
--data "type=0" \
--data "profile_data[firstname]=Ivan" \
--data "profile_data[lastname]=Ivanov" \
--data "profile_data[email][email protected]" \
--data "profile_data[password1]=StrongPass123!" \
--data "profile_data[password2]=StrongPass123!" \
--data "token=YOUR_API_TOKEN"
Failure response
``` { "code": -1, "message": "fill_required_fields" }
```
whmcs/apply_credit¶
Applies the customer's available balance (credit) to pay a selected invoice. If the credit amount is greater than the invoice amount, only the required portion is applied.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: apply_credit |
| invoice_id | ✅ | int | Invoice ID to pay |
| amount | ❌ | number | Credit amount (if not specified, the maximum possible amount is applied) |
| 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 (Add Funds). 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 |
| description | ❌ | string | Payment description |
| subscribe | ❌ | bool | Enable automatic renewal (auto-debit) |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "minimal payment amount is 10.0" }
```
whmcs/delete_cancellation_request¶
Deletes an active service cancellation request for a specific server. If the server was linked to WHMCS, the operation may initiate the unmounting process.
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
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 |
| 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 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 invoice flag (0 or 1) |
| viewpdf | ❌ | int | Display flag: 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 the server. It is blocked if the customer has unpaid invoices or if the current billing cycle is not completed.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: generate_due_invoice |
| id | ✅ | int | Server ID |
| serviceids[] | ❌ | array | Array of service IDs for invoice generation. |
| addonids[] | ❌ | array | Array of addon IDs to include in the invoice. |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
Failure response
``` { "next_invoice_blocked_by_upgrade": { "code": -1, "message": "next_invoice_blocked_by_upgrade" }, "next_invoice_blocked_by_due_date": { "code": -1, "message": "next_invoice_blocked_by_due_date" }, "next_invoice_unpaid_exists": { "code": -1, "message": "next_invoice_unpaid_exists" } }
```
whmcs/get_billing_data¶
Returns detailed information about a specific server's billing data, including EU B2C status and refund data (if applicable).
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",
"client": {
"id": 12345,
"email": "[email protected]",
"firstname": "John",
"lastname": "Doe",
"countrycode": "US",
"currency_code": "USD"
},
"location": "COM",
"eu_b2c": 0,
"eu_withdrawal": 0,
"eu_withdrawal_licenses": []
}
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 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 |
| billing_status | ❌ | string | Payment 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 customer information from WHMCS, including profile data, contact details, and assigned groups.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_client |
| token | ✅ | string | Authorization token |
| ❌ | string | Customer email for search | |
| full | ❌ | bool | Flag to get full data (including password and hidden fields) |
Example Request
Example of a successful response
{
"result": "OK",
"client": {
"id": 123,
"firstname": "John",
"lastname": "Doe",
"email": "[email protected]",
"status": "Active",
"corporate": 0,
"currency_code": "USD",
"countrycode": "US",
"billing_location": "whmcs_itb",
"groupdata": {
"id": 1,
"groupname": "Premium Users"
},
"internal": {
"id": 123,
"email": "[email protected]",
"corporate": 0
}
}
}
Failure response
``` { "code": -1, "message": "whmcs_get_client: Invalid request clientid@location" }
```
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 |
| location | ✅ | string | Billing location (e.g., whmcs, COM, RU) |
| 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 for the specified customer or checks access rights to them.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_contacts |
| token | ✅ | string | Authorization token |
| ❌ | string | Email to search for a specific contact (used when checking sub-account permissions) |
Example Request
Example of a successful response
{
"result": "OK",
"module": "whmcs",
"action": "get_contacts",
"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 | ✅ | int | Invoice ID |
| load_client_data | ❌ | int | Flag to load client data (1 — load) |
Example Request
Example of a successful response
{
"result": "OK",
"status": "success",
"items": {
"item": [
{
"relid": 123,
"inv_id": 456,
"type": "Hosting"
}
]
},
"currencycode": "USD",
"billing": "whmcs",
"userid": 12345,
"customer": {
"client": {
"id": 12345,
"firstname": "John",
"lastname": "Doe",
"email": "[email protected]",
"currency_code": "USD"
}
}
}
Failure response
``` { "code": -1, "message": "invalid invoice id 123 at whmcs" }
```
whmcs/get_invoices¶
Returns a list of all invoices associated with a customer in WHMCS for the specified 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/auth context) |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "Invalid client id" }
```
whmcs/get_related_invoices¶
Returns a list of invoices associated with a specific server or account in WHMCS.
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 |
| id | ❌ | int | Server ID (if specified, its account_id is used) |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
Failure response
``` { "result": -1, "action": "get_related_invoices", "error": "server $id are not linked to the billing" }
```
whmcs/getcredits¶
Returns information about the user's available balance (credits) in WHMCS for the specified location.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: getcredits |
| token | ✅ | string | Authorization token |
| id | ❌ | int | User ID (if not specified, it is taken from the session) |
Example Request
Failure response
``` { "code": -1, "message": "failed to retrive account history at LOC, please contact support - error_details" }
```
whmcs/getpaymentgw¶
Returns a list of payment gateways available for a specific invoice, considering the customer's currency and regional restrictions.
HTTP Method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Action name: getpaymentgw |
| token | ✅ | string | Authorization token |
| invoice_id | ✅ | int | Invoice ID to check available payment methods |
Example Request
Example of a successful response
{
"result": "OK",
"methods": {
"stripe": {
"call": "https://invapi.hostkey.com?invoice_id=123&action=pay"
},
"paypalcheckout": {
"call": "<span style='text-align:left'><p data-intl='please_wire_funds_in_favor'>Please wire funds in favor of: </p><a href=\"https://invapi.hostkey.com?invoice_id=123\">Pay Now</a></span>"
},
"banktransfer": {
"call": "<span style='text-align:left'><p data-intl='please_wire_funds_in_favor'>Please wire funds in favor of: </p>...</span>"
}
}
}
Failure response
``` { "code": -1, "message": "failed to retrive payment gw list: error message" }
```
whmcs/mass_pay¶
Creates one combined invoice to pay several 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. 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 service cancellation process. It checks for active licenses, invoice payment status, and automatic refund eligibility (including EU B2C rules). If there are traffic debts, they are taken into account when calculating the refund amount.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: request_cancellation |
| id | ✅ | int | Server ID for cancellation |
| cancellation_type | ❌ | int | Cancellation type (e.g., 1 for immediate) |
| cancellation_reason | ❌ | string | Order cancellation reason |
| token | ✅ | string | Authorization token |
| billing | ✅ | string | Billing location |
| clientid | ✅ | int | Customer ID in WHMCS |
| ✅ | string | User email | |
| refund | ❌ | float | Refund amount |
| currency | ❌ | string | Refund currency |
| service_price | ❌ | float | Service price |
| refund_message | ❌ | string | Refund message text |
| refund_message_short | ❌ | string | Short refund message text |
| last_invoice | ✅ | int | Last invoice item ID (last_inv_id) |
| prev_invoice_id | ❌ | int | Previous invoice ID to account for overage |
| relid | ✅ | int | Account ID (service_relid) |
| tax | ❌ | float | Tax amount |
| vat_extra | ❌ | bool | VAT extra flag |
| rec_before_tax | ❌ | float | Amount before taxes |
| d_deploy_time | ❌ | string | Deploy date (deploy_date) |
| d_bill_time | ❌ | string | Current request time |
| d_reccuring | ❌ | float | Recurring payment (rec) |
| d_period | ❌ | string | Billing cycle |
| cbp_adjusted | ❌ | string | CBP adjustment message |
Example Request
curl -s "https://invapi.hostkey.com/whmcs.php" -X POST \
--data "action=request_cancellation" \
--data "id=123" \
--data "token=YOUR_TOKEN" \
--data "billing=US" \
--data "clientid=456" \
--data "[email protected]" \
--data "last_invoice=789" \
--data "relid=1011"
Failure response
``` { "code": -3, "message": "whmcs_server_exceded_traffic" }
```
whmcs/request_subscription_cancellation¶
Sends a request to cancel a bank subscription by creating a ticket in JIRA. It checks for active subscriptions and payment status.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: request_subscription_cancellation |
| id | ✅ | int | Server ID for cancellation |
| cancellation_type | ❌ | string | Cancellation type (e.g., 1) |
| cancellation_reason | ❌ | string | Subscription cancellation reason |
| token | ✅ | string | API authentication token |
Example Request
Failure response
``` { "code": -1, "message": "sub_cancel_jira_error" }
```
whmcs/reset_password¶
Initiates the password reset process. If no token is provided, a link is sent via email. If the token is valid, it verifies 2FA and updates the password.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: reset_password |
| ✅ | string | User email for password reset | |
| reset_token | ❌ | string | Access recovery token (if email is not specified) |
| pass | ❌ | string | New password (used if a token is present and 2FA is passed) |
| code | ❌ | string | Two-factor authentication (2FA) code |
| location | ❌ | string | Billing location (default Auto) |
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
``` { "result": -1, "error": "invalid request, user@domain.tld is not email", "code": "PASSWORD_RESET_FAILED" }
```
whmcs/transactions¶
Returns a list of user financial transactions from WHMCS based on filters.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: transactions |
| transaction_id | ❌ | string | Specific transaction ID |
| invoice_id | ❌ | int | 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, and custom fields. Supports email uniqueness check and verification via SMS/2FA.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: update_client |
| token | ✅ | string | Authorization token |
| profile_data[client_id] | ✅ | int | Customer 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 | Billing first name |
| profile_data[billing_lastname] | ❌ | string | Billing last name |
| profile_data[co_customertype] | ❌ | string | Customer type (Individual / Company) |
| profile_data[ips] | ❌ | string | List of IP addresses for ACL separated by comma/space |
| profile_data[co_smsnum] | ❌ | string | Phone number (with verification support) |
| profile_data[tg_username] | ❌ | string | Telegram username (@username) |
| profile_data[co_secret] | ❌ | string | Secret word (if applicable) |
Example Request
Example of a successful response
{
"result": "OK",
"clientid": 123,
"location": "whmcs_ru",
"billing_email": "[email protected]",
"firstname": "John",
"lastname": "Doe",
"co_smsnum": "+79001234567"
}
Failure response
``` { "code": -1, "message": "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. Supports email uniqueness check and phone number validation.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: update_contact |
| contact_id | ✅ | int | Contact ID to update |
| ✅ | string | Contact email (uniqueness check performed) | |
| firstname | ✅ | string | Contact first name |
| lastname | ❌ | string | Contact last name |
| phonenumber | ❌ | string | Phone number (undergoes validation and transliteration) |
| password1 | ❌ | string | New contact password |
| password2 | ❌ | string | Password confirmation |
| token | ✅ | string | API authentication token |
Example Request
Failure response
``` { "code": -1, "message": "fill_required_fields" }