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'
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.