Idempotent commands
A command carries an operationId. Sent again, it returns the first outcome and changes nothing; a refused command leaves no record.
On this page
A network can fail after the ledger applied a command and before you read the answer. The operationId lets you ask again safely.
The rules
| You send | The ledger answers |
|---|---|
A new operationId, a valid command | 202: applied once, with its movements |
The same operationId, the same command | 202 with the first outcome; nothing is applied again |
The same operationId, another command | 409 operation_reused |
An operationId whose command was refused | Treated as new: nothing was recorded |
| Any command, over the limit of requests | 429 rate_limited: not processed. Wait the seconds in Retry-After, then send it again with the same operationId |
| Any command, while the service cannot answer | 503 unavailable: send it again with the same operationId |
“The same command” means every field is equal, including occurredAt and the revisions. Key order does not matter.
In practice
- Create the
operationIdwhen you decide to make the change and store it before you send the request. - After a timeout, a lost answer, a 429 or a 503, send the identical command again. If the first one was applied, you get its outcome.
- Read an outcome later with Get an operation. A 404 means the command was never applied.
- Use a new
operationIdfor a new change, and when the first attempt was refused and you change the command, for example with the revisions you read after arevision_conflict.
curl
curl "$RDC_BASE_URL/inventory/v1/operations/90aebca5-208b-47dd-9e6d-c9159d4aab06" \
-H "Authorization: Bearer $RDC_TOKEN" JavaScript
const response = await fetch(`${process.env.RDC_BASE_URL}/inventory/v1/operations/90aebca5-208b-47dd-9e6d-c9159d4aab06`, {
method: 'GET',
headers: {
Authorization: `Bearer ${process.env.RDC_TOKEN}`,
},
});
const result = await response.json(); Python
import os
import requests
response = requests.request(
'GET',
f'{os.environ["RDC_BASE_URL"]}/inventory/v1/operations/90aebca5-208b-47dd-9e6d-c9159d4aab06',
headers={
'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
},
)
result = response.json() PHP
<?php
$curl = curl_init(getenv('RDC_BASE_URL') . '/inventory/v1/operations/90aebca5-208b-47dd-9e6d-c9159d4aab06');
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#
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, $"{Environment.GetEnvironmentVariable("RDC_BASE_URL")}/inventory/v1/operations/90aebca5-208b-47dd-9e6d-c9159d4aab06");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync(); {
"operationId": "90aebca5-208b-47dd-9e6d-c9159d4aab06",
"status": "completed",
"aggregateRevision": 6,
"movementIds": [
"771d53db-5d2c-4a12-b9a6-bb3c86e5eeea"
]
}