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 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 funds from the account balance (credit) to pay a selected invoice. If the invoice is paid with credit, 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). Supports automatic enabling of autopayments. |
delete_cancellation_request | delete cancellation request | Deletes an existing cancellation request for a specific server, restoring invoice statuses or allowing a new one to be created. |
delete_contact | delete contact | Deletes an additional contact linked to a customer in WHMCS. |
download_invoice | download invoice | Returns the invoice PDF file 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 due invoice in WHMCS, taking into account the current billing cycle and active add-ons. |
get_billing_data | get server billing data | Returns detailed billing information for a specific server, including customer data and EU withdrawal status. |
get_cancellation_requests | get cancellation requests | Returns a list of active service cancellation requests for a specific server or user with filtering by type and payment status. |
get_client | get client info | 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 billing location. |
get_contacts | get contacts | Returns a list of additional contacts for the specified client or checks access rights to subaccount contacts. |
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 client in WHMCS for the specified location. |
get_related_invoices | get related invoices | Returns a list of invoices associated with a specific server (via account_id) |
getcredits | get credits (balance) | Returns information about the user's available balance (credits) in WHMCS for the specified location. |
getpaymentgw | get payment gateways | Returns a list of available payment methods for a specific invoice with processed payment links |
mass_pay | mass pay invoices | Creates one single invoice to pay a list of selected client invoices. |
request_cancellation | request cancellation | Initiates the order/server cancellation process in WHMCS, including status checks, refund calculation, and JIRA ticket creation. |
request_subscription_cancellation | request subscription cancellation | Sends a request to JIRA to cancel a server's bank subscription. Checks for active subscriptions and payment status. |
reset_password | reset password | Initiates the password reset process. If no token is provided, an email link is sent. 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 customer information in WHMCS, including personal data (name, email), contact information, and custom profile fields. |
update_contact | update contact data | Updates additional contact information (first name, last name, email, phone) for a client in WHMCS. Supports email uniqueness check and phone number verification. |
whmcs/add_contact¶
Adds an additional contact 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 new contact) |
| profile_data[firstname] | ✅ | string | Contact first name |
| profile_data[lastname] | ❌ | string | Contact last name |
| profile_data[email] | ✅ | string | Contact email |
| profile_data[password1] | ✅ | string | Password (required for creation) |
| profile_data[password2] | ✅ | string | Password confirmation |
| profile_data[phonenumber] | ❌ | string | Phone number (required for EU-Central location) |
Example Request
Example of a successful response
{
"result": "OK",
"clientid": 12345,
"firstname": "John",
"lastname": "Doe",
"email": "[email protected]"
}
Failure response
``` { "-1": "fill_required_fields" }
```
whmcs/apply_credit¶
Applies funds from the account balance (credit) to pay a selected invoice. If the invoice is paid with credit, 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 | ✅ | float | Credit amount to apply |
| token | ✅ | string | API authentication token |
Example Request
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). Supports automatic enabling of autopayments.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: create_addfunds |
| token | ✅ | string | Authorization token |
| params[amount] | ✅ | number | Top-up amount. If not specified, the default value (0) is used |
| params[description] | ❌ | string | Payment description |
| params[subscribe] | ❌ | boolean | Enable automatic billing (autopay) |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "failed to create AF invoice: [error WHMCS]" }
```
whmcs/delete_cancellation_request¶
Deletes an existing cancellation request for a specific server, restoring invoice statuses 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 (relid) |
| token | ✅ | string | Auth token |
Example Request
Failure response
``` { "code": -1, "message": "Server $id doesn't have a relid data" }
```
whmcs/delete_contact¶
Deletes an additional contact linked to 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 the invoice PDF file 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 |
|---|---|---|---|
| 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, 0 — attachment |
Example Request
Failure response
``` { "code": -1, "message": "Invalid invoice id" }
```
whmcs/generate_due_invoice¶
Generates the next due invoice in WHMCS, taking into account the current billing cycle and active add-ons.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: generate_due_invoice |
| id | ✅ | int | Server ID (equipment ID) |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
Failure response
``` { "next_invoice_blocked_by_upgrade": { "result": -1, "error": "next_invoice_blocked_by_upgrade" }, "next_invoice_blocked_by_due_date": { "result": -1, "error": "next_invoice_blocked_by_due_date" }, "next_invoice_unpaid_exists": { "result": -1, "error": "next_invoice_unpaid_exists" } }
```
whmcs/get_billing_data¶
Returns detailed billing information for a specific server, including customer data and EU withdrawal status.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_billing_data |
| id | ✅ | int | Server ID |
| token | ✅ | string | Authorization token |
Example Request
Example of a successful response
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 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. |
| cancellation_type | ❌ | string | Filter by cancellation type (e.g., 'End of Billing Period') |
| billing_status | ❌ | string | Filter by payment status in WHMCS (e.g., 'Paid', 'Unpaid') |
| period_from | ❌ | string | Start date of the period (format Y-m-d) |
| period_to | ❌ | string | End date of the period (format Y-m-d) |
| 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",
"name_client": "John Doe",
"due_date": "2024-06-20",
"account_id": 55,
"billing": "whmcs_ru",
"status": "Active",
"corporate": "N",
"customer_id": 10,
"is_subcontact": false
}
]
}
Failure response
``` { "code": -1, "message": "Invalid billing location $location" }
```
whmcs/get_client¶
Returns detailed information about the authenticated client, including data from WHMCS and internal system tags.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_client |
| token | ✅ | string | Authorization token |
| ❌ | string | Client email for search | |
| full | ❌ | boolean | Flag to get full data (including passwords and hidden fields) |
Example Request
curl -s "https://invapi.hostkey.com/whmcs.php" -X POST \
--data "action=get_client" \
--data "token=HOSTKEY_TOKEN" \
--data "[email protected]" \
--data "full=true"
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",
"internal": {
"id": 123,
"email": "[email protected]",
"corporate": 0,
"active_since": "2024-01-01"
},
"groupdata": null
}
}
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 billing location.
HTTP-method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_clientgroups |
| location | ✅ | string | Location (billing location) to get groups |
| 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 client or checks access rights to subaccount contacts.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_contacts |
| token | ✅ | string | Authorization token |
| ❌ | string | Email for contact search (used for subaccount) | |
| full | ❌ | boolean | Returns full client data along with contacts |
Example Request
Example of a successful response
{
"result": "OK",
"module": "whmcs",
"action": "get_contacts",
"permission_contacts_granted": true,
"contacts": {
"contact": [
{
"id": 123,
"email": "[email protected]",
"firstname": "John",
"lastname": "Doe",
"permissions": "contacts"
}
]
},
"client": {
"id": 456,
"email": "[email protected]",
"firstname": "John",
"lastname": "Doe"
},
"billing_location": "COM"
}
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 | ❌ | integer | Load client data flag (1 - yes) |
Example Request
Example of a successful response
{
"result": "OK",
"status": "success",
"items": {
"item": [
{
"relid": 123,
"inv_id": 456
}
]
},
"currencycode": "USD",
"billing": "whmcs",
"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 the client in WHMCS for the specified location.
HTTP-method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_invoices |
| token | ✅ | string | Authorization token |
| client_id | ✅ | integer | Client ID |
| location | ✅ | string | Billing location (whmcs_id) |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "Invalid client id or Invalid billing location" }
```
whmcs/get_related_invoices¶
Returns a list of invoices associated with a specific server (via account_id)
HTTP-method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_related_invoices |
| account_id | ❌ | int | WHMCS account ID. If not specified, it is determined automatically by Server ID |
| token | ✅ | string | Authorization token |
Example Request
Example of a successful response
Failure response
``` { "result": -1, "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 |
Example Request
Failure response
``` { "code": -1, "message": "failed to retrive account history at whmcs_ru, please contact support - error_description" }
```
whmcs/getpaymentgw¶
Returns a list of available payment methods 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 | ✅ | int | Invoice ID to get payment gateways |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "failed to retrive payment gw list: error message" }
```
whmcs/mass_pay¶
Creates one single invoice to pay a list of selected client invoices.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: mass_pay |
| invoices[] | ✅ | array | Array of invoice IDs to pay. Minimum 2 values. |
| token | ✅ | string | API authentication token |
Example Request
Failure response
``` { "code": -1, "message": "mass_pay_requires_2_invoices" }
```
whmcs/request_cancellation¶
Initiates the order/server cancellation process in WHMCS, including status checks, refund calculation, and JIRA ticket creation.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | ✅ | int | Server ID for cancellation |
| cancellation_type | ❌ | int | Cancellation type (1 - immediate) |
| cancellation_reason | ❌ | string | Reason for cancellation |
| refund | ❌ | float | Refund amount |
| currency | ❌ | string | Refund currency |
| service_price | ❌ | float | Service cost for calculation |
| refund_message | ❌ | string | Refund message (RU/EN) |
| refund_message_short | ❌ | string | Short refund message |
| last_invoice | ✅ | int | Last invoice ID for refund |
| prev_invoice_id | ❌ | int | Previous invoice ID (if any) |
| relid | ✅ | string | WHMCS account ID |
| vat_msg | ❌ | string | VAT message |
| rec_before_tax | ❌ | float | Amount before taxes |
| d_deploy_time | ❌ | string | Deploy date |
| d_bill_time | ❌ | string | Billing time |
| d_reccuring | ❌ | string | Recurring payment |
| d_period | ❌ | string | Billing period |
| cbp_adjusted | ❌ | string | CBP adjustment message |
| token | ✅ | string | API authentication token |
Example Request
Failure response
``` { "code": -3, "message": "whmcs_immediate_cancellation_no_invoices" }
```
whmcs/request_subscription_cancellation¶
Sends a request to JIRA to cancel a server's bank subscription. 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 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, an email link is sent. If the token is valid, it allows setting a new password (with 2FA support).
HTTP-method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| ✅ | string | User email for password reset | |
| reset_token | ❌ | string | Reset confirmation token (if not empty) |
| 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 "[email protected]"
Example of a successful response
Failure response
``` { "result": "-1", "error": "invalid request, user@domain.tld is not email", "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|GET
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 related 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 customer information in WHMCS, including personal data (name, email), contact information, and custom profile fields.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| token | ✅ | string | Authorization token |
| profile_data[client_id] | ✅ | integer | Client ID in WHMCS |
| profile_data[location] | ✅ | string | Billing location (e.g., whmcs_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 allowed IP addresses separated by comma or space |
| profile_data[co_smsnum] | ❌ | string | Phone number for SMS verification |
| profile_data[form_id] | ❌ | string | Form ID (personal_data, account_owner, address) |
Example Request
curl -s "https://invapi.hostkey.com/whmcs.php" -X POST \
--data "token=HOSTKEY_TOKEN" \
--data "profile_data[client_id]=12345" \
--data "profile_data[location]=whmcs_com" \
--data "profile_data[billing_email][email protected]"
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) for a client in WHMCS. Supports email uniqueness check and phone number verification.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: update_contact |
| contact_id | ✅ | int | Contact ID to update |
| ✅ | string | Contact email (checked for uniqueness and validity) | |
| firstname | ✅ | string | Contact first name |
| lastname | ❌ | string | Contact last name |
| phonenumber | ❌ | string | Phone number (verified via tw_verify_number) |
| password1 | ❌ | string | New password for contact |
| password2 | ❌ | string | Confirm new password |
| token | ✅ | string | API authentication token |
Example Request
Failure response
``` { "code": -1, "message": "fill_required_fields" }