> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mygigsters.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Idempotency

> Retry a request safely without creating a second payment, refund, or payout.

Network failures happen. If a request times out, you can't tell whether it was processed. An idempotency key lets you retry without the risk of doing the same thing twice.

## Send an idempotency key

Add an `idempotency-Key` header to any `POST` or `PUT` request. The header is optional. Use a unique value for each operation, such as a UUID.

```bash cURL theme={null}
curl -X POST https://qa-payments.mygigsters.com.au/api/v1/customer/create-intent/{customer_id} \
  -u "YOUR_UUID:YOUR_SECRET" \
  -H "idempotency-Key: 7b80a149-16ff-4dc8-8eb1-f1f4cfd0d577" \
  -H "X-API-Version: 1.2" \
  -H "Content-Type: application/json" \
  -d '{ "amount": 150.00, "job_id": "job_8842", "auto_capture": false }'
```

```javascript Node.js theme={null}
const response = await fetch("https://qa-payments.mygigsters.com.au/api/v1/customer/create-intent/{customer_id}", {
  method: "POST",
  headers: {
    Authorization: "Basic " + Buffer.from("YOUR_UUID:YOUR_SECRET").toString("base64"),
    "idempotency-Key": "7b80a149-16ff-4dc8-8eb1-f1f4cfd0d577",
    "X-API-Version": "1.2",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "amount": 150.0,
    "job_id": "job_8842",
    "auto_capture": false
  }),
});

const data = await response.json();
console.log(data);
```

```python Python theme={null}
import requests

response = requests.post(
    "https://qa-payments.mygigsters.com.au/api/v1/customer/create-intent/{customer_id}",
    auth=("YOUR_UUID", "YOUR_SECRET"),
    headers={
        "idempotency-Key": "7b80a149-16ff-4dc8-8eb1-f1f4cfd0d577",
        "X-API-Version": "1.2",
    },
    json={
        "amount": 150.0,
        "job_id": "job_8842",
        "auto_capture": False,
    },
)

print(response.json())
```

```ruby Ruby theme={null}
require "net/http"
require "json"
require "uri"

uri = URI("https://qa-payments.mygigsters.com.au/api/v1/customer/create-intent/{customer_id}")
request = Net::HTTP::Post.new(uri)
request.basic_auth("YOUR_UUID", "YOUR_SECRET")
request["idempotency-Key"] = "7b80a149-16ff-4dc8-8eb1-f1f4cfd0d577"
request["X-API-Version"] = "1.2"
request["Content-Type"] = "application/json"
request.body = <<~JSON
  {
    "amount": 150.0,
    "job_id": "job_8842",
    "auto_capture": false
  }
JSON

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
  http.request(request)
end

puts JSON.parse(response.body)
```

```php PHP theme={null}
<?php

$ch = curl_init("https://qa-payments.mygigsters.com.au/api/v1/customer/create-intent/{customer_id}");

curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_USERPWD => "YOUR_UUID:YOUR_SECRET",
    CURLOPT_HTTPHEADER => [
        "idempotency-Key: 7b80a149-16ff-4dc8-8eb1-f1f4cfd0d577",
        "X-API-Version: 1.2",
        "Content-Type: application/json",
    ],
    CURLOPT_POSTFIELDS => <<<'JSON'
{
  "amount": 150.0,
  "job_id": "job_8842",
  "auto_capture": false
}
JSON,
]);

$response = curl_exec($ch);
curl_close($ch);

print_r(json_decode($response, true));
```

```java Java theme={null}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Base64;

public class Example {
    public static void main(String[] args) throws Exception {
        String credentials = Base64.getEncoder()
            .encodeToString("YOUR_UUID:YOUR_SECRET".getBytes());

        String body = String.join("\n",
            "{",
            "  \"amount\": 150.0,",
            "  \"job_id\": \"job_8842\",",
            "  \"auto_capture\": false",
            "}"
        );

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://qa-payments.mygigsters.com.au/api/v1/customer/create-intent/{customer_id}"))
            .header("Authorization", "Basic " + credentials)
            .header("idempotency-Key", "7b80a149-16ff-4dc8-8eb1-f1f4cfd0d577")
            .header("X-API-Version", "1.2")
            .header("Content-Type", "application/json")
            .method("POST", HttpRequest.BodyPublishers.ofString(body))
            .build();

        HttpResponse<String> response = HttpClient.newHttpClient()
            .send(request, HttpResponse.BodyHandlers.ofString());

        System.out.println(response.body());
    }
}
```

```go Go theme={null}
package main

import (
	"fmt"
	"io"
	"net/http"
	"strings"
)

func main() {
	body := strings.NewReader(`{
  "amount": 150.0,
  "job_id": "job_8842",
  "auto_capture": false
}`)

	req, err := http.NewRequest("POST", "https://qa-payments.mygigsters.com.au/api/v1/customer/create-intent/{customer_id}", body)
	if err != nil {
		panic(err)
	}
	req.SetBasicAuth("YOUR_UUID", "YOUR_SECRET")
	req.Header.Set("idempotency-Key", "7b80a149-16ff-4dc8-8eb1-f1f4cfd0d577")
	req.Header.Set("X-API-Version", "1.2")
	req.Header.Set("Content-Type", "application/json")

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()

	data, _ := io.ReadAll(res.Body)
	fmt.Println(string(data))
}
```

```csharp .NET theme={null}
using System.Net.Http.Headers;
using System.Text;

using var client = new HttpClient();

var request = new HttpRequestMessage(HttpMethod.Post, "https://qa-payments.mygigsters.com.au/api/v1/customer/create-intent/{customer_id}");
request.Headers.Authorization = new AuthenticationHeaderValue(
    "Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes("YOUR_UUID:YOUR_SECRET")));
request.Headers.Add("idempotency-Key", "7b80a149-16ff-4dc8-8eb1-f1f4cfd0d577");
request.Headers.Add("X-API-Version", "1.2");
request.Content = new StringContent(@"{
  ""amount"": 150.0,
  ""job_id"": ""job_8842"",
  ""auto_capture"": false
}", Encoding.UTF8, "application/json");

var response = await client.SendAsync(request);
Console.WriteLine(await response.Content.ReadAsStringAsync());
```

## How it works

* If you send the same key again within 24 hours, you get the saved response from the first request. The operation isn't run a second time.
* If you reuse a key with a different request body, the request fails with `409` and the error code `idempotency_conflict`. Send the identical body to replay the original response, or use a new key for a new operation.

## When to use it

Send an idempotency key whenever you retry a request that changes state, such as creating a charge, refund, or payout. Use the same key for every retry of the same operation.

For `429` and `5xx` responses, retry with exponential backoff. See [Errors and conventions](https://docs.mygigsters.com/api-reference/errors-and-conventions.md#handling-errors).

> [!NOTE]
>
> Idempotency keys are available on API version 1.2.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.