Skip to content
HisarPay

API conventions

Idempotency

After a network error or a timeout you cannot know whether a request was processed. An idempotency key lets you send the same request again safely, so the operation is applied only once.

How it works

Add an Idempotency-Key header (up to 255 characters) to any POST under /v1. HisarPay stores the first successful response for 24 hours:

  • A repeat with the same key and the same body does not run the operation again; the stored response is returned as is, with an Idempotent-Replayed: true header.
  • Keys are scoped to the account and the mode (live or test).
  • Error responses (4xx and 5xx) are not stored: an error created nothing, so retrying with the same key is safe and the request is evaluated again as things stand then (for example after a top-up or once a limit resets).
curl -X POST https://hisarpay.com/v1/invoices \
  -H "Authorization: Bearer $HISARPAY_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: checkout-7f3a9c2e" \
  -d '{
    "price_usd": "49.90",
    "order_id": "order_1001"
  }'
Replayed request
HTTP/1.1 201 Created
Idempotent-Replayed: true
X-Request-Id: req_2d9e8f7a6b5c4d3e2f1a0b9c8d7e6f5a

409 responses

CodeWhenWhat to do
idempotency_conflictThe same key was used with a different body or endpoint.Generate a new key for each distinct operation.
request_in_progressThe first request with this key is still running.Wait Retry-After seconds and retry with the same key; you get the first request’s result.
409 request_in_progress
HTTP/1.1 409 Conflict
Retry-After: 4

{
  "error": {
    "code": "request_in_progress",
    "message": "a request with this Idempotency-Key is still in progress",
    "request_id": "req_6a5b4c3d2e1f0a9b8c7d6e5f4a3b2c1d"
  }
}

Permanent uniqueness fields

Some resources have their own uniqueness field that is not limited to 24 hours:

ResourceFieldBehaviour
Invoiceorder_idThe existing invoice is returned with 200.
Withdrawalidempotency_keyRequired in the body. Same details return the existing withdrawal; different details get 409 idempotency_conflict.

Choosing keys

  • Create one key per logical operation and reuse it for every attempt of that operation. It can be a random UUID v4 or a value derived from your own record (for example checkout-<cart>).
  • Keys derived from your own records catch repeats even after your process restarts.
  • The official SDKs generate a key for every POST and reuse it on their own retries; they also wait out request_in_progress and try again.