Sorting

When getting items via the Gtmhub REST API, you can sort the response by any of its properties. Common use cases are to sort the response by creation date, name, or id.

If an endpoint supports sorting, the default sort criteria and available fields to sort by will be specified in the endpoint documentation.

To sort your response, pass a sort query parameter in your request URL and specify the name of the property you want to sort by.

Example:

  • To sort a list of Objectives by their created date use:
`GET` https://app.(us.)gtmhub.com/api/v1/goals?sort=dateCreated
  • If you want to sort the Objectives by Attainment (0-100%), use:
`GET` https://app.(us.)gtmhub.com/api/v1/goals?sort=attainment

If you want to sort in reverse order, add a minus sign in front of the property you are sorting by.

Example:

  • To sort a list of Objectives by name (A-Z), use:
`GET` https://app.(us.)gtmhub.com/api/v1/goals?sort=name
  • To sort a list of Objectives by name (Z-A), use:
`GET` https://app.(us.)gtmhub.com/api/v1/goals?sort=-name

You can also combine sorts to have one property sorted normally, and the other sorted in reverse.

Example:

Gtmhub API V2 - the above examples for Sorting will work with Gtmhub API V2 for a cleaner response. However, you should always check the specific endpoint documentation to determine V2 compatibility.