---
title: "Idempotență și reîncercări | Ghidul dezvoltatorului | R&D Copilot"
lang: ro
canonical: https://rdcopilot.com/ro/docs/idempotency/
content_version: d36ae8c9c345c18d5b764a72934b361091b63c5b41f174bab11903811d57bc7b
contact: https://rdcopilot.com/ro/contact/
---

# Idempotență și reîncercări

Alegi un operationId pentru fiecare modificare, trimiți din nou o cerere în siguranță, tratezi conflictele și reîncerci cu pauze.

Fiecare modificare are un `operationId` pe care îl alegi tu; dacă îl trimiți din nou, primești primul rezultat și nu se schimbă nimic.

## Alegerea unui operationId

-   Generează un UUID pentru fiecare modificare pe care o intenționezi, în clipa în care hotărăști să o faci.
-   Salvează-l înainte să trimiți prima cerere. După o cădere sau o depășire a timpului de așteptare, știi astfel ce modificare făceai.
-   Folosește un `operationId` nou pentru o modificare nouă și pe același doar ca să trimiți din nou aceeași modificare.

## Aceeași cerere de două ori

Trimite rezervarea, apoi trimite-o din nou cu același `operationId` și același corp. Modificarea se aplică o singură dată. Ambele răspunsuri sunt la fel, deci un client care nu l-a văzut pe primul îl poate citi din al doilea. O valoare afișată o singură dată lipsește din repetare: răspunsul la o cerere de creare sau de rotire trimisă din nou și `GET /operations/{operationId}` omit câmpul `secret` al unui abonament.

Prima trimitere

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();
```

Răspuns 202

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

Aceeași cerere trimisă din nou: răspuns 202

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

## Același operationId cu alt corp

Un `operationId` aparține unei singure cereri. Dacă îl trimiți cu alt corp, nu se aplică nimic, iar răspunsul este 409 `operation_reused`. Alege un `operationId` nou pentru modificarea diferită.

Același operationId, cu cantitatea "30" în loc de "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();
```

Răspuns 409

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

## expectedRevision

O înregistrare are o revizie care crește la fiecare modificare. Ca să modifici o înregistrare existentă, trimite revizia pe care ai citit-o ca `expectedRevision`. Dacă înregistrarea s-a schimbat între timp, nu se aplică nimic, iar răspunsul este 409 `revision_conflict`.

Un al doilea client trimite revizia citită mai devreme, 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();
```

Răspuns 409

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

1.  Citește din nou înregistrarea, cu o citire precum `GET /availability`.
2.  Hotărăște dacă modificarea se mai aplică.
3.  Trimite-o cu revizia nouă și cu un `operationId` nou.

## Când reîncerci

| Răspuns | Trimiți din nou? | Cum |
| --- | --- | --- |
| O cădere a rețelei sau o depășire a timpului de așteptare | Da | Cu același `operationId`, după o pauză. Dacă poți, citește mai întâi operația. |
| 429 | Da | Cu același `operationId`, după secundele din `Retry-After`. |
| 5xx | Da | Cu același `operationId`, după o pauză. |
| 401 | Da | Cu un token nou și cu același `operationId`. |
| 409 `revision_conflict` | Nu așa cum este | Citește din nou înregistrarea, apoi trimite o operație nouă. |
| 409 `operation_reused` | Nu | Alege un `operationId` nou dacă modificarea este una nouă. |
| Orice alt 4xx | Nu | Corectează mai întâi cererea. Răspunsul va fi același. |

## Pauzele dintre reîncercări

Așteaptă mai mult după fiecare încercare eșuată, până la un plafon. Când răspunsul are antetul `Retry-After`, așteaptă atâtea secunde: are prioritate față de pauzele tale.

O reîncercare care păstrează același 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.');
}
```

## Când nu știi ce s-a întâmplat

Dacă o cerere s-a încheiat fără răspuns, cere operația după `operationId`. Un 404 spune că modificarea nu a ajuns, deci trimite-o. Un 200 este rezultatul: `accepted`, `completed` sau `rejected`.

Citește operația

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();
```

Răspuns 200

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

O modificare care nu a ajuns nu are operație, deci un 404 la citire înseamnă: trimite modificarea. O operație refuzată are una: citirea răspunde cu 200 și cu starea `rejected`.

## Pagini înrudite

-   [Erori](https://rdcopilot.com/ro/docs/errors/): codurile unei cereri refuzate.
-   [Limite](https://rdcopilot.com/ro/docs/limits/): răspunsul 429.

[Pagina anterioară · **Erori**](https://rdcopilot.com/ro/docs/errors/) [Pagina următoare · **Paginare**](https://rdcopilot.com/ro/docs/pagination/)

---

R&D Copilot · Realizat în UE · Contact: https://rdcopilot.com/ro/contact/
