Filter query results

Overview

It's important that when we query the API, we recieve the exact data we want without needing to do any manipulation locally. To achieve this, you can query the TilliT API to paginate, sort, filter and include relations of entities.

Pagination

By default every GET request will only retrieve the first 20 entries. We can change this by instead changing the request to include the size param, see the following example

request('/core/assets?size=2', 'GET')

We can then combine this with page to get the next two results after the initial 'page'. The prior query is equivalent to page=0

request('/core/assets?size=2&page=1', 'GET')

Sorting

By default every GET request will retrieve the results sorted by id in ascending order. To change this, you can use the sort param to change this.

request('/core/assets?sort=id,DESC', 'GET')

We can also sort by any other field inside entity. For an Asset this can be any of the following

id,
createdAt,
updatedAt,
name,
displayOrder,
defaultRunRate,
packml,
type,
representsLinePerformance,
representsLineProduction,
allowMultipleOrders,
active,
site (only by id),
assetClass (only by id),
uom (only by id)

It is important to note you can only sort by one field at a time.

Filter Where

A query can be filtered by any field in the entity. To do so, simply join the field name with the type of filter seperate by a dot. See below for an example to find all Assets with name like 'Filler'

request('/core/assets?name.contains=Filler', 'GET')

A full list of query filters and examples can be found below

equals - request('/core/assets?name.equal=Filler', 'GET')

contains - request('/core/assets?name.contains=Filler', 'GET')

greaterThan - request('/core/assets?id.greaterThan=5', 'GET')

lessThan - request('/core/assets?id.lessThan=5', 'GET')

greaterOrEqualThan - request('/core/assets?id.greaterOrEqualThan=5', 'GET')

lessOrEqualThan - request('/core/assets?id.lessOrEqualThan=5', 'GET')

in - request('/core/assets?name.in=Filler,Depal,Pal,Line', 'GET')

isNull - request('/core/assets?name.isNull', 'GET')

isNotNull - request('/core/assets?name.isNotNull', 'GET')

between - request('/core/assets?id.between=5,20', 'GET')

Expand Relations

There are times that we need to know how an entity relates to anothers, for example when we query assets we do not recieve the site, assetClass and uom. We can add the expand param to a query to retrieve them. You cannot expand nested relations.

request('/core/assets?expand=site,assetClass,uom', 'GET')

### Example Response
[{
    id: 1,
    createdAt: '2020-12-14T04:49:27.214Z',
    updatedAt: '2021-11-01T04:06:43.607Z',
    name: 'Line 1',
    displayOrder: 1,
    defaultRunRate: 1200,
    packml: true,
    type: 'LINE',
    assetClass: {
      id: 1,
      createdAt: '2020-12-14T04:49:27.057Z',
      updatedAt: '2020-12-14T04:49:27.057Z',
      name: 'Lines'
    },
    uom: {
      id: 1,
      createdAt: '2020-12-14T04:49:27.097Z',
      updatedAt: '2020-12-14T04:49:27.097Z',
      name: 'Crates',
      description: null
    },
    site: {
      id: 1,
      createdAt: '2020-12-14T04:49:27.159Z',
      updatedAt: '2022-05-24T02:45:26.660Z',
      name: 'Bottling site 1',
      displayOrder: 1,
      timezone: 'Australia/Adelaide'
    },
    representsLinePerformance: false,
    representsLineProduction: false,
    allowMultipleOrders: false,
    active: true
  }
]

Last updated