Talk:REST

From Request Tracker Wiki
Jump to: navigation, search

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
   # -<em>- coding: utf-8 -</em>-

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)

<code><pre>   except Exception as login_err:
       print('===> Failed to retrieve tickets. Reason:\n', str(login_err))

   finally:
       rtsystem.logout()
</pre></code>

if <strong>name</strong> == '<strong>main</strong>':
       # 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')

<code><pre>   # should return all new, open and stalled tickets in queue_a,b,c
   gettickets()
   # prints: []
</pre></code>


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

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

Anyone?