Skip to content

Custom columns

Krzysztof Słysz edited this page Dec 8, 2021 · 7 revisions

Columns

This configuration is related only with the .../api/bucket/{bucketName}/get endpoint. Sometimes you may want to take only particular properties or fields from data. In such a cases, you can use columns node in the request payload. The columns item is an array of objects with two items:

  • field - a field name, property path or property path with function, e.g. id, tagId, $.name, $.name.exists()
  • title - any string

When the columns item is not defined, we've got full data structure in the response.

Request:

{
  "rules": [
    ["id", ">", 0]	
  ]
} 

Response:

{
  "page": 1,
  "limit": 1,
  "sort": "id",
  "total": 504,
  "totalPages": 504,
  "data": [
    {
      "id": 1,
      "tagId": 3,
      "reserved": true,
      "owner": "user",
      "properties": {
        "company": "Example company",
        "contact": {
          "email": "[email protected]",
          "phone": "111-111-8927"
        },
        "eyeColor": "blue",
        "lastName": "Lennon",
        "firstName": "John"
      },
      "createdBy": "user",
      "createdAt": "2021-10-05T10:09:41.512Z",
      "modifiedBy": "user",
      "modifiedAt": "2021-10-05T10:09:41.512Z"
    }
  ]
}

Let's define columns to take only id and $.firstName:

Request:

{
  "rules": [
    ["id", ">", 0]	
  ],
  "columns": [
    {
      "field": "id",
      "title": "ID"
    },
    {
      "field": "$.firstName",
      "title": "First name"
    }
  ]
}

Response:

{
  "page": 1,
  "limit": 1,
  "sort": "id",
  "total": 504,
  "totalPages": 504,
  "customData": [
    {
      "ID": 1,
      "First name": "James"
    }
  ]
}

Be aware, that for request with columns, the response data is served in customData item!

Clone this wiki locally