Skip to content
HisarPay

API conventions

Errors

Every failed request returns an error object with the same shape. Make decisions in code based on the HTTP status and, above all, the machine-readable code field.

The error object

409 Conflict
HTTP/1.1 409 Conflict
Content-Type: application/json
X-Request-Id: req_8c1f0b2a9d3e4f5a6b7c8d9e0f1a2b3c

{
  "error": {
    "code": "not_cancellable",
    "message": "only pending invoices with nothing received can be cancelled",
    "request_id": "req_8c1f0b2a9d3e4f5a6b7c8d9e0f1a2b3c"
  }
}
  • code is stable; build your logic on it.
  • message is written for humans and may change. For validation errors it includes the path of the field (for example price_usd: must be a USD amount like "49.90").
  • request_id matches the X-Request-Id header. Include it when you contact support.

Error codes

CodeHTTPMeaning
validation_error400A field is missing or invalid; the message names it.
amount_too_small400The amount is below the invoice or withdrawal minimum.
unauthorized401The key is missing, malformed or revoked.
forbidden403The key lacks the scope, the IP is not allowlisted, or the action is closed to this key.
live_key403The action needs a test key (for example simulation).
test_key403The action needs a live key (for example endpoint management).
account_not_active403The account is not approved yet, or it is suspended.
address_not_trusted403The withdrawal address is not saved and trusted.
address_not_saved403Withdrawals are restricted to saved addresses; this one is not saved or still within its 24-hour wait.
withdrawals_locked403Withdrawals are locked for a while after a security change, or frozen for the account.
limit_exceeded403The daily withdrawal limit would be exceeded.
not_found404No such record in this account and mode.
conflict409The record’s current state does not allow the action.
not_cancellable409The invoice has received a payment and cannot be cancelled.
insufficient_balance409The available balance does not cover the amount and fee.
idempotency_conflict409The same idempotency key was used with a different request.
request_in_progress409The first request with this idempotency key is still running; wait Retry-After seconds.retryable
rate_limited429Rate limit exceeded; wait Retry-After seconds.retryable
internal_error500Unexpected error on our side; retry with the same idempotency key.retryable
service_unavailable503A short interruption; wait Retry-After seconds and retry with the same idempotency key.retryable
rate_unavailable503No fresh exchange rate for a moment; retry shortly.retryable

When to retry

429, 5xx and request_in_progress are temporary: retry with exponential backoff and jitter, using the same Idempotency-Key. If a Retry-After header is present, wait at least that long. For other 4xx errors, repeating the request does not change the outcome; fix the request first.

The official SDKs retry temporary errors on their own and raise a separate error class for each code:

import { ConflictError, HisarPayError, ValidationError } from '@hisarpay/node';

try {
  await hisarpay.invoices.cancel(id);
} catch (err) {
  if (err instanceof ConflictError && err.code === 'not_cancellable') {
    // already (partly) paid: keep the order open
  } else if (err instanceof ValidationError) {
    console.error(err.message);
  } else if (err instanceof HisarPayError) {
    console.error(err.status, err.code, err.requestId);
  } else {
    throw err;
  }
}