Search Export API is outputting incorrect records | Community
Skip to main content

Search Export API is outputting incorrect records

  • December 8, 2022
  • 1 reply
  • 0 views

Allen13

Can somebody help me with my code please. Using search export api, I'm trying to export tickets based on form id and specific updated date. However I'm getting tickets results that does not meet my updated date criteria. 

YESTERDAY   = datetime.combine(date.today(), datetime.min.time()) - timedelta(days=1)


base_url = f"https://{subdomain}.zendesk.com/api/v2"
search_query = "form:5566232321& updated>=" + end_time_str + "&page[size]=100&filter[type]=ticket"
search_url = base_url + "/search/export?query=" + search_query

tickets = []
while True:
    # Set the headers for the API call
    headers = {
        "Content-Type": "application/json",
        "Accept": "application/json",
    }

    # Set the authentication for the API call
    auth = (username, token)

    # Make the API call
    response = requests.get(search_url, headers=headers, auth=auth)

    # Check the status code of the response
    if response.status_code != 200:
        print(f"Failed to search tickets: {response.status_code}")
        break

    # Parse the response data
    data = response.json()

    # Iterate over the results
    # for result in data['results']:
    #     # Process the result here
    #     tickets.append(result)

    # Check if there are more pages of results
    if data['links']['next'] is None:
        # There are no more pages, so break out of the loop
        break
    else:
        search_url = data['links']['next']

1 reply

Hi Allen,
 
Can you double check your end_time_str value to make sure the date is in the format that search is expecting?