Using the API to aggregate customer emails
Publicado 17 feb 2021
Hi,
I am trying to search by tickets, find submitter_id from results, and compare it to users id to print out their respective emails.
I currently have the code together for it, but it only works for smaller results.
Bigger results spit back a 422 error.
Let me know if there are any good guides on similar queries.
# imports
import requests
# my authorization credentials
credentials = 'user', 'pw'
session = requests.Session()
session.auth = credentials
zendesk = 'https://xxx.zendesk.com/'
# query for tix
url = zendesk + '/api/v2/search.json?query=test123'
topic_posts = []
while url:
response = session.get(url)
if response.status_code != 200:
print('Error with status code {}'.format(response.status_code))
exit()
data = response.json()
topic_posts.extend(data['results'])
url = data['next_page']
# pull submitter_id's
newlist1 = []
for post in topic_posts:
newlist1.append(post['submitter_id'])
url = zendesk + '/api/v2/users.json'
topic_posts2 = []
while url:
response = session.get(url)
if response.status_code != 200:
print('Error with status code {}'.format(response.status_code))
exit()
data = response.json()
topic_posts2.extend(data['users'])
url = data['next_page']
# pull emails from user list
for post in topic_posts2:
if post['id'] in newlist1 and post['id'] != 'None':
print(post['email'])
0
2 comentarios
Bot
This is super helpful. I was under the belief that whileURL successfully looped through all pages, so thank you for informing me of the limitation. Will explore these articles and follow up if I have any questions. Thank you so much! Andriy
0
Leafworks Test Team
Hello Cooper,
I can imagine your script breaks because Search API has a limit of 1000 results. So, when your url variable became api/v2/search?query=test123&page=11 it breaks(page=10 is max allowed). To deal with it you basically have the next options:
I'm not 100% sure if (2) is going to help, because I haven't worked with it yet. (3) should work for huge results, but it would require a more complex and completely different approach. See this page for more info.
1
Iniciar sesión para dejar un comentario.