Use the RequestOptions
object to define filtering and sorting criteria for an endpoint,
then pass the object to your endpoint as a parameter.
You can use the TSC library to filter and sort the following endpoints:
For the above endpoints, you can filter or sort on the following fields:
Important: Not all of the fields are available for all endpoints. For more information, see the REST API help.
To filter on a field, you need to specify the following criteria:
The operator that you want to use for that field. For example, you can use the Equals operator to get everything from the endpoint that matches exactly.
The operator can be any of the following:
The value that you want to filter on. This can be any valid string.
The following code displays only the workbooks where the name equals Superstore:
req_option = TSC.RequestOptions()
req_option.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name,
TSC.RequestOptions.Operator.Equals,
'Superstore'))
matching_workbooks, pagination_item = server.workbooks.get(req_option)
print(matching_workbooks[0].owner_id)
To sort on a field, you need to specify the direction in which you want to sort.
This can be either Asc
for ascending or Desc
for descending.
The following code sorts the workbooks in ascending order:
req_option = TSC.RequestOptions()
req_option.sort.add(TSC.Sort(TSC.RequestOptions.Field.Name,
TSC.RequestOptions.Direction.Asc))
matching_workbooks, pagination_item = server.workbooks.get(req_option)
for wb in matching_workbooks:
print(wb.name)