Skip to main content

Using /query in the REST API

Utilizing /query calls in POST requests

Written by Petr Pech

Using the /query call, all parameters and filters that are normally sent in the URL can be submitted via the request body instead. This documentation describes the basic functionality. The POST request body can include the detail level, pagination, filtering, and more.

Before using query, we recommend reviewing the standard URL construction guide or Getting started with Flexi API.

Standard JSON call

  1. Request body
    { "winstrom": { ... filtry, detail, parametry } }

Other information is provided in the request body. A combination is also possible, where some parameters are written directly in the URL:

Specifying detail

Detail is specified as an enumeration of values as follows, including nested included properties:

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

Similarly, includes itself is written as another element, using an enumeration of included records separated by commas:

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

Or other detail parameters and pagination:

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

Specifying a filter

Filters are written in parentheses in the same way as in standard URL notation:

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

The filter supports logical operators and and or, as well as others described in the filtering documentation. Quotation marks used as string delimiters are escaped with backslashes. You can also notice the now() function, which passes today's date. In this example, we are filtering invoices where the due date is earlier than today's date and where the document has not been cancelled or paid.

Specifying sorting

Sorting is written in square brackets in the order in which it should be applied, when multiple sorting criteria are used:

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

The output will first be sorted by total amount and then by currency. Multiple sorting criteria can be specified. For a single sorting criterion, write:

"order":"kod"

Call examples

Below are complete call examples with demonstrations in the Postman application.

  1. We filter 100 issued invoices and add the add-row-count parameter for verification. The invoices are retrieved with a custom detail level, along with nested currency, cost center, and document type. In the filter, we retrieve the currency by ID and the document type by code. We want the entire result without external IDs.

    POST

    Request body

    { "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\")",
    "no-ext-ids":"true",
    "@version":"1.0"
    }}

    Postman view

  2. We want to retrieve a custom detail of a purchase order, including email and phone information from the nested company record. We filter orders with a date of issue from 1 June 2021 and document type OBP. The results are sorted by total amount and document code.

    POST

    Request body

    { "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"
    }}

    Postman view

Did this answer your question?