Skip to main content

Using /query in the REST API

Using the /query Call in POST Requests

Written by Petr Pech

By calling /query, all parameters and filters that are normally sent in the URL can instead be sent in the request body. In the body of the POST method, you can pass the level of detail, pagination, filtering, and sorting. This is especially useful for long filters that wouldn't fit in the URL.

ℹ️ Before using query, we recommend reading up on standard URL construction, or the introductory Getting Started with the Flexi API.


Standard call

The address consists of the record and the name query with the format extension; everything else goes into the request body:

POST https://demo.flexibee.eu/c/demo/faktura-vydana/query.json
{ "winstrom": { ... filtry, detail, parametry } }

A combination is also possible, where part of the parameters remain in the URL:

POST https://demo.flexibee.eu/c/demo/faktura-vydana/query.json?use-internal-id=true&no-ext-ids=true&add-row-count=true

⚠️ Watch out for limit: for the /query call, only the value from the request body is used — the value in the URL is ignored. To limit the number of records, specify "limit" in the body; "limit":"0" means no limit. The add-row-count=true parameter, on the other hand, does work in the URL.


Writing the detail

The detail is written as a list of values — even in the case of nested included properties:

"detail":"custom:kod,nazFirmy,datVyst,datSplat,zbyvaUhradit,sumCelkem,stavUhrK,sumCelkemMen,mena(kod),stredisko(nazev,kod,id)"

Similarly, includes is written as another element, as a comma-separated list of included records:

"includes":"/faktura-vydana/mena,/faktura-vydana/stredisko"

And the same applies to other detail parameters and pagination:

"no-ext-ids":"true","limit":"80","start":"0","@version":"1.0"


Writing the filter

The filter is written in round brackets, the same as in standard URL notation:

"filter":"(datSplat lt now() and ((storno eq false and (stavUhrK is null or (stavUhrK neq \"stavUhr.uhrazeno\")))))"

The filter contains the logical operators and and or, or others as described in the filtering documentation. Semantic quotation marks used to write strings must be escaped with a backslash. The now() function passes today's date — in the example above, we are filtering invoices whose due date is earlier than today's date and which are also neither canceled nor paid.


Writing the sort order

Sorting is written in square brackets, in the order in which it should be applied:

"order":["sumCelkem","sumCelkemMen","mena"]

The output will therefore first be sorted by total amounts and then by currency. If you're sorting by only one column, this is enough:

"order":"kod"


Sample calls

Issued invoices with nested records

We'll filter issued invoices and add the add-row-count parameter for verification. We retrieve the invoices with a custom detail including nested currency, division, and document type; in the filter, we reference the currency by ID and the document type by code. We want the entire result without external IDs and limit it to 100 records — that's why limit is included in the body.

POST https://demo.flexibee.eu/c/demo/faktura-vydana/query.json?add-row-count=true
{ "winstrom": {
"detail":"custom:kod,nazFirmy,datVyst,datSplat,zbyvaUhradit,storno,juhSum,sumCelkem,stavUhrK,sumCelkemMen,mena(kod),stredisko(nazev,kod,id),typDokl(typDoklK)",
"includes":"/faktura-vydana/mena,/faktura-vydana/stredisko,/faktura-vydana/typDokl",
"filter":"(kod like \"2021\" and mena eq \"31\" and typDokl eq \"code:FAKTURA\")",
"limit":"100",
"no-ext-ids":"true",
"@version":"1.0"
}}

Setup in Postman:

Received orders with company contact

We want to retrieve a custom detail of a received order, including the email and phone number from the nested company record. We're filtering orders with an issue date from June 1, 2021, and document type OBP, sorting the results by total amount and document code.

POST https://demo.flexibee.eu/c/demo/objednavka-prijata/query.json
{ "winstrom": {
"detail":"custom:kod,sumCelkem,varSym,typDokl,firma(email,tel)",
"limit":"0",
"filter":"(datVyst > 2021-06-01) and typDokl = \"code:OBP\"",
"includes":"/objednavka-prijata/firma",
"order":["sumCelkem","kod"],
"@version":"1.0"
}}

Setup in Postman:


Related

Did this answer your question?