Xtopay

Authentication & Errors

Securely authorize API requests using your Client ID and Client Secret credentials, and handle error responses.

Authentication & Errors

All Xtopay API requests must be authenticated using secure credentials passed in the HTTP headers. Requests made without authorization will fail.


Client ID & Client Secret

Xtopay uses a Client ID and Client Secret credential pair to identify and authorize API requests on behalf of your business. These keys are scoped by environment (Sandbox/Test Mode and Live Mode):

CredentialFormatPrefix / LengthScopeUsage
Client IDHex String12 charactersClient-Side / Server-SidePublic identifier for your integration.
Client SecretHex String64 charactersServer-SideSecure credential used to authorize API actions. Must be kept secret.

To retrieve or roll your API credentials, navigate to the Developer Settings > API Keys section in your dashboard.

[!CAUTION] Keep Client Secrets Safe Your Client Secret grants full access to your Xtopay wallet collections, direct debits, and disbursements. Never commit secrets to version control, expose them in client-side code, or distribute them inside frontend applications.


Authorization Header

Authenticate server-side API requests by combining your Client ID and Client Secret, base64-encoding the result, and passing it in the Authorization header. Xtopay's authentication middleware supports both the Basic and Bearer authorization schemes.

Step-by-Step Authorization Token Generation

  1. Concatenate your Client ID and Client Secret with a colon (:):
    YOUR_CLIENT_ID:YOUR_CLIENT_SECRET
  2. Base64 Encode the concatenated string:
    Base64("YOUR_CLIENT_ID:YOUR_CLIENT_SECRET")
  3. Include the encoded token in the HTTP request headers:
    Authorization: Basic Y2xpZW50SWQ6Y2xpZW50U2VjcmV0
    Content-Type: application/json

Authentication Examples

Choose your language below to see how to programmatically generate the token and authenticate API requests:

# You can pass client_id and client_secret directly via curl basic auth using the -u flag
curl https://api.xtopay.co/v1/payments/pay_cl8z2e8z20000g \
  -u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \
  -H "Accept: application/json"

API Key Permissions & Scopes

To enforce the principle of least privilege, you can restrict API keys to specific permissions. When generating keys in the Xtopay Dashboard, you can assign granular scopes:

ScopeDescription
payments:writeAllowed to create payments, direct debits, bank transfers, and process refunds.
payments:readAllowed to retrieve payments and query transaction history.
customers:writeAllowed to create and update customer profiles.
customers:readAllowed to list and retrieve customer information.
credits:writeAllowed to grant and deduct credit balances.
credits:readAllowed to retrieve wallet balances and ledgers.
meters:writeAllowed to define billing meters and ingest usage events.
meters:readAllowed to view meters and fetch event history.
licenses:writeAllowed to create, activate, modify, and revoke license keys.
licenses:readAllowed to read and validate license keys.

Error Handling

Xtopay uses standard HTTP response codes to indicate the success or failure of requests. In general:

  • Codes in the 2xx range indicate success.
  • Codes in the 4xx range indicate a client error (e.g. missing parameters, invalid inputs, or authentication failure).
  • Codes in the 5xx range indicate a server-side error with Xtopay's infrastructure or processor gateways.

Error Response Format

When an API call fails, Xtopay returns a descriptive JSON payload containing a success boolean and an error message detail:

{
  "success": false,
  "error": "amount must be a positive integer."
}

HTTP Status Codes

Status CodeTypeDescription / Troubleshooting
200 OKSuccessThe request succeeded.
201 CreatedSuccessThe resource (payment, customer, license) was created successfully.
400 Bad RequestClient ErrorMissing required fields, invalid parameter types, or malformed JSON payload.
401 UnauthorizedClient ErrorInvalid, expired, or missing API credentials in the request header.
403 ForbiddenClient ErrorThe credentials are valid but lack the required scope (e.g., trying to write using a read-only key), or request originated from a non-whitelisted IP.
404 Not FoundClient ErrorThe requested resource (e.g., payment ID, customer ID) does not exist.
409 ConflictClient ErrorThe action conflicts with the current state (e.g., trying to create a customer with an email address that already exists).
429 Too Many RequestsClient ErrorYou have hit the rate limit threshold. Please implement request throttling / backoff.
500 Server ErrorServer ErrorAn error occurred on Xtopay's side or with downstream clearing houses. Retry in a few minutes or contact support.

Sample Error Payloads

401 Unauthorized (Invalid Format)

{
  "success": false,
  "message": "Invalid Token Format. Expected base64(clientId:clientSecret)."
}

401 Unauthorized (Invalid Credentials)

{
  "success": false,
  "message": "Invalid API Token or Token Expired"
}

403 Forbidden (Missing Scope)

{
  "success": false,
  "error": "Forbidden. This API key lacks the 'payments:write' scope required to perform this action."
}

404 Not Found (Resource Missing)

{
  "success": false,
  "error": "The requested payment resource 'pay_cl8z2e8z20000g' was not found."
}

429 Too Many Requests (Rate Limited)

{
  "success": false,
  "error": "Rate limit exceeded. You are limited to 100 API requests per second."
}

How is this guide?

Edit this page on GitHub
Last updated on June 6, 2026

On this page