---
title: "Tasks and runs | Docs | AI Assistant by R&D Copilot"
description: "Prepare, review and dispatch an offer from a CRM request."
canonical: "https://ai.rdcopilot.com/docs/api-reference/tasks-and-runs/"
language: en
updated: 2026-11-22
---

# Tasks and runs

Prepare, review and dispatch an offer from a CRM request.

## Queue offer preparation

POST `/ai/v1/tasks/runs`

### Request body

| Field | Type | Required | Meaning |
| --- | --- | --- | --- |
| `operationId` | `string (uuid)` | Yesrequired | UUID selected by the client. |
| `expectedRevision` | `integer` | Yesrequired | Revision of the record. |
| `runId` | `string` | Yesrequired | Stable identifier. |
| `requestId` | `string` | Yesrequired | Stable identifier. |

### Responses

| Status | Meaning | Body |
| --- | --- | --- |
| `202` | Read the operation to follow the outcome. | `OperationResult` |
| `400` | The request cannot be read or breaks the contract: malformed JSON, a missing or unknown field, a wrong type. `fields` names each one. | `Error` |
| `401` | The token is missing, expired or not ours. | `Error` |
| `403` | The token does not give access to this company or operation. | `Error` |
| `409` | `expectedRevision` is older than the record. | `Error` |
| `422` | Read the current run before choosing an action. | `Error` |
| `429` | Too many requests. `Retry-After` gives the seconds. | `Error` |
| `503` | The service cannot answer now. | `Error` |

### Request

curl

```bash
curl -X POST "$RDC_BASE_URL/ai/v1/tasks/runs" \
  -H "Authorization: Bearer $RDC_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "operationId": "1b5201ad-39eb-4cc1-889c-2dd2d43ffc57",
  "expectedRevision": 0,
  "runId": "run-1042",
  "requestId": "CV-1042"
}'
```

JavaScript

```javascript
const response = await fetch(`${process.env.RDC_BASE_URL}/ai/v1/tasks/runs`, {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.RDC_TOKEN}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "operationId": "1b5201ad-39eb-4cc1-889c-2dd2d43ffc57",
    "expectedRevision": 0,
    "runId": "run-1042",
    "requestId": "CV-1042"
  }),
});
const result = await response.json();
```

Python

```python
import os
import requests

response = requests.request(
    'POST',
    f'{os.environ["RDC_BASE_URL"]}/ai/v1/tasks/runs',
    headers={
        'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
    },
    json={
        'operationId': '1b5201ad-39eb-4cc1-889c-2dd2d43ffc57',
        'expectedRevision': 0,
        'runId': 'run-1042',
        'requestId': 'CV-1042',
    },
)
result = response.json()
```

PHP

```php
<?php

$body = <<<'JSON'
{
  "operationId": "1b5201ad-39eb-4cc1-889c-2dd2d43ffc57",
  "expectedRevision": 0,
  "runId": "run-1042",
  "requestId": "CV-1042"
}
JSON;

$curl = curl_init(getenv('RDC_BASE_URL') . '/ai/v1/tasks/runs');
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")}/ai/v1/tasks/runs");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
request.Content = new StringContent("""
{
  "operationId": "1b5201ad-39eb-4cc1-889c-2dd2d43ffc57",
  "expectedRevision": 0,
  "runId": "run-1042",
  "requestId": "CV-1042"
}
""", System.Text.Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync();
```

### Response `202`

JSON

```json
{
  "operationId": "1b5201ad-39eb-4cc1-889c-2dd2d43ffc57",
  "status": "accepted",
  "aggregateRevision": 1
}
```

## Read run, steps and decision

GET `/ai/v1/tasks/runs/{runId}`

### Parameters

| Name | In | Type | Required | Meaning |
| --- | --- | --- | --- | --- |
| `runId` | path | `string` | Yesrequired | Identifier of the run. |

### Responses

| Status | Meaning | Body |
| --- | --- | --- |
| `200` | Current result. | `Run` |
| `400` | The request cannot be read or breaks the contract: malformed JSON, a missing or unknown field, a wrong type. `fields` names each one. | `Error` |
| `401` | The token is missing, expired or not ours. | `Error` |
| `403` | The token does not give access to this company or operation. | `Error` |
| `404` | The record does not exist for this company. | `Error` |
| `429` | Too many requests. `Retry-After` gives the seconds. | `Error` |
| `503` | The service cannot answer now. | `Error` |

### Request

curl

```bash
curl "$RDC_BASE_URL/ai/v1/tasks/runs/run-1042" \
  -H "Authorization: Bearer $RDC_TOKEN"
```

JavaScript

```javascript
const response = await fetch(`${process.env.RDC_BASE_URL}/ai/v1/tasks/runs/run-1042`, {
  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"]}/ai/v1/tasks/runs/run-1042',
    headers={
        'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
    },
)
result = response.json()
```

PHP

```php
<?php

$curl = curl_init(getenv('RDC_BASE_URL') . '/ai/v1/tasks/runs/run-1042');
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")}/ai/v1/tasks/runs/run-1042");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync();
```

### Response `200`

JSON

```json
{
  "status": "waiting_for_approval",
  "draft": {
    "net": "399.81",
    "lines": [
      {
        "sku": "DT-0412",
        "name": "Dishwashing liquid, 5 l",
        "quantity": "12",
        "unitPrice": "23.47",
        "net": "281.64"
      },
      {
        "sku": "AM-0518",
        "name": "Paper bags, pack of 100",
        "quantity": "9",
        "unitPrice": "13.13",
        "net": "118.17"
      }
    ]
  },
  "revision": 2,
  "steps": [
    {
      "id": "read_request",
      "tool": "CRM",
      "status": "done",
      "output": "CV-1042"
    },
    {
      "id": "price_offer",
      "tool": "ERP",
      "status": "done"
    },
    {
      "id": "send_offer",
      "tool": "CRM",
      "status": "waiting_for_approval"
    }
  ],
  "id": "run-1042"
}
```

## Edit a draft line

PATCH `/ai/v1/tasks/runs/{runId}/draft`

### Parameters

| Name | In | Type | Required | Meaning |
| --- | --- | --- | --- | --- |
| `runId` | path | `string` | Yesrequired | Identifier of the run. |

### Request body

| Field | Type | Required | Meaning |
| --- | --- | --- | --- |
| `operationId` | `string (uuid)` | Yesrequired | UUID selected by the client. |
| `expectedRevision` | `integer` | Yesrequired | Revision of the record. |
| `sku` | `string` | Yesrequired | Stable identifier. |
| `quantity` | `string` | Yesrequired | Positive whole quantity as a decimal string. |

### Responses

| Status | Meaning | Body |
| --- | --- | --- |
| `202` | Read the operation to follow the outcome. | `OperationResult` |
| `400` | The request cannot be read or breaks the contract: malformed JSON, a missing or unknown field, a wrong type. `fields` names each one. | `Error` |
| `401` | The token is missing, expired or not ours. | `Error` |
| `403` | The token does not give access to this company or operation. | `Error` |
| `404` | The record does not exist for this company. | `Error` |
| `409` | `expectedRevision` is older than the record. | `Error` |
| `422` | Read the current run before choosing an action. | `Error` |
| `429` | Too many requests. `Retry-After` gives the seconds. | `Error` |
| `503` | The service cannot answer now. | `Error` |

### Request

curl

```bash
curl -X PATCH "$RDC_BASE_URL/ai/v1/tasks/runs/run-1042/draft" \
  -H "Authorization: Bearer $RDC_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "operationId": "68549b88-bb2a-449e-a341-79d16f31f897",
  "expectedRevision": 2,
  "sku": "DT-0412",
  "quantity": "7"
}'
```

JavaScript

```javascript
const response = await fetch(`${process.env.RDC_BASE_URL}/ai/v1/tasks/runs/run-1042/draft`, {
  method: 'PATCH',
  headers: {
    Authorization: `Bearer ${process.env.RDC_TOKEN}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "operationId": "68549b88-bb2a-449e-a341-79d16f31f897",
    "expectedRevision": 2,
    "sku": "DT-0412",
    "quantity": "7"
  }),
});
const result = await response.json();
```

Python

```python
import os
import requests

response = requests.request(
    'PATCH',
    f'{os.environ["RDC_BASE_URL"]}/ai/v1/tasks/runs/run-1042/draft',
    headers={
        'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
    },
    json={
        'operationId': '68549b88-bb2a-449e-a341-79d16f31f897',
        'expectedRevision': 2,
        'sku': 'DT-0412',
        'quantity': '7',
    },
)
result = response.json()
```

PHP

```php
<?php

$body = <<<'JSON'
{
  "operationId": "68549b88-bb2a-449e-a341-79d16f31f897",
  "expectedRevision": 2,
  "sku": "DT-0412",
  "quantity": "7"
}
JSON;

$curl = curl_init(getenv('RDC_BASE_URL') . '/ai/v1/tasks/runs/run-1042/draft');
curl_setopt_array($curl, [
    CURLOPT_CUSTOMREQUEST => 'PATCH',
    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.Patch, $"{Environment.GetEnvironmentVariable("RDC_BASE_URL")}/ai/v1/tasks/runs/run-1042/draft");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
request.Content = new StringContent("""
{
  "operationId": "68549b88-bb2a-449e-a341-79d16f31f897",
  "expectedRevision": 2,
  "sku": "DT-0412",
  "quantity": "7"
}
""", System.Text.Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync();
```

### Response `202`

JSON

```json
{
  "operationId": "68549b88-bb2a-449e-a341-79d16f31f897",
  "status": "accepted",
  "aggregateRevision": 3
}
```

## Approve and send, or reject an offer

POST `/ai/v1/tasks/runs/{runId}/decision`

### Parameters

| Name | In | Type | Required | Meaning |
| --- | --- | --- | --- | --- |
| `runId` | path | `string` | Yesrequired | Identifier of the run. |

### Request body

| Field | Type | Required | Meaning |
| --- | --- | --- | --- |
| `operationId` | `string (uuid)` | Yesrequired | UUID selected by the client. |
| `expectedRevision` | `integer` | Yesrequired | Revision of the record. |
| `decision` | `string` | Yesrequired | Reviewer’s decision. One of `approved`, `rejected` |

### Responses

| Status | Meaning | Body |
| --- | --- | --- |
| `202` | Read the operation to follow the outcome. | `OperationResult` |
| `400` | The request cannot be read or breaks the contract: malformed JSON, a missing or unknown field, a wrong type. `fields` names each one. | `Error` |
| `401` | The token is missing, expired or not ours. | `Error` |
| `403` | The token does not give access to this company or operation. | `Error` |
| `404` | The record does not exist for this company. | `Error` |
| `409` | `expectedRevision` is older than the record. | `Error` |
| `422` | Read the current run before choosing an action. | `Error` |
| `429` | Too many requests. `Retry-After` gives the seconds. | `Error` |
| `503` | The service cannot answer now. | `Error` |

### Request

curl

```bash
curl -X POST "$RDC_BASE_URL/ai/v1/tasks/runs/run-1042/decision" \
  -H "Authorization: Bearer $RDC_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "operationId": "423a61ed-2ea7-40fd-a31e-da3baa387eac",
  "expectedRevision": 2,
  "decision": "approved"
}'
```

JavaScript

```javascript
const response = await fetch(`${process.env.RDC_BASE_URL}/ai/v1/tasks/runs/run-1042/decision`, {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.RDC_TOKEN}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "operationId": "423a61ed-2ea7-40fd-a31e-da3baa387eac",
    "expectedRevision": 2,
    "decision": "approved"
  }),
});
const result = await response.json();
```

Python

```python
import os
import requests

response = requests.request(
    'POST',
    f'{os.environ["RDC_BASE_URL"]}/ai/v1/tasks/runs/run-1042/decision',
    headers={
        'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
    },
    json={
        'operationId': '423a61ed-2ea7-40fd-a31e-da3baa387eac',
        'expectedRevision': 2,
        'decision': 'approved',
    },
)
result = response.json()
```

PHP

```php
<?php

$body = <<<'JSON'
{
  "operationId": "423a61ed-2ea7-40fd-a31e-da3baa387eac",
  "expectedRevision": 2,
  "decision": "approved"
}
JSON;

$curl = curl_init(getenv('RDC_BASE_URL') . '/ai/v1/tasks/runs/run-1042/decision');
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")}/ai/v1/tasks/runs/run-1042/decision");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
request.Content = new StringContent("""
{
  "operationId": "423a61ed-2ea7-40fd-a31e-da3baa387eac",
  "expectedRevision": 2,
  "decision": "approved"
}
""", System.Text.Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync();
```

### Response `202`

JSON

```json
{
  "operationId": "423a61ed-2ea7-40fd-a31e-da3baa387eac",
  "status": "accepted",
  "aggregateRevision": 3
}
```
