WHMCSpy

WHMCSpy is a Python interface to the WHMCS REST API.

PyPI version Documentation Status

Usage

Create a WHMCS interface with the API URL and credentials and use it to call the API.

import whmcspy

whmcs = whmcspy.WHMCS(
    'https://example.com/whmcs/includes/api.php',
    'identifier',
    'secret')
whmcs.accept_order(2)

In general API methods can be called as methods in the WHMCS class. For available API methods see the WHMCS API reference. Note that the casing of the methods differ from the API actions. While the API actions are CamelCased the methods are snake_cased.

Calling unimplemented actions

Not all API actions are implemented as Python methods (they will be implemented as required, of course pull-requests are accepted). In order to call actions that are not yet implemented call() can be used. Example:

response = whmcs.call(
    'SomeAction',
    param=value,
    list_param=[
        element,
        element2,
    ]
)

See the call() documentation for more info.

Some actions return batches of results. To iterate over all results multiple requests need to be done. For this a convenience method is added: paginated_call() This method is a generator which yields batches. Using keywords additional params are accepted. Example:

for response in whmcs.paginated_call(
        'GetOrders'):
    for order in response['orders']['order']:
        print(order)

WHMCSpy reference

API
class whmcspy.api.WHMCS(url, identifier, secret)[source]

Bases: object

WHMCS interface.

accept_order(order_id, **params)[source]

Accept an order.

Parameters:
  • order_id (int) – The id of the order to accept.
  • **params – Additional params.

Hint

For additional params, see the official API docs: https://developers.whmcs.com/api-reference/acceptorder/

add_order(clientid, domains=None, paymentmethod='banktransfer', products=None, **params)[source]

Add an order.

Parameters:
  • clientid (int) – The id of the client whom the order is for.
  • **params – Additional params.
Keyword Arguments:
 
  • domains (list) – A list of domains to include in the order.
  • paymentmethod (str) – The payment method for the order.
  • products – A list of products (dict) with an id and a domain name (pid, domain).
Returns:

The response of the successfully created order.

Hint

For additional params, see the official API docs: https://developers.whmcs.com/api-reference/addorder/

add_product(name, gid, **params)[source]

Add product.

Parameters:
  • name (str) – The name of the product.
  • gid (int) – The id of the group to add the product to.
  • **params – Additional params.
Returns:

The id of the created product (pid).

Return type:

int

Hint

For additional params, see the official API docs: https://developers.whmcs.com/api-reference/addproduct/

add_transaction(paymentmethod, **params)[source]

Add a transaction.

Parameters:
  • paymentmethod (str) – The payment method used to perform the
  • transaction.
  • **params – Additional params.

Hint

For additional params, see the official API docs: https://developers.whmcs.com/api-reference/addtransaction/

call(action, **params)[source]

Call the WHMCS api.

This is an abstract way to call the WHMCS API. Basically only the action and additional params are required to make a call.

Parameters:
  • action (str) – The action to perform.
  • **params – Additional params.
Returns:

The result of the call.

Return type:

dict

Raises:
  • MissingPermission – When access is denied due to a missing permission.
  • Error – Whenever the call fails.
cancel_order(orderid, **params)[source]

Cancel a pending order.

Parameters:
  • orderid (int) – The id of the order.
  • **params – Additional params.

Hint

For additional params, see the official API docs: https://developers.whmcs.com/api-reference/cancelorder/

delete_order(orderid, **params)[source]

Delete a cancelled or fraud order.

Parameters:orderid (int) – The id of the order.
get_clients_domains(active=None, **params)[source]

Get domains (registrations).

Parameters:**params – Additional params.
Keyword Arguments:
 active (bool) – Filter on active or inactive domains.
Yields:The domains.

Hint

For additional params, see the official API docs: https://developers.whmcs.com/api-reference/getclientsdomains/

get_clients_products(active=None, productid=None, **params)[source]

Get client products.

Parameters:

**params – Additional params.

Keyword Arguments:
 
  • active (bool) – Filter on active or inactive domains.
  • productid (int) – Only get products with this product id.
Yields:

The products.

Hint

For additional params, see the official API docs: https://developers.whmcs.com/api-reference/getclientsproducts/

get_invoice(invoiceid)[source]

Get an invoice.

Parameters:invoiceid (int) – The id of the invoice.
Returns:The invoice
get_orders(**params)[source]

Get orders.

Parameters:**params – Additional params.
Yields:The matching orders.

Hint

For additional params, see the official API docs: https://developers.whmcs.com/api-reference/getorders/

get_servers(**params)[source]

Get servers configured in WHMCS.

Parameters:**params – Additional params.

Hint

For additional params, see the official API docs: https://developers.whmcs.com/api-reference/getservers/

get_tickets(**params)[source]

Get support tickets.

Parameters:**params – Additional params.
Yields:The tickets.

Hint

For additional params, see the official API docs: https://developers.whmcs.com/api-reference/gettickets/

get_tld_pricing()[source]

Get the TLD pricing.

Returns:The TLD pricing info.
Return type:dict
get_transactions(**params)[source]

Get (find) transactions.

Parameters:**params – Additional params.
Returns:A list of matching transactions.

Hint

For additional params, see the official API docs: https://developers.whmcs.com/api-reference/gettransactions/

module_create(serviceid)[source]

Run the module create action for a service.

Parameters:serviceid (int) – The id of the service.
open_ticket(deptid, subject, message, **params)[source]

Open a support ticket

Parameters:
  • deptid (int) – The id of the department to open the ticket for.
  • subject (str) – The subject of the ticket.
  • message (str) – The initial message of the ticket.
  • **params – Additional params.

Hint

For additional params, see the official API docs: https://developers.whmcs.com/api-reference/openticket/

Note

Markdown doesn’t seem to work when opening a ticket by using the API. Maybe it’s fixed in later versions of WHMCS. Consider it unstable.

paginated_call(action, limitstart=0, **params)[source]

Perform a WHMCS API call, but paginated.

Instead of returning just a single result a result is yielded for every iteration until an empty result returns from WHMCS. See call() for common params.

Keyword Arguments:
 limitstart (int) – The offset from which to start. Initially this is 0.
Yields:An API response.
pending_order(orderid, **params)[source]

Set an order and it’s items to Pending.

Parameters:orderid (int) – The id of the order.
send_email(**params)[source]

Send a client email notification.

Parameters:**params – Additional params.

Hint

For additional params, see the official API docs: https://developers.whmcs.com/api-reference/sendemail/

update_client_domain(domain, **params)[source]

Update a client’s domain registration.

Parameters:
  • domain (dict) – The domain to update.
  • **params – Additional params.

Hint

For additional params, see the official API docs: https://developers.whmcs.com/api-reference/updateclientdomain/

update_client_product(productid, **params)[source]

Update a client’s product.

Parameters:
  • productid (int) – The id of the client product.
  • **params – Additional params.

Hint

For additional params, see the official API docs: https://developers.whmcs.com/api-reference/updateclientproduct/

Exceptions
exception whmcspy.exceptions.Error[source]

Bases: Exception

An unspecified error.

exception whmcspy.exceptions.MissingPermission[source]

Bases: whmcspy.exceptions.Error

Missing permission when calling the API.

Indices and tables