Skip to main content

User Associations - API

How to work with user relationships via API?

Written by Lenka Haringerová

User relations allow you to link any object to another one. Each relation must specify a relation type and the linked objects. Relations can be of two kinds:

  • manual — linked within the application or via import,

  • automatic — objects are assigned automatically according to the relation type's configuration (using a filter).

Relation types are managed via the typ-uzivatelske-vazby code list. Each type has a automaticka property and a beanKeysA/beanKeysB pair, which determines which records can appear on each side of the relation.


Retrieving a relation

You can get a list of objects in a relation as a child resource of a specific record:

GET https://demo.flexibee.eu/c/demo/faktura-vydana/1/uzivatelske-vazby

The linked object can be a direct part of the relation export:

GET https://demo.flexibee.eu/c/demo/faktura-vydana/1/uzivatelske-vazby.xml?detail=full&includes=/winstrom/uzivatelska-vazba/object

Or relations can be exported as a relation of the object itself:

GET https://demo.flexibee.eu/c/demo/faktura-vydana/1.xml?relations=uzivatelske-vazby

In addition to the entered values, each relation also returns read-only data taken over from the linked object — modul, kod, nazev, castka, datum, and objectId with the numeric ID of the linked record.


Importing a relation

Relations are imported as a child element of the record they belong to. Fill in the following:

Element

Value

vazbaTyp

Relation type from the typ-uzivatelske-vazby code list.

evidenceType

The record type in which the linked record should be searched for. The list of possible values is returned by evidence-list.

object

The linked record — searched for in the record type specified by the evidenceType element.

popis, poznam

Optional description and note for the relation.

Example of importing a manual relation in XML — we're also giving the relation an external identifier so we can reference it later:

<?xml version="1.0" encoding="UTF-8"?>
<winstrom version="1.0">
<adresar>
<id>109</id>
<uzivatelske-vazby>
<uzivatelska-vazba>
<id>ext:VAZBA:TESTEXTID-CEN</id>
<evidenceType>cenik</evidenceType>
<object>code:SKL-0001/2022</object>
<popis>popisek skl</popis>
<poznam>poznam skl</poznam>
<vazbaTyp>code:ADRCEN</vazbaTyp>
</uzivatelska-vazba>
</uzivatelske-vazby>
</adresar>
</winstrom>

And the same in JSON:

{
"winstrom":{
"@version":"1.0",
"interni-doklad":[
{
"id":"1054",
"uzivatelske-vazby":[
{
"vazbaTyp":"code:INT-FAV",
"evidenceType":"faktura-vydana",
"object":"code:VF1-0073/2022"
}
]
}
]
}
}


Deleting a relation

You can delete a relation using the action delete on the uzivatelska-vazba record type; simply provide its identifier:

<?xml version="1.0" encoding="UTF-8"?>
<winstrom version="1.0">
<uzivatelska-vazba action="delete">
<id>ext:VAZBA:TESTEXTID-CEN</id>
</uzivatelska-vazba>
</winstrom>


Failed requests

Situation

Response

evidenceType or object is missing, the specified record type doesn't exist, or the linked object doesn't exist

400, vazbyChybiElementyWhen creating a relation, 'evidenceType' and 'object' must be specified.

The selected relation type doesn't allow the given combination of record types

400, vazbaNelzeKombinaceObjektuThe selected combination of objects is not allowed for the chosen relation type.

⚠️ Getting vazbyChybiElementy even though you have evidenceType filled in? Then one of the objects you want to link doesn't exist — this is covered in more detail in the article Error when creating a user relation.


Related

Did this answer your question?