Pagination in ticket_fields | Community
Skip to main content

Pagination in ticket_fields

  • February 13, 2024
  • 2 replies
  • 0 views

Can you confirm if pagination is properly implemented for the ticket fields endpoint or not? In my case, I get a count of 102. This means that when I query page 1, I should get 100 items and when I query page 2, I should get 2 items. Similarly, when I query page 3, I shouldn't get anything. 

However, currently, when I query page 1, I get 102 items instead of 2. Even if I query a random number let's say page # 80, I still get 102 items. Is this behavior expected? 

The behavior for other endpoints seem to work okay. It's just this one endpoint that's creating an issue.

2 replies

Greg29
  • February 15, 2024

Hi there! If you check our documentation, you'll see that we recommend using cursor-based pagination for this endpoint (and probably most of our endpoints). To get results in the way that you're expecting, you'll need to use the following syntax: `yoursubdomain.zendesk.com/api/v2/ticket_fields?page[size]=100`


Tomas19
  • February 29, 2024

Hi Developer1234,

I do not know which programming language are you using but if you use Python, the following script will create a csv file with all you ticket fields no matter how many pages you have:

import requests
import pandas as pd

credentials = (email,token)

url = f"https://{zendesk}.zendesk.com/api/v2/ticket_fields"

ticket_fields = []

while url:
    response = requests.get(url,auth=credentials)
    data = response.json()
    df = pd.DataFrame(data['ticket_fields'])
   ticket_fields.append(df)
    url = data['next_page']
    
ticket_fields_final = pd.concat(ticket_fields)

ticket_fields_final.to_csv('ticket_fields.csv')