---
title: "Idempotency and retries | Developer guide | R&D Copilot"
lang: en
canonical: https://rdcopilot.com/docs/idempotency/
content_version: eba4b823bfede00fc91c5a611e75576a5ff020be94ca2a42c635b431593f9165
contact: https://rdcopilot.com/contact/
---

# Idempotency and retries

Choose an operationId per change, send a request again safely, handle conflicts and retry with pauses.

A change carries an `operationId` that you choose, and sending the same one again returns the first outcome and changes nothing.

## Choosing an operationId

-   Make a UUID for each change you intend, at the moment you decide to make it.
-   Store it before you send the first request. After a crash or a timeout, you then know which change you were making.
-   Use a new `operationId` for a new change, and the same one only to send the same change again.

## The same request twice

Send the reservation, then send it again with the same `operationId` and the same body. The change is applied once. Both answers are the same, so a client that never saw the first one can read it from the second. A value that is shown once is left out of the repeat. When a create or rotate request is sent again, the answer leaves out the `secret` of a subscription, and so does `GET /operations/{operationId}`.

The first send

curl

```bash
curl -X POST "$RDC_BASE_URL/inventory/v1/reservations" \
  -H "Authorization: Bearer $RDC_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "operationId": "3b7e41a8-9c25-4d60-b8f3-1a05e6d27c94",
  "customerOrgId": "a3f1d7c2-64be-4b09-9d58-2c0e7f1a8b34",
  "legalCompanyId": "c8b25e90-1d47-4f3a-a6d2-93e0b51f7c68",
  "occurredAt": "2026-11-20T09:41:05Z",
  "source": {
    "service": "erp",
    "documentId": "4c8a1f72-e6b9-4d35-a0c8-5b2e9d7f1a63",
    "documentType": "sales-order",
    "documentRevision": 1
  },
  "actor": {
    "serviceId": "erp",
    "userId": "9a4e7b10-2c6d-4f38-b5a1-0d3e8c7f6b25"
  },
  "lines": [
    {
      "productId": "7d0c4e19-b3a2-4f65-8e91-2a6f5c8d3b40",
      "locationId": "1b9e6a35-d4c7-4082-b5f3-9e0a7c2d8164",
      "quantity": "24",
      "expectedRevision": 7
    }
  ]
}'
```

JavaScript

```javascript
const response = await fetch(`${process.env.RDC_BASE_URL}/inventory/v1/reservations`, {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.RDC_TOKEN}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "operationId": "3b7e41a8-9c25-4d60-b8f3-1a05e6d27c94",
    "customerOrgId": "a3f1d7c2-64be-4b09-9d58-2c0e7f1a8b34",
    "legalCompanyId": "c8b25e90-1d47-4f3a-a6d2-93e0b51f7c68",
    "occurredAt": "2026-11-20T09:41:05Z",
    "source": {
      "service": "erp",
      "documentId": "4c8a1f72-e6b9-4d35-a0c8-5b2e9d7f1a63",
      "documentType": "sales-order",
      "documentRevision": 1
    },
    "actor": {
      "serviceId": "erp",
      "userId": "9a4e7b10-2c6d-4f38-b5a1-0d3e8c7f6b25"
    },
    "lines": [
      {
        "productId": "7d0c4e19-b3a2-4f65-8e91-2a6f5c8d3b40",
        "locationId": "1b9e6a35-d4c7-4082-b5f3-9e0a7c2d8164",
        "quantity": "24",
        "expectedRevision": 7
      }
    ]
  }),
});
const result = await response.json();
```

Python

```python
import os
import requests

response = requests.request(
    'POST',
    f'{os.environ["RDC_BASE_URL"]}/inventory/v1/reservations',
    headers={
        'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
    },
    json={
        'operationId': '3b7e41a8-9c25-4d60-b8f3-1a05e6d27c94',
        'customerOrgId': 'a3f1d7c2-64be-4b09-9d58-2c0e7f1a8b34',
        'legalCompanyId': 'c8b25e90-1d47-4f3a-a6d2-93e0b51f7c68',
        'occurredAt': '2026-11-20T09:41:05Z',
        'source': {
            'service': 'erp',
            'documentId': '4c8a1f72-e6b9-4d35-a0c8-5b2e9d7f1a63',
            'documentType': 'sales-order',
            'documentRevision': 1,
        },
        'actor': {
            'serviceId': 'erp',
            'userId': '9a4e7b10-2c6d-4f38-b5a1-0d3e8c7f6b25',
        },
        'lines': [
            {
                'productId': '7d0c4e19-b3a2-4f65-8e91-2a6f5c8d3b40',
                'locationId': '1b9e6a35-d4c7-4082-b5f3-9e0a7c2d8164',
                'quantity': '24',
                'expectedRevision': 7,
            },
        ],
    },
)
result = response.json()
```

PHP

```php
<?php

$body = <<<'JSON'
{
  "operationId": "3b7e41a8-9c25-4d60-b8f3-1a05e6d27c94",
  "customerOrgId": "a3f1d7c2-64be-4b09-9d58-2c0e7f1a8b34",
  "legalCompanyId": "c8b25e90-1d47-4f3a-a6d2-93e0b51f7c68",
  "occurredAt": "2026-11-20T09:41:05Z",
  "source": {
    "service": "erp",
    "documentId": "4c8a1f72-e6b9-4d35-a0c8-5b2e9d7f1a63",
    "documentType": "sales-order",
    "documentRevision": 1
  },
  "actor": {
    "serviceId": "erp",
    "userId": "9a4e7b10-2c6d-4f38-b5a1-0d3e8c7f6b25"
  },
  "lines": [
    {
      "productId": "7d0c4e19-b3a2-4f65-8e91-2a6f5c8d3b40",
      "locationId": "1b9e6a35-d4c7-4082-b5f3-9e0a7c2d8164",
      "quantity": "24",
      "expectedRevision": 7
    }
  ]
}
JSON;

$curl = curl_init(getenv('RDC_BASE_URL') . '/inventory/v1/reservations');
curl_setopt_array($curl, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('RDC_TOKEN'),
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => $body,
]);
$result = json_decode(curl_exec($curl), true);
curl_close($curl);
```

C#

```csharp
using System.Net.Http.Headers;

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, $"{Environment.GetEnvironmentVariable("RDC_BASE_URL")}/inventory/v1/reservations");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
request.Content = new StringContent("""
{
  "operationId": "3b7e41a8-9c25-4d60-b8f3-1a05e6d27c94",
  "customerOrgId": "a3f1d7c2-64be-4b09-9d58-2c0e7f1a8b34",
  "legalCompanyId": "c8b25e90-1d47-4f3a-a6d2-93e0b51f7c68",
  "occurredAt": "2026-11-20T09:41:05Z",
  "source": {
    "service": "erp",
    "documentId": "4c8a1f72-e6b9-4d35-a0c8-5b2e9d7f1a63",
    "documentType": "sales-order",
    "documentRevision": 1
  },
  "actor": {
    "serviceId": "erp",
    "userId": "9a4e7b10-2c6d-4f38-b5a1-0d3e8c7f6b25"
  },
  "lines": [
    {
      "productId": "7d0c4e19-b3a2-4f65-8e91-2a6f5c8d3b40",
      "locationId": "1b9e6a35-d4c7-4082-b5f3-9e0a7c2d8164",
      "quantity": "24",
      "expectedRevision": 7
    }
  ]
}
""", System.Text.Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync();
```

Answer 202

```json
{
  "operationId": "3b7e41a8-9c25-4d60-b8f3-1a05e6d27c94",
  "status": "completed",
  "aggregateRevision": 8,
  "movementIds": [
    "f2a95c08-6d41-4e7b-83a0-b7d14e92c5a6"
  ]
}
```

The same request sent again: answer 202

```json
{
  "operationId": "3b7e41a8-9c25-4d60-b8f3-1a05e6d27c94",
  "status": "completed",
  "aggregateRevision": 8,
  "movementIds": [
    "f2a95c08-6d41-4e7b-83a0-b7d14e92c5a6"
  ]
}
```

## The same operationId with another body

An `operationId` belongs to one request. If you send it with a different body, nothing is applied and the answer is 409 `operation_reused`. Choose a new `operationId` for the different change.

The same operationId, with quantity "30" instead of "24"

curl

```bash
curl -X POST "$RDC_BASE_URL/inventory/v1/reservations" \
  -H "Authorization: Bearer $RDC_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "operationId": "3b7e41a8-9c25-4d60-b8f3-1a05e6d27c94",
  "customerOrgId": "a3f1d7c2-64be-4b09-9d58-2c0e7f1a8b34",
  "legalCompanyId": "c8b25e90-1d47-4f3a-a6d2-93e0b51f7c68",
  "occurredAt": "2026-11-20T09:41:05Z",
  "source": {
    "service": "erp",
    "documentId": "4c8a1f72-e6b9-4d35-a0c8-5b2e9d7f1a63",
    "documentType": "sales-order",
    "documentRevision": 1
  },
  "actor": {
    "serviceId": "erp",
    "userId": "9a4e7b10-2c6d-4f38-b5a1-0d3e8c7f6b25"
  },
  "lines": [
    {
      "productId": "7d0c4e19-b3a2-4f65-8e91-2a6f5c8d3b40",
      "locationId": "1b9e6a35-d4c7-4082-b5f3-9e0a7c2d8164",
      "quantity": "30",
      "expectedRevision": 7
    }
  ]
}'
```

JavaScript

```javascript
const response = await fetch(`${process.env.RDC_BASE_URL}/inventory/v1/reservations`, {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.RDC_TOKEN}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "operationId": "3b7e41a8-9c25-4d60-b8f3-1a05e6d27c94",
    "customerOrgId": "a3f1d7c2-64be-4b09-9d58-2c0e7f1a8b34",
    "legalCompanyId": "c8b25e90-1d47-4f3a-a6d2-93e0b51f7c68",
    "occurredAt": "2026-11-20T09:41:05Z",
    "source": {
      "service": "erp",
      "documentId": "4c8a1f72-e6b9-4d35-a0c8-5b2e9d7f1a63",
      "documentType": "sales-order",
      "documentRevision": 1
    },
    "actor": {
      "serviceId": "erp",
      "userId": "9a4e7b10-2c6d-4f38-b5a1-0d3e8c7f6b25"
    },
    "lines": [
      {
        "productId": "7d0c4e19-b3a2-4f65-8e91-2a6f5c8d3b40",
        "locationId": "1b9e6a35-d4c7-4082-b5f3-9e0a7c2d8164",
        "quantity": "30",
        "expectedRevision": 7
      }
    ]
  }),
});
const result = await response.json();
```

Python

```python
import os
import requests

response = requests.request(
    'POST',
    f'{os.environ["RDC_BASE_URL"]}/inventory/v1/reservations',
    headers={
        'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
    },
    json={
        'operationId': '3b7e41a8-9c25-4d60-b8f3-1a05e6d27c94',
        'customerOrgId': 'a3f1d7c2-64be-4b09-9d58-2c0e7f1a8b34',
        'legalCompanyId': 'c8b25e90-1d47-4f3a-a6d2-93e0b51f7c68',
        'occurredAt': '2026-11-20T09:41:05Z',
        'source': {
            'service': 'erp',
            'documentId': '4c8a1f72-e6b9-4d35-a0c8-5b2e9d7f1a63',
            'documentType': 'sales-order',
            'documentRevision': 1,
        },
        'actor': {
            'serviceId': 'erp',
            'userId': '9a4e7b10-2c6d-4f38-b5a1-0d3e8c7f6b25',
        },
        'lines': [
            {
                'productId': '7d0c4e19-b3a2-4f65-8e91-2a6f5c8d3b40',
                'locationId': '1b9e6a35-d4c7-4082-b5f3-9e0a7c2d8164',
                'quantity': '30',
                'expectedRevision': 7,
            },
        ],
    },
)
result = response.json()
```

PHP

```php
<?php

$body = <<<'JSON'
{
  "operationId": "3b7e41a8-9c25-4d60-b8f3-1a05e6d27c94",
  "customerOrgId": "a3f1d7c2-64be-4b09-9d58-2c0e7f1a8b34",
  "legalCompanyId": "c8b25e90-1d47-4f3a-a6d2-93e0b51f7c68",
  "occurredAt": "2026-11-20T09:41:05Z",
  "source": {
    "service": "erp",
    "documentId": "4c8a1f72-e6b9-4d35-a0c8-5b2e9d7f1a63",
    "documentType": "sales-order",
    "documentRevision": 1
  },
  "actor": {
    "serviceId": "erp",
    "userId": "9a4e7b10-2c6d-4f38-b5a1-0d3e8c7f6b25"
  },
  "lines": [
    {
      "productId": "7d0c4e19-b3a2-4f65-8e91-2a6f5c8d3b40",
      "locationId": "1b9e6a35-d4c7-4082-b5f3-9e0a7c2d8164",
      "quantity": "30",
      "expectedRevision": 7
    }
  ]
}
JSON;

$curl = curl_init(getenv('RDC_BASE_URL') . '/inventory/v1/reservations');
curl_setopt_array($curl, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('RDC_TOKEN'),
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => $body,
]);
$result = json_decode(curl_exec($curl), true);
curl_close($curl);
```

C#

```csharp
using System.Net.Http.Headers;

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, $"{Environment.GetEnvironmentVariable("RDC_BASE_URL")}/inventory/v1/reservations");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
request.Content = new StringContent("""
{
  "operationId": "3b7e41a8-9c25-4d60-b8f3-1a05e6d27c94",
  "customerOrgId": "a3f1d7c2-64be-4b09-9d58-2c0e7f1a8b34",
  "legalCompanyId": "c8b25e90-1d47-4f3a-a6d2-93e0b51f7c68",
  "occurredAt": "2026-11-20T09:41:05Z",
  "source": {
    "service": "erp",
    "documentId": "4c8a1f72-e6b9-4d35-a0c8-5b2e9d7f1a63",
    "documentType": "sales-order",
    "documentRevision": 1
  },
  "actor": {
    "serviceId": "erp",
    "userId": "9a4e7b10-2c6d-4f38-b5a1-0d3e8c7f6b25"
  },
  "lines": [
    {
      "productId": "7d0c4e19-b3a2-4f65-8e91-2a6f5c8d3b40",
      "locationId": "1b9e6a35-d4c7-4082-b5f3-9e0a7c2d8164",
      "quantity": "30",
      "expectedRevision": 7
    }
  ]
}
""", System.Text.Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync();
```

Answer 409

```json
{
  "code": "operation_reused",
  "message": "This operationId was sent before with another body.",
  "requestId": "req_6Fy9cJ2sQa4M"
}
```

## expectedRevision

A record has a revision that grows with every change. To change an existing record, send the revision you read as `expectedRevision`. If the record has moved on since, nothing is applied and the answer is 409 `revision_conflict`.

A second client sends the revision it read earlier, 6

curl

```bash
curl -X POST "$RDC_BASE_URL/inventory/v1/reservations" \
  -H "Authorization: Bearer $RDC_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "operationId": "8e5d2a96-0f13-4b7c-9a64-d1c38b05e7f2",
  "customerOrgId": "a3f1d7c2-64be-4b09-9d58-2c0e7f1a8b34",
  "legalCompanyId": "c8b25e90-1d47-4f3a-a6d2-93e0b51f7c68",
  "occurredAt": "2026-11-20T09:41:05Z",
  "source": {
    "service": "erp",
    "documentId": "4c8a1f72-e6b9-4d35-a0c8-5b2e9d7f1a63",
    "documentType": "sales-order",
    "documentRevision": 1
  },
  "actor": {
    "serviceId": "erp",
    "userId": "9a4e7b10-2c6d-4f38-b5a1-0d3e8c7f6b25"
  },
  "lines": [
    {
      "productId": "7d0c4e19-b3a2-4f65-8e91-2a6f5c8d3b40",
      "locationId": "1b9e6a35-d4c7-4082-b5f3-9e0a7c2d8164",
      "quantity": "6",
      "expectedRevision": 6
    }
  ]
}'
```

JavaScript

```javascript
const response = await fetch(`${process.env.RDC_BASE_URL}/inventory/v1/reservations`, {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.RDC_TOKEN}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "operationId": "8e5d2a96-0f13-4b7c-9a64-d1c38b05e7f2",
    "customerOrgId": "a3f1d7c2-64be-4b09-9d58-2c0e7f1a8b34",
    "legalCompanyId": "c8b25e90-1d47-4f3a-a6d2-93e0b51f7c68",
    "occurredAt": "2026-11-20T09:41:05Z",
    "source": {
      "service": "erp",
      "documentId": "4c8a1f72-e6b9-4d35-a0c8-5b2e9d7f1a63",
      "documentType": "sales-order",
      "documentRevision": 1
    },
    "actor": {
      "serviceId": "erp",
      "userId": "9a4e7b10-2c6d-4f38-b5a1-0d3e8c7f6b25"
    },
    "lines": [
      {
        "productId": "7d0c4e19-b3a2-4f65-8e91-2a6f5c8d3b40",
        "locationId": "1b9e6a35-d4c7-4082-b5f3-9e0a7c2d8164",
        "quantity": "6",
        "expectedRevision": 6
      }
    ]
  }),
});
const result = await response.json();
```

Python

```python
import os
import requests

response = requests.request(
    'POST',
    f'{os.environ["RDC_BASE_URL"]}/inventory/v1/reservations',
    headers={
        'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
    },
    json={
        'operationId': '8e5d2a96-0f13-4b7c-9a64-d1c38b05e7f2',
        'customerOrgId': 'a3f1d7c2-64be-4b09-9d58-2c0e7f1a8b34',
        'legalCompanyId': 'c8b25e90-1d47-4f3a-a6d2-93e0b51f7c68',
        'occurredAt': '2026-11-20T09:41:05Z',
        'source': {
            'service': 'erp',
            'documentId': '4c8a1f72-e6b9-4d35-a0c8-5b2e9d7f1a63',
            'documentType': 'sales-order',
            'documentRevision': 1,
        },
        'actor': {
            'serviceId': 'erp',
            'userId': '9a4e7b10-2c6d-4f38-b5a1-0d3e8c7f6b25',
        },
        'lines': [
            {
                'productId': '7d0c4e19-b3a2-4f65-8e91-2a6f5c8d3b40',
                'locationId': '1b9e6a35-d4c7-4082-b5f3-9e0a7c2d8164',
                'quantity': '6',
                'expectedRevision': 6,
            },
        ],
    },
)
result = response.json()
```

PHP

```php
<?php

$body = <<<'JSON'
{
  "operationId": "8e5d2a96-0f13-4b7c-9a64-d1c38b05e7f2",
  "customerOrgId": "a3f1d7c2-64be-4b09-9d58-2c0e7f1a8b34",
  "legalCompanyId": "c8b25e90-1d47-4f3a-a6d2-93e0b51f7c68",
  "occurredAt": "2026-11-20T09:41:05Z",
  "source": {
    "service": "erp",
    "documentId": "4c8a1f72-e6b9-4d35-a0c8-5b2e9d7f1a63",
    "documentType": "sales-order",
    "documentRevision": 1
  },
  "actor": {
    "serviceId": "erp",
    "userId": "9a4e7b10-2c6d-4f38-b5a1-0d3e8c7f6b25"
  },
  "lines": [
    {
      "productId": "7d0c4e19-b3a2-4f65-8e91-2a6f5c8d3b40",
      "locationId": "1b9e6a35-d4c7-4082-b5f3-9e0a7c2d8164",
      "quantity": "6",
      "expectedRevision": 6
    }
  ]
}
JSON;

$curl = curl_init(getenv('RDC_BASE_URL') . '/inventory/v1/reservations');
curl_setopt_array($curl, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('RDC_TOKEN'),
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => $body,
]);
$result = json_decode(curl_exec($curl), true);
curl_close($curl);
```

C#

```csharp
using System.Net.Http.Headers;

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, $"{Environment.GetEnvironmentVariable("RDC_BASE_URL")}/inventory/v1/reservations");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
request.Content = new StringContent("""
{
  "operationId": "8e5d2a96-0f13-4b7c-9a64-d1c38b05e7f2",
  "customerOrgId": "a3f1d7c2-64be-4b09-9d58-2c0e7f1a8b34",
  "legalCompanyId": "c8b25e90-1d47-4f3a-a6d2-93e0b51f7c68",
  "occurredAt": "2026-11-20T09:41:05Z",
  "source": {
    "service": "erp",
    "documentId": "4c8a1f72-e6b9-4d35-a0c8-5b2e9d7f1a63",
    "documentType": "sales-order",
    "documentRevision": 1
  },
  "actor": {
    "serviceId": "erp",
    "userId": "9a4e7b10-2c6d-4f38-b5a1-0d3e8c7f6b25"
  },
  "lines": [
    {
      "productId": "7d0c4e19-b3a2-4f65-8e91-2a6f5c8d3b40",
      "locationId": "1b9e6a35-d4c7-4082-b5f3-9e0a7c2d8164",
      "quantity": "6",
      "expectedRevision": 6
    }
  ]
}
""", System.Text.Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync();
```

Answer 409

```json
{
  "code": "revision_conflict",
  "message": "The balance changed after revision 6.",
  "requestId": "req_3Hd7vB1pLw5R"
}
```

1.  Read the record again with a read such as `GET /availability`.
2.  Decide whether the change still applies.
3.  Send it with the new revision and a new `operationId`.

## When to retry

| Answer | Send again? | How |
| --- | --- | --- |
| A network failure or a timeout | Yes | With the same `operationId`, after a pause. If you can, read the operation first. |
| 429 | Yes | With the same `operationId`, after the seconds in `Retry-After`. |
| 5xx | Yes | With the same `operationId`, after a pause. |
| 401 | Yes | With a new token and the same `operationId`. |
| 409 `revision_conflict` | Not as it is | Read the record again, then send a new operation. |
| 409 `operation_reused` | No | Choose a new `operationId` if the change is a new one. |
| Any other 4xx | No | Fix the request first. The answer will be the same. |

## Pauses between retries

Wait longer after each failed try, up to a ceiling. When the answer carries `Retry-After`, wait that many seconds instead: it wins over your own pauses.

A retry that keeps the same operationId

```javascript
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

export async function send(url, options, tries = 6) {
  for (let attempt = 0; attempt < tries; attempt += 1) {
    let response;
    try {
      response = await fetch(url, options);
    } catch {
      // A network failure: send the same request again.
    }
    if (response && response.status !== 429 && response.status < 500) return response;
    const asked = Number(response?.headers.get('retry-after'));
    // Start at one second, double each time, and stop doubling at one minute.
    const own = Math.min(1000 * 2 ** attempt, 60000);
    await sleep(asked > 0 ? asked * 1000 : own);
  }
  throw new Error('The request did not go through. Read the operation before you send it again.');
}
```

## When you do not know what happened

If a request ended without an answer, ask for the operation by its `operationId`. A 404 says the change never arrived, so send it. A 200 is the outcome: `accepted`, `completed` or `rejected`.

Read the operation

curl

```bash
curl "$RDC_BASE_URL/inventory/v1/operations/3b7e41a8-9c25-4d60-b8f3-1a05e6d27c94" \
  -H "Authorization: Bearer $RDC_TOKEN"
```

JavaScript

```javascript
const response = await fetch(`${process.env.RDC_BASE_URL}/inventory/v1/operations/3b7e41a8-9c25-4d60-b8f3-1a05e6d27c94`, {
  method: 'GET',
  headers: {
    Authorization: `Bearer ${process.env.RDC_TOKEN}`,
  },
});
const result = await response.json();
```

Python

```python
import os
import requests

response = requests.request(
    'GET',
    f'{os.environ["RDC_BASE_URL"]}/inventory/v1/operations/3b7e41a8-9c25-4d60-b8f3-1a05e6d27c94',
    headers={
        'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
    },
)
result = response.json()
```

PHP

```php
<?php

$curl = curl_init(getenv('RDC_BASE_URL') . '/inventory/v1/operations/3b7e41a8-9c25-4d60-b8f3-1a05e6d27c94');
curl_setopt_array($curl, [
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('RDC_TOKEN'),
    ],
]);
$result = json_decode(curl_exec($curl), true);
curl_close($curl);
```

C#

```csharp
using System.Net.Http.Headers;

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, $"{Environment.GetEnvironmentVariable("RDC_BASE_URL")}/inventory/v1/operations/3b7e41a8-9c25-4d60-b8f3-1a05e6d27c94");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync();
```

Answer 200

```json
{
  "operationId": "3b7e41a8-9c25-4d60-b8f3-1a05e6d27c94",
  "status": "completed",
  "aggregateRevision": 8,
  "movementIds": [
    "f2a95c08-6d41-4e7b-83a0-b7d14e92c5a6"
  ]
}
```

A change that never arrived has no operation, so a 404 on the lookup means: send the change. A rejected operation has one: the lookup answers 200 with the status `rejected`.

## Related pages

-   [Errors](https://rdcopilot.com/docs/errors/): the codes of a refused request.
-   [Limits](https://rdcopilot.com/docs/limits/): the 429 answer.

[Previous · **Errors**](https://rdcopilot.com/docs/errors/) [Next · **Pagination**](https://rdcopilot.com/docs/pagination/)

---

R&D Copilot · Made in EU · Contact: https://rdcopilot.com/contact/
