Create an ERP order from a won deal
Turn a won deal into its order in ERP with one request, and read the order number back on the deal.
On this page
When a deal is won, the sale becomes an order. CRM creates the order in ERP and keeps the link: the deal then names the order in order. This is the same step as Create order in ERP on a won deal in the CRM.
Check the deal
Only a won deal can have an order, and it has one. The deal must have stage won and order null.
curl
curl "$RDC_BASE_URL/crm/v1/deals/17f8c3b4-62d9-4e05-9a3c-b8e4d1f70a34" \
-H "Authorization: Bearer $RDC_TOKEN" JavaScript
const response = await fetch(`${process.env.RDC_BASE_URL}/crm/v1/deals/17f8c3b4-62d9-4e05-9a3c-b8e4d1f70a34`, {
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"]}/crm/v1/deals/17f8c3b4-62d9-4e05-9a3c-b8e4d1f70a34',
headers={
'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
},
)
result = response.json() PHP
<?php
$curl = curl_init(getenv('RDC_BASE_URL') . '/crm/v1/deals/17f8c3b4-62d9-4e05-9a3c-b8e4d1f70a34');
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")}/crm/v1/deals/17f8c3b4-62d9-4e05-9a3c-b8e4d1f70a34");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync(); {
"id": "17f8c3b4-62d9-4e05-9a3c-b8e4d1f70a34",
"number": "DL-1034",
"companyId": "256f7b75-9582-481b-8b79-5acf8ff89642",
"company": "Silozurile Zănești SRL",
"name": "Packaging for the harvest",
"owner": "ana-rusu",
"value": "214775.25",
"currency": "RON",
"stage": "won",
"reason": "price",
"expectedClose": "2026-11-20",
"order": null,
"externalId": null,
"customFields": {},
"revision": 5
} Create the order
Send the revision you read as expectedRevision. The answer is accepted, as for every change.
curl
curl -X POST "$RDC_BASE_URL/crm/v1/deals/17f8c3b4-62d9-4e05-9a3c-b8e4d1f70a34/erp-order" \
-H "Authorization: Bearer $RDC_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"operationId": "016522fb-835b-4235-83d0-a790eb0a074a",
"expectedRevision": 5
}' JavaScript
const response = await fetch(`${process.env.RDC_BASE_URL}/crm/v1/deals/17f8c3b4-62d9-4e05-9a3c-b8e4d1f70a34/erp-order`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.RDC_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"operationId": "016522fb-835b-4235-83d0-a790eb0a074a",
"expectedRevision": 5
}),
});
const result = await response.json(); Python
import os
import requests
response = requests.request(
'POST',
f'{os.environ["RDC_BASE_URL"]}/crm/v1/deals/17f8c3b4-62d9-4e05-9a3c-b8e4d1f70a34/erp-order',
headers={
'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
},
json={
'operationId': '016522fb-835b-4235-83d0-a790eb0a074a',
'expectedRevision': 5,
},
)
result = response.json() PHP
<?php
$body = <<<'JSON'
{
"operationId": "016522fb-835b-4235-83d0-a790eb0a074a",
"expectedRevision": 5
}
JSON;
$curl = curl_init(getenv('RDC_BASE_URL') . '/crm/v1/deals/17f8c3b4-62d9-4e05-9a3c-b8e4d1f70a34/erp-order');
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#
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, $"{Environment.GetEnvironmentVariable("RDC_BASE_URL")}/crm/v1/deals/17f8c3b4-62d9-4e05-9a3c-b8e4d1f70a34/erp-order");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
request.Content = new StringContent("""
{
"operationId": "016522fb-835b-4235-83d0-a790eb0a074a",
"expectedRevision": 5
}
""", System.Text.Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync(); {
"operationId": "016522fb-835b-4235-83d0-a790eb0a074a",
"status": "accepted",
"aggregateRevision": 6
} Read the order number
Read the deal again. order holds the number of the order in ERP, CV-1048 here, and the revision of the deal went up by one. The same number names the order in ERP.
curl
curl "$RDC_BASE_URL/crm/v1/deals/17f8c3b4-62d9-4e05-9a3c-b8e4d1f70a34" \
-H "Authorization: Bearer $RDC_TOKEN" JavaScript
const response = await fetch(`${process.env.RDC_BASE_URL}/crm/v1/deals/17f8c3b4-62d9-4e05-9a3c-b8e4d1f70a34`, {
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"]}/crm/v1/deals/17f8c3b4-62d9-4e05-9a3c-b8e4d1f70a34',
headers={
'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
},
)
result = response.json() PHP
<?php
$curl = curl_init(getenv('RDC_BASE_URL') . '/crm/v1/deals/17f8c3b4-62d9-4e05-9a3c-b8e4d1f70a34');
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")}/crm/v1/deals/17f8c3b4-62d9-4e05-9a3c-b8e4d1f70a34");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync(); {
"id": "17f8c3b4-62d9-4e05-9a3c-b8e4d1f70a34",
"number": "DL-1034",
"companyId": "256f7b75-9582-481b-8b79-5acf8ff89642",
"company": "Silozurile Zănești SRL",
"name": "Packaging for the harvest",
"owner": "ana-rusu",
"value": "214775.25",
"currency": "RON",
"stage": "won",
"reason": "price",
"expectedClose": "2026-11-20",
"order": "CV-1048",
"externalId": null,
"customFields": {},
"revision": 6
} Hear about it
The change sends com.rdcopilot.crm.deal.order_created.v1 to your subscriptions. Subscribe to it to follow the order without asking. See Subscriptions.
{
"specversion": "1.0",
"id": "cba18472-c7a2-4e50-9f35-9d35a805a0ee",
"type": "com.rdcopilot.crm.deal.order_created.v1",
"source": "/crm/v1",
"time": "2026-11-23T09:48:31Z",
"customerOrgId": "a3f1d7c2-64be-4b09-9d58-2c0e7f1a8b34",
"legalCompanyId": "c8b25e90-1d47-4f3a-a6d2-93e0b51f7c68",
"aggregateType": "deal",
"aggregateId": "17f8c3b4-62d9-4e05-9a3c-b8e4d1f70a34",
"aggregateRevision": 6,
"correlationId": "f06a3b8d-9e21-47c5-8b14-d5a7e2c10963",
"causationId": "016522fb-835b-4235-83d0-a790eb0a074a",
"actor": {
"serviceId": "crm-api"
},
"data": {
"number": "DL-1034",
"order": "CV-1048"
}
} What is refused
| Request | Answer | Why |
|---|---|---|
createErpOrder | 409 deal_not_won | The deal is not won. |
createErpOrder | 409 order_already_created | The deal has its order. A second one is not created, and the number does not change. |
reopenDeal | 409 order_exists | A deal that has its order in ERP cannot be reopened. |