Idempotency-Key header and a retry returns the first answer instead of doing the work twice.
Which requests
Creating a charge, a refund, a payout, a transfer, an invoice, a payment link or a subscription. The header is optional. Without it nothing changes.The rules
- The key is 8 to 64 characters: letters, numbers, dots, dashes, underscores and colons. Use a new random value, or one built from your own id such as
order_1001_attempt_1. - First request: runs normally. Its answer is saved for 24 hours.
- Same key, same request: returns the saved answer with the header
Idempotent-Replayed: true. Nothing is created again. - Same key, different request: refused with
422. A key stands for one request. Use a new key for a different one. - Same key while the first is still running: refused with
409. Wait a moment and try again. - A request that failed is forgotten, so retrying with the same key runs it again.
- Keys belong to the account (and business) that sent them. Two accounts can use the same key without affecting each other.
Retrying
- Send the request with a key and save the key with your order.
- If you get a timeout or a
5xx, send the same request with the same key. - If you get
409, wait a second and retry. - If you get
422, you reused a key for a different request. Fix your code; do not just retry.