Ordering results

As well as using queries to limit response data, you can also use the orderBy parameter to specify the order of records in the response.

Ascending order

By default, results are returned in ascending order. For example, if you want to return a list of invoices in ascending order, oldest first, use the following syntax: {parameter}={value}. In this case, orderBy=issueDate.

GET /companies/{companyId}/data/invoices?page=1&orderBy=issueDate

Descending order

To return results in descending order you simply prepend a - to the parameter value. For example, to return the same list of invoices, this time with the newest invoice first, use the following syntax: orderBy=-issueDate.

GET /companies/{companyId}/data/invoices?page=1&orderBy=-issueDate

Ordering results from a custom query

You can also order the results returned by any custom queries that you've written. For example, you might regularly run a query that returns all outstanding bills:

GET /companies/{companyId}/data/bills?query=amountDue%3E0

To see the same list in ascending order, that is the oldest outstanding bills first, you add the following syntax: orderBy=dueDate. The query becomes:

GET /companies/{companyId}/data/bills?query=amountDue%3E0&orderBy=dueDate

To see the same list in descending order, that is the newest outstanding bills first, prepend - to the parameter value dueDate:

GET /companies/{companyId}/data/bills?query=amountDue%3E0&orderBy=-dueDate

Did this page help you?