Skip to content
Wire Ghdocs

Idempotent Requests

Retry a request safely after a timeout or a dropped connection, without creating a second charge or refund.

Why it matters

Networks fail. Your server may send a charge and lose the connection before the response arrives. You cannot tell whether the charge was made, and sending it again could charge your customer twice.

An idempotency key solves this. Send the same key with the retry, and Wire Gh returns the result of the first request instead of running it again.

How to use it

Add an Idempotency-Key header to any POST request. Use a value that is unique to the action, such as your order number plus an attempt number.

curl https://api.wiregh.com/charge \
-H "Authorization: Bearer YOUR_SECRET_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: order-1042-attempt-1" \
-d '{ "email": "customer@email.com", "amount": 5000, "mobile_money": { "phone": "0551234987", "provider": "mtn" } }' \
-X POST
  • Keys are 8 to 80 characters long, using letters, digits, underscores, hyphens, colons or full stops.
  • Keys are remembered for 24 hours, separately for test and live mode.
  • A replayed response has the header Idempotent-Replayed: true.

What happens on a retry

You sendWe do
The same key and the same body, after the first request finishedReturn the first response again. Nothing new happens.
The same key while the first request is still runningReturn 409 with code idempotency_conflict. Wait a moment and retry.
The same key with a different bodyReturn 409 with code idempotency_conflict. Use a new key for a new action.
The same key after the first request got a 500 or 503 errorRun the request again, because the first one did not complete.
Unique references help too

Sending your own reference gives a second layer of protection: a reference can only be used once, so a duplicate request fails with duplicate_reference instead of creating a second transaction.