1

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.

5
  • Do the ZenPy docs say what type of argument .search() takes? Will it take a list? have you tried to get it to work with a single item from test_list, without the loop? Commented May 8, 2018 at 21:11
  • Well, that would just make too much sense. Got so caught up in it I didn't try it at its most basic. So if I have just a variable in .search it works perfectly. But if I use a list (even a list containing a single item) it gives me TypeError: sequence item 0: expected str instance, list found. Any idea how to get around that kind of limitation? Commented May 9, 2018 at 12:22
  • If you pay attention to the error messages they usually give you a pretty good hint at the problem. That coupled with the successful test you did with a single string should make it clear. Commented May 9, 2018 at 13:43
  • FYI, the tickets endpoint will accept a list of ids: zenpy_client.tickets(ids=[6151, 6152, 6153, 6154, 6155, 6156, 6157]) Commented May 20, 2018 at 5:55
  • Thanks much facetoe! Didn't even realize that was an option and thats probably much more efficient. Thanks a ton for zenpy, has made my life much easier. Commented May 21, 2018 at 12:35

1 Answer 1

1

.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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.