Feb-02-2021, 04:57 AM
(This post was last modified: Feb-02-2021, 10:41 PM by frankenchrist.)
Hi,
I have gotten a script to pull in new helpdesk tickets from Zendesk and display then in a terminal window (Ubuntu). It pulls the information without any issue but what I need to it do is refresh the data in the same session so for every minute, it will display any new tickets that have been requested by staff.
This is the code that I have that works:
Another method I hacked together was while True statement, something along the lines of:
I hope this makes sense and helps.
Cheers
I have gotten a script to pull in new helpdesk tickets from Zendesk and display then in a terminal window (Ubuntu). It pulls the information without any issue but what I need to it do is refresh the data in the same session so for every minute, it will display any new tickets that have been requested by staff.
This is the code that I have that works:
from urllib.parse import urlencode import requests import os os.system('clear') credentials = 'zendesk_email' + '/token', 'zendesk_token' session = requests.Session() session.auth = credentials params = { 'query': 'type:ticket status:new', 'sort_by': 'created_at', 'sort_order': 'desc' } url = 'https://subdomain.zendesk.com/api/v2/search.json?' + urlencode(params) response = session.get(url) if response.status_code != 200: print('Status:', response.status_code, 'Problem with the request. Exiting.') exit() # Print the subject of each ticket in the results data = response.json() for result in data['results']: print(result['subject'])Now, I have played around with a couple of ways to refresh the content in the script in real time. I entered these at the bottom of the above coding in the same script. One was to reload the script as a module:
import open_tickets import importlib import time importlib.reload(open_tickets) time.sleep(60)Now that sort of worked, as it would reload the script, but it wouldn't update the content when a new ticket is requested by a user.
Another method I hacked together was while True statement, something along the lines of:
while True: print(result['subject']) time.sleep(60) os.system('clear')I need the script to reload the data automatically and in real time and display any new helpdesk ticket everytime one has been create.
I hope this makes sense and helps.
Cheers