python - Querying JIRA via REST API and possible bad values in query -


i have portal users can access built on cherrypy has forms can submitted sent jira via rest api tracking purposes. once has been submitted take information user supplied information on form , jira issue id , send them oracle db.

as well, extended functionality of portal able view user submissions via list page , select record view stored in db submission. had idea use rest api jira status , assignee issue within jira. converting code submit api instead query necessary jql statement simple , can seen below.

def jira_status_check(jira_id): if jira_id != "no jira issue":     try:         search_url = "https://myjirainstance.atlassian.net/rest/api/2/search/?jql=issue=" + jira_id + "&fields=status,assignee,resolution"         print search_url         username = 'some_user'         password = 'some_password'         request = urllib2.request(search_url)         base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')         request.add_header("authorization", "basic %s" % base64string)         request.add_header("content-type", "application/json")         result = urllib2.urlopen(request).read()         json_results = json.loads(result)         print json_results         jira_status = json_results["issues"][0]["fields"]["status"]["name"]         if json_results["issues"][0]["fields"]["resolution"] none:             tmp = "tmp"         if json_results["issues"][0]["fields"]["resolution"] not none:             jira_status = jira_status + " - " + json_results["issues"][0]["fields"]["resolution"]["name"]         # assignee_name = "test"         # assignee_nt = "test"         if json_results["issues"][0]["fields"]["assignee"] none:             assignee_name = "unassigned"             assignee_nt = "unassigned"         if json_results["issues"][0]["fields"]["assignee"] not none:             assignee_name = json_results["issues"][0]["fields"]["assignee"]["displayname"]             assignee_nt = json_results["issues"][0]["fields"]["assignee"]["name"]         # if json_results["issues"][0]["fields"]["assignee"]["displayname"] not none:         #     assignee_name = json_results["issues"][0]["fields"]["assignee"]["displayname"]         # if json_results["issues"][0]["fields"]["assignee"] none:         #     assignee_nt = "unassigned"         # if json_results["issues"][0]["fields"]["assignee"]["name"] not none:         #     assignee_nt = json_results["issues"][0]["fields"]["assignee"]["name"]         print jira_status         print assignee_name         print assignee_nt         output = [jira_status, assignee_name, assignee_nt]     except:         jira_status = "no jira issue number or jira inaccessible"         assignee_name = "no jira issue number or jira inaccessible"         assignee_nt = "no jira issue number or jira inaccessible"         output = [jira_status, assignee_name, assignee_nt] else:     jira_status = "no jira issue"     assignee_name = "no jira issue"     assignee_nt = "no jira issue"     output = [jira_status, assignee_name, assignee_nt] return output 

however limited searching single record @ time, works when viewing single record, hoping extend possibly list page , searching many @ once 1 api query rather tons of single issue queries. capable of using jql , rest api search multiple issue numbers @ link https://myjirainstance.atlassian.net/rest/api/2/search/?jql=issue%3dspl-3284%20or%20issue%3dspl-3285&fields=status,assignee,resolution

but thinking if somehow bad issue id saved , queried part of massive query. handled except statement in jira_status_check function when single record query. when try query rest api link last 1 shared instead

 {"errormessages":["an issue key 'spl-6666' not exist field 'issue'."],"warningmessages":[]} 

i tried build query advanced search of issues when issue=spl-3284 or issue=spl-3285 or issue=spl-6666 response of an issue key 'spl-6666' not exist field 'issue'.

is there correct way search via jql multiple issue numbers , give no values fields ones without matching issue numbers?

or stuck doing ton of single issue queries api cover bases? less ideal, , might cause me limit api queries when single record viewed rather list page usability.

would better off moving function query jira javascript/jquery can populate list of submissions after page rendered?

i ended reaching out atlassian question jql , given following rest api documentation , told validatequery parameter add jql achieve search. https://docs.atlassian.com/jira/rest/6.1.7/

when use query similar on rest api link additional parameter

jql=issue%3dspl-3284 or issue%3dspl-3285&fields=status,assignee,resolution&validatequery=true

i json actual content issues valid , separate warningmessages object bad. example json below, $content actual results query

{   "expand": "schema,names",   "startat": 0,   "maxresults": 50,   "total": 2,   "issues": [     {       $content     },     {       $content     }   ],   "warningmessages": [     "an issue key 'spl-6666' not exist field 'issue'."   ] } 

hopefully else find helpful in future


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -