Skip to main content

API Guide#

Table of Contents#

Idempotent Requests#

The Tuna APIs supports idempotency for safely retrying requests without accidentally performing the same operation twice. This is useful when an API call is disrupted in transit, and you do not receive a response. For example, if a request to submit a charge does not respond due to a network connection error, you can retry the request with the same idempotency key, ensuring that this charge request will not be duplicated.

To perform an idempotent request, provide an additional Idempotency-Key in the header of the request. Example:

curl -X 'POST' \
'https://sandbox.tuna-demo.uy/api/Merchant/Register' \
-H 'accept: application/json' \
-H 'x-tuna-account: demo' \
-H 'x-tuna-apptoken: a3823a59-66bb-49e2-95eb-b47c447ec7a7' \
-H 'Idempotency-Key: YzHfUsJHm79qhTZr' \
-H 'Content-Type: application/json'

Tuna's idempotency works by saving the resulting status code and body of the first request submitted for any given idempotency key, whether it succeeded or failed. Subsequent requests with the same key will return the same result, including 500 errors.

An idempotency key is a unique value generated by the client which the server uses to recognize subsequent retries of the same request. Creating unique keys is up to you, but we suggest using V4 UUIDs or another random string with enough entropy to avoid collisions.

Keys are eligible to be removed from the system automatically after they're at least 24 hours old. A new request is generated if a key is reused after removing the original. The idempotency layer compares incoming parameters to those of the original request and errors, unless they're the same, to prevent accidental misuse.

Results are saved only if an API endpoint has started to execute. For example, suppose incoming parameters have failed the validation or have the request conflicted with another executing concurrently. In that case, no idempotent result will be saved because no API endpoint has begun the execution. It is safe to retry these requests.

All POST requests accept idempotency keys. However, sending idempotency keys in GET and DELETE requests has no effect and should be avoided since they are idempotent by definition.

Resources#

  • API Guide: are you looking for a guide for our APIs? Check out the introduction to the API Guide.

  • Payment Integration: do you need to be able to perform secure credit card payments and/or also use other payment methods such as Debit Card, Boleto, PIX, Bitcoin? Checkout how to perform a Payment Integration with our Payment API and Token API.

  • Split Integration: are you looking to set up a marketplace, so your merchants will use split payment solutions in your marketplace? Check out how to perform a Split Integration with our Merchant API.

  • Tuna Codes: do you need to learn about your codes and status? Please, check out the Tuna Codes.

  • Webhooks Notifications: learn more about our notifications in the guide Webhooks Notifications.

  • Sandbox Environment: check out for information about test data and a full description of the Sandbox Environment.

  • Idempotent Requests: do you require idempotent requests? Take a look how to make Idempotent Requests.