Skip to main content

Creating a Production Order Using the REST API

How to create an issued order for production via the Flexi REST API?

Written by Petr Pech

A production order is created from an existing issued order: the REST API goes through its items, breaks them down into materials according to the bill of materials, and creates a new issued order for the selected supplier from it. For this to work, the material items must have a bill of materials and warehouse mapping set up.

ℹ️ This service is only available for the issued orders record. The behavior of this feature in the app is described in the article Issued Order.


Building the URL

Ordering for production is implemented in the REST API as a virtual record objednani with two sub-records. The call takes place in two steps — first you request the list of materials, then you send it back to create the order.

Address

Methods

What it does

/c/{firma}/objednani/(filtr)/pro-vyrobu-zbozi

GET

Returns the materials needed to manufacture the goods on the filtered orders.

/c/{firma}/objednani/(filtr)/pro-vyrobu

POST, PUT

Creates a material order from the specified suppliers.

The supported output formats are XML and JSON, selected via the URL suffix. An overview of HTTP methods can be found in the developer documentation.

⚠️ Both sub-records require a filter in the URL that identifies objects from the objednavka-vydana record — it is written in parentheses between the name of the virtual record and the name of the sub-record. Without a filter, the API returns 404 with code adresaNeplatnaUrl.


Getting the material list

A request using method GET returns the materials broken down according to the bill of materials. For each zbozi item, you get the following properties:

Property

Meaning

cenik

The goods to be ordered.

sklad

The warehouse the goods belong to.

jizObjednano

The quantity already ordered.

jizRezervovano

Fulfilled reservations.

objednano

The quantity to be ordered.

objednat

The quantity to order — this value can be adjusted before sending.

skladem

The quantity in stock.

sklMinimum

The minimum stock quantity.

On the issued order with ID 123, we have goods ready for production that have a defined bill of materials:

GET https://demo.flexibee.eu/c/demo/objednani/(id=123)/pro-vyrobu-zbozi.xml

The response is a list of materials:

<?xml version="1.0" ?>
<winstrom>
<zbozi>
<cenik>code:DRÁT</cenik>
<jizObjednano>680.9</jizObjednano>
<jizRezervovano>0.0</jizRezervovano>
<objednano>32.0</objednano>
<objednat>0.0</objednat>
<sklMinimum>0.0</sklMinimum>
<sklad>code:LIBEREC</sklad>
<skladem>49.7</skladem>
</zbozi>
<zbozi>
<cenik>code:STŘED</cenik>
<jizObjednano>0.0</jizObjednano>
<jizRezervovano>0.0</jizRezervovano>
<objednano>1.0</objednano>
<objednat>0.0</objednat>
<sklMinimum>0.0</sklMinimum>
<sklad>code:LIBEREC</sklad>
<skladem>112.0</skladem>
</zbozi>
<zbozi>
<cenik>code:RÁFEK</cenik>
<jizObjednano>0.0</jizObjednano>
<jizRezervovano>0.0</jizRezervovano>
<objednano>1.0</objednano>
<objednat>0.0</objednat>
<sklMinimum>0.0</sklMinimum>
<sklad>code:LIBEREC</sklad>
<skladem>122.0</skladem>
</zbozi>
</winstrom>

The same request can also be sent in JSON:

GET https://demo.flexibee.eu/c/demo/objednani/(id=123)/pro-vyrobu-zbozi.json
{
"winstrom": {
"zbozi": [
{
"cenik": "code:DRÁT",
"jizObjednano": "685.9",
"jizRezervovano": "0.0",
"objednano": "32.0",
"objednat": "0.0",
"sklMinimum": "0.0",
"sklad": "code:LIBEREC",
"skladem": "49.7"
},
{
"cenik": "code:STŘED",
"jizObjednano": "10.0",
"jizRezervovano": "0.0",
"objednano": "1.0",
"objednat": "0.0",
"sklMinimum": "0.0",
"sklad": "code:LIBEREC",
"skladem": "112.0"
},
{
"cenik": "code:RÁFEK",
"jizObjednano": "10.0",
"jizRezervovano": "0.0",
"objednano": "1.0",
"objednat": "0.0",
"sklMinimum": "0.0",
"sklad": "code:LIBEREC",
"skladem": "122.0"
}
]
}
}


Creating a production order

Send the obtained material list — with the objednat value possibly adjusted — back as the request body. Each objednaniProVyrobu element creates one issued order and requires:

Element

Value

typDokl

ID or code of an object from the typ-objednavky-vydane record

dodavatel

ID or code of an object from the adresar record

zboziProVyrobu

A list of zbozi elements obtained from the pro-vyrobu-zbozi sub-record

POST https://demo.flexibee.eu/c/demo/objednani/(id=123)/pro-vyrobu.xml
<?xml version="1.0" ?>
<winstrom>
<objednaniProVyrobu>
<typDokl>code:VYROBA</typDokl>
<dodavatel>code:SIGNA</dodavatel>
<zboziProVyrobu>
<zbozi>
<cenik>code:DRÁT</cenik>
<jizObjednano>680.9</jizObjednano>
<jizRezervovano>0.0</jizRezervovano>
<objednano>32.0</objednano>
<objednat>5.0</objednat>
<sklMinimum>0.0</sklMinimum>
<sklad>code:LIBEREC</sklad>
<skladem>49.7</skladem>
</zbozi>
<zbozi>
<cenik>code:STŘED</cenik>
<jizObjednano>0.0</jizObjednano>
<jizRezervovano>0.0</jizRezervovano>
<objednano>1.0</objednano>
<objednat>10.0</objednat>
<sklMinimum>0.0</sklMinimum>
<sklad>code:LIBEREC</sklad>
<skladem>112.0</skladem>
</zbozi>
</zboziProVyrobu>
</objednaniProVyrobu>
</winstrom>

On success, the API returns 201 Created with the identifiers of the created issued orders:

<?xml version="1.0" encoding="utf-8"?>
<winstrom version="1.0">
<success>true</success>
<stats>
<created>1</created>
<updated>0</updated>
<deleted>0</deleted>
<skipped>0</skipped>
<failed>0</failed>
</stats>
<results>
<result>
<id>363</id>
</result>
</results>
</winstrom>

⚠️ Check the created value in the response. An item for which the warehouse cannot be determined — for example, because you omitted the sklad element in zbozi — will be skipped by the service, but it will still return 201 Created with created equal to zero and an empty results element.

Ordering from multiple suppliers

The objednaniProVyrobu element can be listed multiple times in a single request — a separate order is created for each supplier:

POST https://demo.flexibee.eu/c/demo/objednani/(id=123)/pro-vyrobu.json
{
"winstrom": {
"@version": "1.0",
"objednaniProVyrobu": [
{
"typDokl": "code:OBV",
"dodavatel": "code:DODAVATEL-A",
"zboziProVyrobu": {
"zbozi": {
"cenik": "5",
"sklad": "4",
"jizObjednano": "0.0",
"jizRezervovano": "0.0",
"objednano": "10.0",
"objednat": "10.0",
"sklMinimum": "0.0",
"skladem": "0.0"
}
}
},
{
"typDokl": "code:OBV",
"dodavatel": "code:DODAVATEL-B",
"zboziProVyrobu": {
"zbozi": {
"cenik": "6",
"sklad": "4",
"jizObjednano": "0.0",
"jizRezervovano": "0.0",
"objednano": "20.0",
"objednat": "20.0",
"sklMinimum": "0.0",
"skladem": "0.0"
}
}
}
]
}
}

Ordering in packages

Instead of the objednat element, you can use the objednatBaleni element and specify the quantity in packages. Packages are defined in the price list for the goods identified by the cenik element, and multiple package types can be combined in a single request. Each package includes:

  • id — package identification in the price list (values 1 to 5)

  • mnozMj — the quantity to order in packages (decimal number)

If we have a package with id 1 containing two pieces, and a package with id 2 containing four pieces, the following request will order 10 pieces of the goods:

POST https://demo.flexibee.eu/c/demo/objednani/(id=123)/pro-vyrobu.json
{
"winstrom": {
"@version": "1.0",
"objednaniProVyrobu": {
"typDokl": "code:OBV",
"dodavatel": "code:DODAVATEL-A",
"zboziProVyrobu": {
"zbozi": {
"cenik": "5",
"sklad": "4",
"jizObjednano": "0.0",
"jizRezervovano": "0.0",
"objednano": "10.0",
"objednatBaleni": {
"baleni": [
{
"id": "1",
"mnozMj": "1.0"
},
{
"id": "2",
"mnozMj": "2.0"
}
]
},
"sklMinimum": "0.0",
"skladem": "0.0"
}
}
}
}
}

On the item of the created order, the number of packages is stored in mnozBaleni, and the recalculated quantity in measurement units is stored in mnozMj.


Failed requests

Situation

Response

Method GET sent to the pro-vyrobu sub-record

405 Method Not Allowed, success is false

The order filter is missing from the URL

404, adresaNeplatnaUrl — Address … is not valid.

The order has already been sent to production, or does not contain a goods item with a bill of materials

400, obchodGenerNicProHromObj — No items suitable for ordering were found.

The material from the bill of materials does not have warehouse mapping set up

400, mapSkladChybi — Warehouse mapping is not set for price list item 'DOPRAVA'.

The request body is missing typDokl

400, importXmlMissingIdentifier — Identifier (typDokl) is not specified.

A typo in the element name, for example doddavatel

400 — unexpected element (uri:"", local:"doddavatel"). Expected elements are <zboziProVyrobu>, <dodavatel>, <typDokl>

The error message is generated already when reading the material list, not only when creating the order — so you will see codes obchodGenerNicProHromObj and mapSkladChybi even with a GET request to pro-vyrobu-zbozi.

🚨 The pro-vyrobu sub-record does not respect the dry-run parameter ?dry-run=true — the issued order will be created even with it. Therefore, do not try this call "for testing" in a production company.


Related

Did this answer your question?