Chuyển tới nội dung chính

OData Filter

Query Parameter

eTask REST interface uses OData’s expression to provide filters in many of its query. eTask REST API supports the following OData operators:

NameDescriptionExample
$countRetrieves the total count of matching resources./api/tasks?$top=20&$count=true
$filterFilters results (rows)./api/tasks?$filter=(status eq 'Not Started')
$selectFilters properties (columns)./api/tasks?$select=name,priority&$top=10
$orderbyOrders results./api/tasks?$orderby=internalId desc
$skipIndexes into a result set. Also used by some APIs to implement paging and can be used together with $top to manually page results./api/tasks?$skip=11
$topSets the page size of results./api/tasks?$top=20&$count=true

Filter Expressions

eTask REST Endpoint currently support the following OData filter expressions:

NameExamples
Equal$filter=(status eq 'Not Started') Query on list of tasks. Return tasks that have status field is Not Started
Less than$filter=(startDate lt '$date:2020-09-17T16:59:59Z') Query on list of tasks. Return tasks that have startDate less than 2020-09-17T16:59:59Z
Greater than$filter=(startDate gt '$date:2020-09-17T16:59:59Z') Query on list of tasks. Return tasks that have startDate greater than ‘2020-09-17T16:59:59Z’
Greater than or equal to$filter=(internalId ge 5) Query on list of tasks. Return tasks that have internalId greater than or equal to 5
Less than or equal to$filter=(internalId le 5) Query on list of tasks. Return tasks that have internalId less than or equal to 5
Select a range of values$filter=(createdAt ge '$date:2020-09-01T17:00:00Z' and createdAt le '$date:2020-09-09T16:59:59Z') Query on list of tasks. Return tasks that have createdAt greater than or equal to 2020-09-01T17:00:00Z and less than or equal to 2020-09-09T16:59:59Z
And$filter=(priority eq 'High') and (status eq 'Not Started') Query on list of tasks. Return tasks that have status is 'Not Started' and priority is 'High'
Or$filter=(status eq 'Not Started' or status eq 'In Progress') Query on list of tasks. Return tasks that have status is 'Not Started' or 'In Progress'.
substringof$filter =(substringof('API', name)) Query on list of tasks. Return tasks records that have name with names containing the string 'API'.

Notes:

  • String value must pass in single quotation.
  • Numeric value does not require any delimiters.
  • Date time value must pass in single quotation and must preceded by the word datetime for example datetime'2016-04-25T05:16:43.1354695Z'.

Additional reference on OData expression are here: Using Filter Expression in Odata