Lists Requests API with Cursor Paginatoin not sorting | The place for Zendesk users to come together and share
Skip to main content
November 20, 2024
Question

Lists Requests API with Cursor Paginatoin not sorting

  • November 20, 2024
  • 3 replies
  • 35 views

Hi, 

 

I'm using the List Requests API as documented here: https://developer.zendesk.com/api-reference/ticketing/tickets/ticket-requests/#list-requests

 

When I use cursor pagination and attempt to sort the request the response is not sorted. If I make the same request with offset pagination it sorts fine. 

 

The documentation mentions that the sort operations are supported and makes no mention of pagination types affecting the sort operations; it even recommends using cursor pagination over offset pagination.

 

Here's the request I'm making: {{baseUrl}}/api/v2/requests.json?sort_by=updated_at&sort_order=desc&page[size]=5

 

And the response with only the relevant data:

{
  "requests": [
    {
      "updated_at": "2024-11-06T16:15:28Z"
    },
    {
      "updated_at": "2024-11-06T16:17:21Z"
    },
    {
      "updated_at": "2024-11-06T16:14:44Z"
    },
    {
      "updated_at": "2024-11-01T20:12:45Z"
    },
    {
      "updated_at": "2024-11-15T22:23:45Z"
    }
  ],
  "meta": {
    "has_more": true,
    "after_cursor": "...",
    "before_cursor": "..."
  }
}

As you can see the updated_at fields are in random order. Changing the sorting field does not change the order of the response in any way.

 

Is the documentation not accurate? Or is this a bug? 

3 replies

Employee
November 27, 2024
Hi Terry,
 
Thanks for pointing this out.  To sort when using cursor-based pagination use the sort parameter instead:
 
{{baseUrl}}/api/v2/requests.json?page[size]=5&sort=updated_at
 
We detail this in Comparing cursor pagination and offset pagination, but we need to make it more clear in the endpoint specific docs.
Terry14Author
December 2, 2024

Thanks that works! 

 

Is updated_at the only supported sort field? I've tried created_at but get the following error

{
    "error": "InvalidPaginationParameter",
    "description": "sort is not valid"
}

 

 

March 24, 2025

Is it possible to specify sort_order with cursor pagination? Asc/Desc.