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 to an existing customer in WHMCS or creates a random contact user. |
apply_credit | apply credit to invoice | Applies the customer's available balance (credit) to pay a selected invoice. If the credit amount exceeds the invoice balance, only the debt amount is applied. |
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 fund deduction is activated. |
delete_cancellation_request | delete cancellation request | Deletes an existing service cancellation request for a specific server, allowing the order status to be restored. |
delete_contact | delete contact | Deletes an additional contact linked to a customer in WHMCS. |
download_invoice | download invoice | Returns a PDF file of the invoice in base64 format. Allows viewing the invoice (inline) or downloading it as a file. |
generate_due_invoice | generate due invoice | Generates the next due invoice in WHMCS, considering the current billing cycle and any unpaid invoices. The operation is blocked if the customer has active upgrade tags or unpaid invoices. |
get_billing_data | get server billing data | Returns detailed billing information for a specific server, including customer data and related parameters. |
get_cancellation_requests | get cancellation requests list | 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 information | Returns detailed information about the client from WHMCS, including profile data, groups, and internal system data. |
get_clientgroups | get groups | Returns a list of available client groups from WHMCS for the specified location. |
get_contacts | get client contacts | Returns a list of additional contacts linked to the WHMCS client. If an email is specified, only contacts with corresponding access rights are returned. |
get_invoice | get invoice data | Returns detailed information about an invoice from WHMCS, including customer data and payment status. |
get_invoices | get invoices list | Returns a list of all invoices associated with the client's account in WHMCS. If the user is a customer, only their own invoices are returned. |
get_related_invoices | get related invoices | Returns a list of invoices associated with a specific server or account in WHMCS |
getcredits | get credit balance | Returns information about the available credits (balance) of the user in WHMCS for the specified location. |
getpaymentgw | get payment gateways for invoice | Returns a list of available payment methods (gateways) for a specific invoice. Includes link processing and specific parameters for gateways such as PayPal or BitPay. |
mass_pay | mass pay invoices | Creates one single invoice to pay multiple selected client invoices. |
request_cancellation | request order/subscription cancellation | Initiates the process of canceling an order or subscription. Checks for active licenses, invoice payment status, and traffic debt before processing a refund. |
request_subscription_cancellation | request subscription cancellation | Initiates the process of canceling a bank subscription for a server. Creates a JIRA ticket and attaches a request tag to the server. |
reset_password | reset password | Allows initiating the password reset process (sending a link via email) or completing it using a token and 2FA code. |
transactions | get client transactions | Returns a list of financial transactions for the user associated with an invoice or a specific operation. |
update_client | update client data | Updates personal client data, contact information (email, phone), 2FA settings, and custom fields in WHMCS. |
update_contact | update contact | Updates existing contact data (first name, last name, email, phone) in WHMCS. If the primary client email is updated, re-verification may be required. |
whmcs/add_contact¶
Adds a new additional contact to an existing customer in WHMCS or creates a random contact user.
HTTP Method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: add_contact |
| type | ❌ | integer | Operation type (0 - create random contact, 1 - add specific user) |
| 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 (for EU location and user creation) |
| profile_data[password2] | ✅ | string | Confirm password |
| 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 "action=add_contact" \
--data "type=1" \
--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 selected invoice. If the credit amount exceeds the invoice balance, only the debt amount is applied.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: apply_credit |
| token | ✅ | string | Authorization token |
| invoice_id | ✅ | integer | Invoice ID for payment |
| amount | ❌ | number | Credit amount (if not specified, the maximum possible amount is used) |
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 fund deduction is activated.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: create_addfunds |
| amount | ✅ | number | Top-up amount. Minimum 20 for regular top-ups. |
| subscribe | ❌ | boolean | Enable automatic fund deduction (recurring payment) |
| description | ❌ | string | Payment purpose description |
| 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 for a specific server, allowing the order status to be restored.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: delete_cancellation_request |
| id | ✅ | int | Server ID (relid) |
| token | ✅ | string | Authorization token |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "Server 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 a PDF file of the invoice in base64 format. Allows viewing the invoice (inline) or downloading it as a file.
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 (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 in WHMCS, considering the current billing cycle and any unpaid invoices. The operation is blocked if the customer has active upgrade tags or unpaid invoices.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: generate_due_invoice |
| id | ✅ | int | Server ID for invoice generation |
| 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 billing information for a specific server, including customer data and related parameters.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_billing_data |
| id | ✅ | int | Server ID |
| token | ✅ | string | Authorization token |
| full | ❌ | bool | Flag to retrieve full data (via GET/POST) |
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 | Product (server) ID to get requests for a specific product |
| user_id | ❌ | int | User (client) ID to filter their requests |
| location | ❌ | string | Billing location |
| cancellation_type | ❌ | string | Cancellation type for filtering |
| billing_status | ❌ | string | Invoice payment status (e.g., Paid) |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
whmcs/get_client¶
Returns detailed information about the client from WHMCS, including profile data, groups, and internal system data.
HTTP Method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_client |
| token | ✅ | string | Authorization token |
| ❌ | string | Client email for search | |
| full | ❌ | boolean | Flag to retrieve 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",
"status": "Active",
"currency_code": "USD",
"countrycode": "US",
"phonenumber": "+1234567890",
"address1": "Main St 1",
"city": "New York",
"state": "NY",
"postcode": "10001",
"countryname": "United States",
"groupid": 1,
"corporate": 0,
"customfields": {}
},
"billing_location": "whmcs",
"internal": {
"id": 123,
"email": "[email protected]",
"active_since": "2024-01-01"
}
}
Failure response
``` { "code": -1, "message": "Request failed for client@location: error message" }
```
whmcs/get_clientgroups¶
Returns a list of available client 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 (defaults to config) |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "Invalid request or unauthorized access" }
```
whmcs/get_contacts¶
Returns a list of additional contacts linked to the WHMCS client. If an email is specified, only those contacts with corresponding access rights are returned.
HTTP Method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_contacts |
| token | ✅ | string | Authorization token |
| ❌ | string | Email for filtering contacts (used to check sub-contact access rights) | |
| full | ❌ | boolean | If true, returns extended information from WHMCS |
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",
"contact_id": 456
}
]
}
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|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_invoice |
| invoice_id | ✅ | int | Invoice ID |
| token | ✅ | string | Authorization token |
| load_client_data | ❌ | int | Load client data flag (1 — yes) |
Example Request
Example of a successful response
{
"result": "OK",
"status": "Paid",
"items": {
"item": [
{
"relid": 123,
"inv_id": 456
}
]
},
"currencycode": "USD",
"billing": "whmcs_eu",
"customer": {
"id": 12345,
"email": "[email protected]"
}
}
Failure response
``` { "code": -1, "message": "invalid invoice id 0 at whmcs_eu" }
```
whmcs/get_invoices¶
Returns a list of all invoices associated with the client's account in WHMCS. If the user is a customer, only their own invoices are returned.
HTTP Method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_invoices |
| token | ✅ | string | Authorization token |
| clientid | ❌ | integer | Client ID (used for filtering in user context) |
| location | ❌ | string | Billing location |
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 or account in WHMCS
HTTP Method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_related_invoices |
| id | ❌ | int | Server ID (if specified, its account_id is used) |
| account_id | ❌ | int | Account ID to search for invoices |
| token | ✅ | string | API authentication 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 credits (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_LOCATION, please contact support - error_details" }
```
whmcs/getpaymentgw¶
Returns a list of available payment methods (gateways) for a specific invoice. Includes link processing and specific parameters for gateways such as PayPal or BitPay.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method name: getpaymentgw |
| token | ✅ | string | Authorization token |
| invoice_id | ✅ | int | Invoice ID |
Example Request
Example of a successful response
{
"result": "OK",
"methods": {
"paymaster": {
"call": "https://bill.hostkey.com/modules/gateways/paymaster.php?id=123"
},
"paypalcheckout": {
"call": "https://invapi.hostkey.com?invoice_id=123"
},
"banktransfer": {
"call": "<span style='text-align:left'><p data-intl='please_wire_funds_in_favor'>Please wire funds in favor of: </p>https://bill.hostkey.com/..."
}
}
}
Failure response
``` { "code": -1, "message": "failed to retrive payment gw list: error message", "details": {} }
```
whmcs/mass_pay¶
Creates one single invoice to pay multiple 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 process of canceling an order or subscription. Checks for active licenses, invoice payment status, and traffic debt before processing a refund.
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 (1 — immediate with refund) |
| cancellation_reason | ❌ | string | Order cancellation reason |
| refund | ✅ | float | Refund amount |
| currency | ✅ | string | Refund currency |
| service_price | ❌ | float | Service cost for calculation |
| refund_message | ✅ | string | Refund message text (RU/EN) |
| refund_message_short | ✅ | string | Short refund message text |
| clientid | ✅ | int | Client ID in WHMCS |
| billing | ✅ | string | Billing location (e.g., whmcs_eu) |
| ✅ | string | Client email for notification | |
| last_invoice | ✅ | int | Last invoice item ID |
| prev_invoice_id | ❌ | int | Previous invoice ID for partial refund |
| relid | ✅ | Account ID (Relid) of the server | |
| vat_msg | ❌ | string | Tax/VAT message |
| rec_before_tax | ❌ | float | Amount before tax deduction |
| d_deploy_time | ❌ | string | Deployment date |
| d_bill_time | ❌ | string | Billing time |
| d_reccuring | ❌ | string | Recurrence period |
| d_period | ❌ | string | Billing cycle/period |
| cbp_adjusted | ❌ | string | CBP adjustment message |
| token | ✅ | string | API authentication token |
Example Request
curl -s "https://invapi.hostkey.com/whmcs.php" -X POST \
--data "action=request_cancellation" \
--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_eu" \
--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 a 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 |
| cancellation_type | ❌ | string | Cancellation type (e.g., 1 for immediate) |
| cancellation_reason | ❌ | string | Cancellation reason |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
{
"result": "OK",
"data": {
"account_id": 1,
"amount": 0.0,
"billing": "string",
"cancellation_reason": "string",
"cancellation_type": "string",
"clientid": 1,
"created": "2023-01-01 00:00:00",
"currency": "USD",
"customfields": [],
"dc_location": "string",
"description": "string",
"displayid": "string",
"email": "[email protected]",
"hwconfig": {},
"invoiceid": 1,
"issueKey": "JIRA-123"
}
}
Failure response
``` { "code": -1, "message": "sub_cancel_jira_error" }
```
whmcs/reset_password¶
Allows initiating the password reset process (sending a link via email) or completing it using a token and 2FA code.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| token | ✅ | string | Auth token for API authorization |
| ✅ | string | User email for password reset or verification | |
| reset_token | ❌ | string | Password reset token (used when completing the process) |
| 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 "token=HOSTKEY_TOKEN" \
--data "[email protected]"
Example of a successful response
Failure response
``` { "code": -1, "message": "Invalid password reset token, please try again." }
```
whmcs/transactions¶
Returns a list of financial transactions for the user associated with an invoice or a specific operation.
HTTP Method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: transactions |
| transaction_id | ❌ | string | Specific transaction ID |
| invoice_id | ❌ | integer | Invoice ID for filtering |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "failed to retrive transactions - error message" }
```
whmcs/update_client¶
Updates personal client data, contact information (email, phone), 2FA settings, and custom fields in WHMCS.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: update_client |
| params[client_id] | ✅ | int | Client ID to update |
| params[location] | ✅ | string | Billing location (e.g., whmcs_eu) |
| params[billing_email] | ❌ | string | New client email address |
| params[billing_firstname] | ❌ | string | Client first name |
| params[billing_lastname] | ❌ | string | Client last name |
| params[co_smsnum] | ❌ | string | Phone number for SMS verification (must be verified) |
| params[ips] | ❌ | string | List of IP addresses for ACL separated by comma/space |
| params[co_customertype] | ❌ | string | Client type (Individual / Company) |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
{
"result": "OK",
"clientid": 12345,
"email": "[email protected]",
"billing_location": "whmcs_eu"
}
Failure response
``` { "code": -1, "message": "invalid profile data: first name contain incorrect symbols" }
```
whmcs/update_contact¶
Updates existing contact data (first name, last name, email, phone) in WHMCS. If the primary client email is updated, re-verification may be required.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: update_contact |
| contact_id | ✅ | int | Contact ID to update |
| ✅ | string | Contact email (required) | |
| firstname | ✅ | string | Contact first name |
| lastname | ❌ | string | Contact last name |
| phonenumber | ❌ | string | Phone number (undergoes validation and transliteration) |
| password1 | ❌ | string | New Password 1 |
| password2 | ❌ | string | Confirm password |
| co_smsnum | ❌ | string | Special field for SMS number (if applicable) |
| token | ✅ | string | API authentication token |
Example Request
Example of a successful response
{
"result": "OK",
"clientid": 12345,
"location": "whmcs_eu",
"email": "[email protected]",
"firstname": "John",
"lastname": "Doe",
"phonenumber": "+79001234567",
"billing_email": "[email protected]",
"co_smsnum": ""
}
Failure response
``` { "code": -1, "message": "fill_required_fields" }