Reputation: 19
this might be a bit specific and I know it's related to the fact that my python training is all self taught. I'm trying to use a wrapper called Zenpy to make some API calls for me. Specifically, I have a list of ticket ids. I'm trying to run a search for each ticket id, save the data into a variable, then print the variable (ultimately do a lot more with the data in the variable, but for my purposes they're the same). Trouble is my script is working, but I think it's failing to do the search. Here's my code:
from datetime import datetime, timedelta
creds = {
'email': 'redacted',
'token': 'redacted',
'subdomain': 'redacted'
yesterday = datetime.now() - timedelta(days=20)
today = datetime.now()
from zenpy import Zenpy
zenpy = Zenpy(**creds)
print('Connected to Zendesk')
test_list = ['12345',
'12346',
'12347',
'12348',
'12349',
'12350',
'12351',
'12352'
]
for ticket in zenpy.search(test_list):
id = ticket.id
print(id)
I imagine it's something to do with how the API is making the call and how its parsing a list (have also tried it as a dict and the results were the same) but no idea what to do. Have also tried zenpy.search(id=test_list) without any success.
Upvotes: 1
Views: 998
Reputation: 23753
.search()
takes a single string for its search term. Iterate over the list and make multiple searches.
for thing in test_list:
ticket = zenpy.search(thing)
id = ticket.id
print(id)
Upvotes: 1