# Idempotent Transaction Requests

PayEngine supports idempotency for safely retrying transaction requests without accidentally performing a duplicate execution of the same requests.\
\
Idempotency is supported with [Auth](https://docs.payengine.co/payengine-api-v2.5/transactions/authorization), [Sale](https://docs.payengine.co/payengine-api-v2.5/transactions/sale), [Capture](https://docs.payengine.co/payengine-api-v2.5/transactions/capture), [Refund](https://docs.payengine.co/payengine-api-v2.5/transactions/refund) and [Void](https://docs.payengine.co/payengine-api-v2.5/transactions/void) APIs

To mark an idempotent request, provide an additional HTTP header `request-key` in supported APIs. PayEngine saves the response of the first request regardless of its failure or success; subsequent requests with the same `request-key` will produce the same response. This is very useful if a request times out and client needs to retrieve the response of the previous request.

A `request-key` is a unique value generated by client and we recommend to use UUIDs or any unique key with enough entropy to avoid collision. PayEngine system will clean up the keys after 24 hours.

{% hint style="danger" %}
Results are stored including failed respoenses. This feature is to support safe retries and it is client's responsibility to maintain uniqueness of the `request-key`
{% endhint %}

### Sample Sale Request

Subsequent calls of this request will always yield the same results as the firtst call until the `request-key` expires (24 hours)

```shell
curl --location --request POST 'https://<PayEngine Host>/api/payment/sale' \
--header 'Authorization: Basic <Your Private Key>' \
--header 'Content-Type: application/json' \
--header 'request-key : <Unique Reqeust Key>' \
--data-raw '{
    "merchant_id": "<Your Merchant ID>",
    "data": {
        "transaction_amount": "10.00",
        "card_token": "<Your Card Token>",
    }
}'
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.payengine.co/payengine-api-v2.5/transactions/idempotent-transaction-requests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
