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 contact user to an existing 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 specific unpaid invoice. If payment is successful, the invoice status changes to Paid. |
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 billing is activated. |
delete_cancellation_request | delete cancellation request | Deletes an existing service cancellation request, restoring the invoice status or allowing the order to be recreated. |
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 server is undergoing an upgrade. |
get_billing_data | get server billing data | Returns detailed information about the billing data of a specific server, including EU withdrawal status and synchronized data from WHMCS. |
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 information about the authenticated client, including data from WHMCS and internal system data (tags, verification status). Supports extended output mode via the full parameter. |
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 client or checks access rights to user contacts. |
get_invoice | get invoice data | Returns detailed information about an invoice from WHMCS, including client data and payment status. |
get_invoices | get client invoices list | Returns a list of all invoices associated with the client in WHMCS for the specified location. |
get_related_invoices | get related invoices | Returns a list of invoices associated with a specific server (order/service) |
getcredits | get balance (credits) | Returns the user's current credit balance in WHMCS for the specified location. |
getpaymentgw | get available payment gateways | Returns a list of available payment methods (gateways) attached to a specific invoice in WHMCS. |
mass_pay | mass pay invoices | Allows bulk payment of several client invoices in a single request. A minimum of 2 invoices is required. |
request_cancellation | request subscription cancellation | Sends a request to cancel the bank subscription for a server. It checks for active licenses, invoice payment status, and eligibility for automatic refunds (EU withdrawal). |
request_subscription_cancellation | request subscription cancellation | Initiates the process of canceling the bank subscription for a server. Creates a JIRA ticket and attaches a request tag to the server. |
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 allows setting a new password (with 2FA support). |
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 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 | Updates additional contact information (first name, last name, email, phone) in the WHMCS system. Changing the primary email or phone may require re-verification. |
whmcs/add_contact¶
Adds a new contact user to an existing customer in WHMCS. If the request 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 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 |
| profile_data[password2] | ✅ | string | Password confirmation |
| profile_data[phonenumber] | ❌ | string | Phone number (SMS support check) |
| token | ✅ | string | API authentication token |
Example Request
curl -s "https://invapi.hostkey.com/whmcs.php" -X POST \
--data "action=add_contact" \
--data "type=0" \
--data "profile_data[firstname]=John" \
--data "profile_data[lastname]=Doe" \
--data "profile_data[email][email protected]" \
--data "profile_data[password1]=Secret123!" \
--data "profile_data[password2]=Secret123!" \
--data "token=YOUR_API_TOKEN"
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 the customer's available balance (credit) to pay a specific unpaid invoice. If payment is successful, the invoice status changes to Paid.
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
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). If the subscribe option is enabled, automatic billing is activated.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: create_addfunds |
| amount | ✅ | number | Top-up amount. If subscribe=true is not specified, the minimum amount is 20. |
| description | ❌ | string | Payment description |
| subscribe | ❌ | boolean | Enable automatic billing (auto-renewal) |
| 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 an existing service cancellation request, restoring the invoice status or allowing the order to be recreated.
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 is being deleted |
| 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 (extracted from user context) |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
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
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 mode: 1 — inline (in browser), 0 — attachment (download) |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "undefined billing location" }
```
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 server is undergoing an upgrade.
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
``` { "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 the billing data of a specific server, including EU withdrawal status and 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 |
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|GET
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. |
| user_id | ❌ | int | User ID to get all their cancellation requests. |
| period_from | ❌ | string | Start date of the period (format Y-m-d). |
| period_to | ❌ | string | End date of the period (format Y-m-d). |
| 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": "Invalid billing location $location" }
```
whmcs/get_client¶
Returns detailed information about the authenticated client, including data from WHMCS and internal system data (tags, verification status). Supports extended output mode via the full parameter.
HTTP Method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_client |
| token | ✅ | string | Authorization token |
| full | ❌ | boolean | If true, returns an extended dataset (including groups and full client data) |
| 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",
"status": "Active",
"currency_code": "USD",
"countrycode": "US",
"phonenumber": "+1234567890",
"address1": "Main St 1",
"city": "New York",
"state": "NY",
"postcode": "10001",
"countryname": "United States",
"companyname": "John Corp",
"groupid": 5,
"corporate": 0
},
"billing_location": "whmcs_com",
"internal": {
"id": 123,
"email": "[email protected]",
"active_since": "2023-01-15",
"corporate": 0
},
"groupdata": {
"id": 5,
"groupname": "Premium Users"
}
}
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 | Billing location (e.g., whmcs_com or COM) |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "Billing error: Invalid location" }
```
whmcs/get_contacts¶
Returns a list of additional contacts for the specified client or checks access rights to user contacts.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_contacts |
| ❌ | string | Email for searching a specific contact in the list of associated users | |
| full | ❌ | boolean | If true, returns complete data from WHMCS along with API metadata |
| 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 client data and payment status.
HTTP Method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_invoice |
| invoice_id | ✅ | int | Invoice ID |
| load_client_data | ❌ | boolean | Load client data along with the invoice |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
{
"result": "OK",
"status": "success",
"items": {
"item": [
{
"relid": 123,
"inv_id": 456,
"type": "Hosting"
}
]
},
"currencycode": "USD",
"billing": "whmcs",
"customer": {
"firstname": "John",
"lastname": "Doe",
"email": "[email protected]"
}
}
Failure response
``` { "code": -1, "message": "invalid invoice id 0 at whmcs_com" }
```
whmcs/get_invoices¶
Returns a list of all invoices associated with the client 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 (e.g., whmcs_com) |
Example Request
Example of a successful response
Failure response
``` { "result": -1, "message": "Invalid client id" }
```
whmcs/get_related_invoices¶
Returns a list of invoices associated with a specific server (order/service)
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_related_invoices |
| account_id | ❌ | int | WHMCS Account ID |
| id | ✅ | int | Server ID (relid) |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "Invalid billing location whmcs_com" }
```
whmcs/getcredits¶
Returns the user's current credit balance 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 whmcs_com, please contact support - error_details" }
```
whmcs/getpaymentgw¶
Returns a list of available payment methods (gateways) attached to a specific invoice in WHMCS.
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 gateways for |
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>...</span>"
}
}
}
Failure response
``` { "code": -1, "message": "failed to retrive payment gw list: error message" }
```
whmcs/mass_pay¶
Allows bulk payment of several client invoices in a single request. 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¶
Sends a request to cancel the bank subscription for a server. It checks for active licenses, invoice payment status, and eligibility for automatic refunds (EU withdrawal).
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | ✅ | int | Server ID to cancel subscription |
| cancellation_type | ❌ | int | Cancellation type (1 - automatic) |
| cancellation_reason | ❌ | string | Reason for cancellation |
| refund | ✅ | float | Refund amount |
| currency | ✅ | string | Refund currency |
| service_price | ❌ | float | Service price for calculation |
| refund_message | ✅ | string | Full refund message (RU/EN) |
| refund_message_short | ✅ | string | Short refund message |
| clientid | ✅ | int | WHMCS Client ID |
| billing | ✅ | string | Billing location (e.g., whmcs_itb) |
| ✅ | string | Client email for notification | |
| last_invoice | ✅ | int | Last payment ID (last_inv_id) |
| prev_invoice_id | ❌ | int | Previous invoice ID for partial refund |
| relid | ✅ | int | Server Account ID (service_relid) |
| tax | ❌ | float | Tax amount for refund adjustment |
| vat_extra | ❌ | boolean | VAT extra flag (for COM locations) |
| rec_before_tax | ❌ | float | Amount before tax for correct invoice generation |
| d_deploy_time | ❌ | string | Server deployment date (for EU withdrawal) |
| d_bill_time | ❌ | string | Current request execution time |
| d_reccuring | ❌ | float | Recurring payment amount (recurring amount) |
| d_period | ❌ | string | Current billing cycle |
| cbp_adjusted | ❌ | string | CBP adjustment message |
| token | ✅ | string | API authentication token |
Example Request
curl -s "https://invapi.hostkey.com/whmcs.php" -X POST \
--data "id=123" \
--data "refund=50.00" \
--data "currency=USD" \
--data "refund_message=Refund processed successfully" \
--data "refund_message_short=Refunded" \
--data "clientid=456" \
--data "billing=whmcs_itb" \
--data "[email protected]" \
--data "last_invoice=789" \
--data "relid=1011" \
--data "token=YOUR_API_TOKEN"
Failure response
``` { "code": -3, "message": "whmcs_immediate_cancellation_no_invoices" }
```
whmcs/request_subscription_cancellation¶
Initiates the process of canceling the bank subscription 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
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 allows setting a new password (with 2FA support).
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: reset_password |
| token | ✅ | string | Auth token for API authorization |
| ❌ | string | Email address for password reset or identification | |
| reset_token | ❌ | string | Token to confirm the reset operation (if not provided, email is sent) |
| pass | ❌ | string | New password for the user |
| code | ❌ | string | 2FA code required if 2FA is enabled for the account |
Example Request
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 | ❌ | int | Invoice ID to get associated transactions |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "failed to retrive transactions - error_details" }
```
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 email address |
| profile_data[billing_firstname] | ❌ | string | Client first name |
| profile_data[billing_lastname] | ❌ | string | Client 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) |
| profile_data[billing_country] | ❌ | string | Country of residence/registration |
| profile_data[co_secret] | ❌ | string | Secret word (custom field) |
Example Request
Example of a successful response
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) in the WHMCS system. Changing the primary email or phone may require re-verification.
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 (validated and transliterated) |
| params[password1] | ❌ | string | New password 1 |
| params[password2] | ❌ | string | New password 2 (for password change) |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
{
"result": "OK",
"contactid": 67890,
"clientid": 12345,
"email": "[email protected]",
"firstname": "John",
"lastname": "Doe",
"location": "whmcs_com"
}
Failure response
``` { "code": -1, "message": "fill_required_fields" }