Import items and partners
Load items and partners from your own system with changes that are safe to repeat, and check what arrived.
On this page
There is no bulk call. An import is a loop of createItem and createPartner calls, one per record. The loop is safe to stop and to run again if every call carries an operationId that you derive from your own key for the record.
Items
curl
curl -X POST "$RDC_BASE_URL/erp/v1/items" \
-H "Authorization: Bearer $RDC_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"operationId": "165ff430-37fd-46db-8215-bdb803f7fa8d",
"code": "DT-0450",
"name": "Floor cleaner, 5 l",
"unit": "canister",
"unitPrice": "21.50",
"vatClass": "standard"
}' JavaScript
const response = await fetch(`${process.env.RDC_BASE_URL}/erp/v1/items`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.RDC_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"operationId": "165ff430-37fd-46db-8215-bdb803f7fa8d",
"code": "DT-0450",
"name": "Floor cleaner, 5 l",
"unit": "canister",
"unitPrice": "21.50",
"vatClass": "standard"
}),
});
const result = await response.json(); Python
import os
import requests
response = requests.request(
'POST',
f'{os.environ["RDC_BASE_URL"]}/erp/v1/items',
headers={
'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
},
json={
'operationId': '165ff430-37fd-46db-8215-bdb803f7fa8d',
'code': 'DT-0450',
'name': 'Floor cleaner, 5 l',
'unit': 'canister',
'unitPrice': '21.50',
'vatClass': 'standard',
},
)
result = response.json() PHP
<?php
$body = <<<'JSON'
{
"operationId": "165ff430-37fd-46db-8215-bdb803f7fa8d",
"code": "DT-0450",
"name": "Floor cleaner, 5 l",
"unit": "canister",
"unitPrice": "21.50",
"vatClass": "standard"
}
JSON;
$curl = curl_init(getenv('RDC_BASE_URL') . '/erp/v1/items');
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")}/erp/v1/items");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
request.Content = new StringContent("""
{
"operationId": "165ff430-37fd-46db-8215-bdb803f7fa8d",
"code": "DT-0450",
"name": "Floor cleaner, 5 l",
"unit": "canister",
"unitPrice": "21.50",
"vatClass": "standard"
}
""", System.Text.Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync(); {
"operationId": "165ff430-37fd-46db-8215-bdb803f7fa8d",
"status": "accepted",
"aggregateId": "99c92e8e-31cd-4090-ad40-ac0ad9e8f317",
"aggregateRevision": 1
} - The
codeis unique in the company. CreatingDT-0450a second time with a newoperationIdis refused withitem_code_takenand changes nothing. - Repeating the very same call, with the same
operationIdand the same body, is not an error: you get the result of the first call. Reusing anoperationIdwith a different body is refused withoperation_reused. unitPriceis a net amount with at most two decimals andvatClassisstandardorreduced. The stock of a new item is 0; goods enter with a receipt.
// Import items from your own list. The operationId is derived from your own key,
// so running the import again repeats the same changes instead of making new ones.
import {createHash} from 'node:crypto';
const base = process.env.RDC_BASE_URL;
const headers = {Authorization: `Bearer ${process.env.RDC_TOKEN}`, 'Content-Type': 'application/json'};
// A stable UUID for one change: the same code always gives the same operationId.
const operationIdFor = (kind, key) => {
const h = createHash('sha256').update(`${kind}:${key}`).digest('hex');
return `${h.slice(0, 8)}-${h.slice(8, 12)}-4${h.slice(13, 16)}-8${h.slice(17, 20)}-${h.slice(20, 32)}`;
};
async function createItem(item) {
const response = await fetch(`${base}/erp/v1/items`, {
method: 'POST', headers,
body: JSON.stringify(Object.assign({operationId: operationIdFor('item', item.code)}, item)),
});
if (response.status === 202) return 'created';
const error = await response.json();
if (error.code === 'item_code_taken') return 'exists';
throw new Error(`${item.code}: ${response.status} ${error.code}`);
}
for (const item of items) console.log(item.code, await createItem(item)); Partners
createPartner takes the name, the roles (customer, supplier or both), the town and the country, and the VAT identifier if the partner has one. Import customers and suppliers before the orders that name them: an order that names a partner that does not exist is refused with partner_not_found.
curl
curl -X POST "$RDC_BASE_URL/erp/v1/partners" \
-H "Authorization: Bearer $RDC_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"operationId": "198aa2c7-7aa6-4ef8-91b6-2655bcdfce2f",
"name": "Băuturi Trotuș SRL",
"roles": [
"supplier"
],
"city": "Onești",
"country": "RO",
"vatId": "RO51603783"
}' JavaScript
const response = await fetch(`${process.env.RDC_BASE_URL}/erp/v1/partners`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.RDC_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"operationId": "198aa2c7-7aa6-4ef8-91b6-2655bcdfce2f",
"name": "Băuturi Trotuș SRL",
"roles": [
"supplier"
],
"city": "Onești",
"country": "RO",
"vatId": "RO51603783"
}),
});
const result = await response.json(); Python
import os
import requests
response = requests.request(
'POST',
f'{os.environ["RDC_BASE_URL"]}/erp/v1/partners',
headers={
'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
},
json={
'operationId': '198aa2c7-7aa6-4ef8-91b6-2655bcdfce2f',
'name': 'Băuturi Trotuș SRL',
'roles': [
'supplier',
],
'city': 'Onești',
'country': 'RO',
'vatId': 'RO51603783',
},
)
result = response.json() PHP
<?php
$body = <<<'JSON'
{
"operationId": "198aa2c7-7aa6-4ef8-91b6-2655bcdfce2f",
"name": "Băuturi Trotuș SRL",
"roles": [
"supplier"
],
"city": "Onești",
"country": "RO",
"vatId": "RO51603783"
}
JSON;
$curl = curl_init(getenv('RDC_BASE_URL') . '/erp/v1/partners');
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")}/erp/v1/partners");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
request.Content = new StringContent("""
{
"operationId": "198aa2c7-7aa6-4ef8-91b6-2655bcdfce2f",
"name": "Băuturi Trotuș SRL",
"roles": [
"supplier"
],
"city": "Onești",
"country": "RO",
"vatId": "RO51603783"
}
""", System.Text.Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync(); {
"operationId": "198aa2c7-7aa6-4ef8-91b6-2655bcdfce2f",
"status": "accepted",
"aggregateId": "6c530bd6-7a0b-45d5-ab13-c97963e33d0a",
"aggregateRevision": 1
} Check what arrived
Walk the list with limit and cursor and compare it with your source. A change is answered with 202 before it is applied; read the operation, or list the items, before you rely on a record. See Pagination and Operations.
curl
curl "$RDC_BASE_URL/erp/v1/items?limit=20" \
-H "Authorization: Bearer $RDC_TOKEN" JavaScript
const response = await fetch(`${process.env.RDC_BASE_URL}/erp/v1/items?limit=20`, {
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"]}/erp/v1/items?limit=20',
headers={
'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
},
)
result = response.json() PHP
<?php
$curl = curl_init(getenv('RDC_BASE_URL') . '/erp/v1/items?limit=20');
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")}/erp/v1/items?limit=20");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync(); {
"items": [
{
"id": "1f30c60b-f896-443e-9086-2e72ab3dcc3c",
"code": "FA-0010",
"name": "White flour, 10 kg bag",
"unit": "bag",
"unitPrice": "38.90",
"vatClass": "reduced",
"vatRate": "11",
"cost": "32.50",
"made": false,
"onHand": "36",
"reserved": "0",
"available": "36",
"incoming": "0"
},
{
"id": "42c7977f-e96f-4243-b6fe-f133d52b1f18",
"code": "UL-0101",
"name": "Sunflower oil, 1 l",
"unit": "bottle",
"unitPrice": "7.84",
"vatClass": "reduced",
"vatRate": "11",
"cost": "6.40",
"made": false,
"onHand": "140",
"reserved": "48",
"available": "92",
"incoming": "0"
},
{
"id": "4a929b04-42fc-4df8-9784-852fdd270787",
"code": "ZA-0201",
"name": "Sugar, 1 kg",
"unit": "bag",
"unitPrice": "4.29",
"vatClass": "reduced",
"vatRate": "11",
"cost": "3.50",
"made": false,
"onHand": "210",
"reserved": "0",
"available": "210",
"incoming": "0"
}
],
"nextCursor": null
}