Skip to main content

Pricing tree via REST API

How to create a pricing plan tree via the REST API

Written by Petr Pech

The price list tree is a hierarchy of categories into which price list items are assigned. It can be managed via REST API both by reading and importing; this guide demonstrates the procedure using a simple example.

⚠️ Importing into the price list tree is NOT_DOCUMENTED — we support it, but it is not part of the official documentation and we do not recommend relying on it. It is not fully implemented; for example, a tree node can only be identified by its numeric ID, not by code.


Tree records

The tree is described by three records:

Record

Contents

Individual nodes (branches) of the tree as you see them in the application once the tree is enabled — including level, order, parent node, and path.

The root of the tree; by default a single record STR_CEN — Price list tree.

Assignment of price list items to individual tree nodes.

The image shows the path to the Salt soaps category and its level:

In the API, the same tree is displayed as follows:

The element otec is the previous node (MYDLA), while cesta and hladina correspond to the order as shown in the application — the initial Price list tree node is also counted. Both of these properties are read-only, calculated automatically by Flexi.


Creating a tree

A node is created with a name (nazev), an order (poradi), and the tree it belongs to (strom). The order determines the position at which the node appears within its category; strom is the root of the tree, and otec is the preceding node. The path and level are calculated automatically.

POST https://demo.flexibee.eu/c/demo/strom.xml
<winstrom version="1.0">
<strom>
<kod>TELKREM</kod>
<nazev>Tělové krémy</nazev>
<poradi>1</poradi>
<strom>code:STR_CEN</strom>
<otec>code:KREMY</otec>
</strom>
</winstrom>

ℹ️ In the elements strom and otec, a node can be addressed by code (code:…) or by numeric ID. Nodes without a code — for example, the system nodes Assigned items and Unassigned items — can only be addressed by ID.


Assigning a price list item to the tree

The assignment is imported into the strom-cenik record. You can specify the price list item (idZaznamu) by either ID or code, but the node (uzel) only by numeric ID, which you can find by querying /strom.xml.

POST https://demo.flexibee.eu/c/demo/strom-cenik.xml
<winstrom version="1.0">
<strom-cenik>
<!-- idZaznamu = ID nebo kód ceníkové položky,
kterou chcete do stromu přiřadit -->
<idZaznamu>code:TELKREM ABC 500</idZaznamu>

<!-- uzel = ID daného uzlu ve stromu,
které zjistíte dotazem na /strom.xml -->
<uzel>4</uzel>
</strom-cenik>
</winstrom>

After the import, the assigned item TELKREM ABC 500 appears in the node with ID 4.

⚠️ Watch out for the asymmetry between reading and writing: when reading, the API returns uzel as a code (for example, code:A-I), but you cannot send such a value back — the import will reject it with 400 and code neniKodNeboNemuzeBytID (Entity 'Node' does not contain a code or it cannot be used as an ID). Use the value from uzel@ref, which contains the numeric ID.

A non-existent price list item will be rejected by the API with 400 and code formZaznamNenalezen.


Moving a tree branch

To move a branch, simply change the otec element of an existing node to the new parent category and poradi to the desired position — for example, 99, so it is placed at the end.

<winstrom version="1.0">
<strom>
<id>code:PANSKEKREMY</id>
<poradi>99</poradi>
<otec>code:TELKREMY</otec>
</strom>
</winstrom>

This will move the entire PANSKEKREMY category, including its subcategories and assigned items, into the TELKREMY category — rather than copying it. The level and path are recalculated automatically.


Related

Did this answer your question?