Skip to main content

Crate whmcs

Crate whmcs 

Source
Expand description

§whmcs

Async HTTP client for the WHMCS remote API (includes/api.php). It sends application/x-www-form-urlencoded bodies, asks WHMCS for JSON (responsetype=json), and maps the envelope result: success | error to Result<T, WhmcsError> (WhmcsError).

Typical use looks like this:

§Quick start

use whmcs::{WhmcsBuilder, WhmcsError};
use whmcs::models::clients::{GetClientParams, GetClientsResponse};

async fn example() -> Result<(), WhmcsError> {
    let client = WhmcsBuilder::new()
        .url("https://billing.example.com/includes/api.php")
        .api_identifier("your-api-identifier")
        .api_secret("your-api-secret")
        .timeout(30_u64)
        .build()?;

    let list: GetClientsResponse = client
        .get_clients(GetClientParams::default().search("user@example.com"))
        .await?;

    println!("total matches: {}", list.total_results);
    Ok(())
}

§Building a client

With the default builder feature, use WhmcsBuilder to set the API URL, credentials, and optional timeout, then call WhmcsBuilder::build. Any field you omit on the builder is filled from environment variables when build runs:

Builder fieldEnvironment variable
URLWHMCS_URL
IdentifierWHMCS_API_IDENTIFIER
SecretWHMCS_API_SECRET
Timeout (seconds)WHMCS_TIMEOUT (falls back to 30)

If the URL path does not end with api.php, the builder normalizes it so requests target .../includes/api.php under your WHMCS base path.

With default-features = false (disabling builder), construct WhmcsClient with WhmcsClient::new and supply URL and secrets yourself.

§Requests and responses

  • Typed helpers — Methods on WhmcsClient (implemented in this crate’s resources modules) call WhmcsClient::request with the correct WHMCS action name and serde types.
  • Generic accessWhmcsClient::request accepts any P that implements serde::Serialize into a JSON object (flat key/value pairs), and any success body type T that implements serde::de::DeserializeOwned for the payload after the result field is handled by WhmcsRawResponse.

WHMCS often encodes booleans and nested lists in non-standard ways; this crate uses custom deserializers in models where needed.

§Errors

See WhmcsError for request, JSON, and WHMCS-level failures. Configuration problems when using the builder are reported as BuilderError.

§Cargo features

FeatureDefaultDescription
builderyesWhmcsBuilder, BuilderError, and BuilderError inside WhmcsError.

§Further reading

Re-exports§

pub use models::WhmcsRawResponse;
pub use models::WhmcsSorting;

Modules§

models
Serde types and helpers for the WHMCS JSON API.

Structs§

WhmcsBuilder
A builder for the WHMCS API client.
WhmcsClient
HTTP client for the WHMCS remote API.

Enums§

BuilderError
Errors that can occur when building a WhmcsClient.
WhmcsError
Errors that can occur when making a request to the WHMCS API.