Talk:REST

From Request Tracker Wiki
Revision as of 10:22, 14 June 2016 by Admin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.


Hi everyone,

I'm trying to build a script that can report on multiple queues. I've gotten it to work for one single queue, but it returns an empty list when I try it on multiple queues at the same time. What am I missing?


   #!/usr/bin/env python3
   # -*- coding: utf-8 -*-
   
   import rt
   from credentials import *  # Contains rturl, rtuser, rtpass
   
   rtsystem = rt.Rt(rturl, rtuser, rtpass)
   queues = ['queue_a', 'queue_b', 'queue_c']
   states = ['Open', 'New', 'Stalled']
   
   def build_query():
       queues_part = "(Queue='{}')".format("'+OR+Queue='".join(queues))
       states_part = "(Status='{}')".format("'+OR+Status='".join(states))
       query_items = [queues_part, states_part]
       raw_query = ("+AND+".join(query_items))
       return raw_query
   
   
   def gettickets():
       try:
           rtsystem.login()
           tickets = rtsystem.search(raw_query=build_query())
           print('----->',tickets)
   
       except Exception as login_err:
           print('===> Failed to retrieve tickets. Reason:\n', str(login_err))
   
       finally:
           rtsystem.logout()
   
   
   if __name__ == '__main__':
       # to check query for errors
       print(build_query())
       # prints: (Queue='queue_a'+OR+Queue='queue_b'+OR+Queue='queue_c')+AND+(Status='Open'+OR+Status='New'+OR+Status='Stalled')
   
       # should return all new, open and stalled tickets in queue_a,b,c
       gettickets()
       # prints: []

 

If I use this query the results are as expected (so that would rule out connection of credential problems):


       tickets = rtsystem.search(Queue='queue_a', raw_query="(Owner='nobody')+AND+(Status='Open'+OR+Status='New'+OR+Status='Stalled')")

 

Anyone?