Skip to main content

Idempotency

Plug’s API supports idempotency keys to avoid duplicate request processing in case of multiple repetitions of the same operation. This feature is useful when a request fails due to a communication error and you have not received a conclusive answer. If you receive a connection error on a given call you can simply reattempt a new request using the same idempotency key, this way our API can guarantee that the second call will not be processed in duplicity.

To make calls with idempotency just send an additional header X-Idempotency-Key.

  curl --location --request POST 'https://api.plugpagamentos.com/v1/charges' \
--header 'X-Client-Id: <YOUR_CLIENT_ID>' \
--header 'X-Api-Key: <YOUR_PUBLIC_KEY>' \
--header 'Content-Type: application/json' \
--header 'X-Idempotency-Key: <IDEMPOTENCY_KEY>'

Our service saves the Idempotency-Key and the Body sent in your request, given a request, regardless of failure or success in the processing. We save the processing result, and when a second request is made with the same idempotency key our service returns the same content returned on the first call, including the errors.

caution

The idempotency key needs to be unique, generated client-side, and it is necessary to ensure on your side that the keys do not collide. We suggest using V4 UUID or a similar algorithm that guarantees unique hashes.

The result is only stored on the Plug’s side if processing of the first request has been started. If there is a failure in the validation of the fields, or if another key is being processed simultaneously, no idempotency response is given.

All POST calls accept idempotent key.