CodamAIDocs
Topicdone

Structure of a search

What a search request looks like: response, parameter with query, order, page, limit, meta, and which default values apply.

Variants
minimal searchwith filterwith sortingwith pageswithout parameterwithout read role → 403

What this is about

With POST {basis}/query you get a list of objects of a model, for example all customers from Köln, sorted by name, 25 per page. The body has two parts:

  • response says which fields each object in the list has. This is the same field selection as for reading, see Field selection with response.
  • parameter says which objects come back, and in which order.

A complete request

{
  "response": ["id", "name", "city"],
  "parameter": {
    "query": {
      "type": "AND",
      "filter": [
        { "key": "city", "value": "Köln", "param": "EQ" }
      ],
      "group": []
    },
    "order": [ { "field": "name", "order": "ASC" } ],
    "page": 0,
    "limit": 25,
    "meta": true
  }
}
flowchart TB
    B["Body of POST /query"] --> R["response<br/>which fields"]
    B --> P["parameter"]
    P --> Q["query<br/>which objects (filter tree)"]
    P --> O["order<br/>in which order"]
    P --> S["page + limit<br/>which slice"]
    P --> M["meta<br/>information about the list"]
    Q --> T["type: AND or OR"]
    Q --> F["filter: single conditions<br/>key, value, param"]
    Q --> G["group: subgroups<br/>again with type, filter, group"]
PartMeaningMore on this
query.typehow the entries of this group are combined: AND or ORAND/OR groups
query.filtersingle conditions: field (key), value (value), operator (param)All filter operators
query.groupsubgroups with their own typeAND/OR groups
ordersort criteria in order of their importanceSorting
page, limitwhich page and how many objects per pagePaging and match count
metawhether information about the list comes alongPaging and match count

Default values

Everything in parameter may be left out. Then these values apply:

SettingDefaultEffect
parameteremptyall visible objects, no sorting
querynoneno filter from the client
query.typeORentries of the group are combined with OR
filter[].paramLIKEcomparison with a search pattern
ordernoneorder is not defined
page0first page, counted from 0
limit-1all matches at once
metatrueinformation about the list comes along

The response

Response to a search
Request
POST /api/rest/crm/customer/query
{ "response": ["id", "name"],
  "parameter": { "limit": 2, "order": [{ "field": "name", "order": "ASC" }] } }
Response
{
  "data": [
    { "id": "5a2b…", "name": "Alt-Muster AG" },
    { "id": "7c1d…", "name": "Muster GmbH" }
  ],
  "meta": {
    "error": false,
    "totalCount": 42,
    "currentPage": 0,
    "currentLimit": 2
  }
}

data is the list of objects on this page. Among other things, meta contains totalCount, the number of all matches across all pages. The response is shortened, see Paging and match count for all information in meta.

What happens along the way

POST /crm/customer/query
  1. 1
    Client→CDMS
    sends response and parameter
  2. 2
    CDMS
    resolves the response into fields. If it is missing → 400
  3. 3
    CDMS
    checks the read role of customer. If it is missing → 403 missing-permission|customer-read
  4. 4
    CDMS
    combines your filter tree with AND with the filters that always run along: own data, attribute filters, required filters
  5. 5
    CDMS→Database
    counts the matches, determines the page and reads the requested columns
  6. 6
    CDMS→Client
    returns data and meta

A search needs the same read role as reading a single object. The endpoint exists only if the model enables it, see Which endpoints a model has.

All variants

From a simple to a complete request

When: You want to see everything, for example to try things out.

{ "response": ["id", "name"] } returns all visible objects, unsorted, without pages.

Result: All matches at once. Not suitable for large tables.

When: You are looking for specific objects.

"parameter": { "query": { "type": "AND", "filter": [{ "key": "city", "value": "Köln", "param": "EQ" }] } }

Result: Only the customers from Köln.

When: The order matters, for example in a table.

"order": [{ "field": "name", "order": "ASC" }]

Result: Alphabetical by name.

When: A table shows 25 rows per page.

"page": 0, "limit": 25 for the first page, "page": 1 for the second.

Result: At most 25 objects, plus totalCount for the page bar.

When: Production.

Filter with an explicit type, sorting, page and limit, and in response only the fields that the UI shows.

Result: Stable, fast and predictable.

Pitfalls

Sources in the code and the knowledge base
  • CDMS/cdms-rest-api – RestListPayload, AbstractRestApi.queryObjects
  • CDMS/cdms-commons – ListSearchParameter, ListSearchLogic, ListSearchFilter, ListOrderLogic
  • CDMS/cdms-system-layer – AbstractLayer.recursiveQuery, buildSearchRoot
  • documentation/05-api-guide/05-suchen.md
Search