Extract only the issuekeys from REST API output

Rahul Aich [Nagra]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 15, 2015

Hi All

I got this response from REST API(see below). I want to extract TES-7 and TES-8 (i.e. the issuekeys) only into another file (for further scripting)

How do you think i can achieve this? Any ideas?

Rahul

 

{"expand":"schema,names","startAt":0,"maxResults":50,"total":2,"issues":[{"expan
d":"operations,editmeta,changelog,transitions,renderedFields","id":"10100","self
":"http://localhost:2990/jira/rest/api/2/issue/10100","key":"TES-8"},{"expand":"
operations,editmeta,changelog,transitions,renderedFields","id":"10006","self":"h
ttp://localhost:2990/jira/rest/api/2/issue/10006","key":"TES-7"}]}
C:\rest>

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Matheus Fernandes
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 30, 2015

That really depends on how you are retrieving that. You could use any number of tools to get and parse the data. For example, using Python's standard library you could do:

import urllib2
import base64
import json

#Credentials
username='matheus'
password='nopass'
#Hash Password
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')

url = 'http://myjirainstance.com/jira/rest/api/2/search?jql=Project=BONS&fields=summary'

request = urllib2.Request(url)
request.add_header("Authorization", "Basic %s" % base64string)

response = json.loads(urllib2.urlopen(request).read())['issues']
for issue in response:
    print issue['key']

But you can do it in a number of different ways smile

0 votes
ChandraG October 5, 2015

Matheus, Could you pls help to extract issuetype & status as well from response.

url = https://jira.test.com/rest/api/2/search?jql=issue=mdm-2300&fields=issuetype,status

response which i am getting --

{"expand":"names,schema","startAt":0,"maxResults":50,"total":1,"issues":[{"expand":"editmeta,renderedFields,transitions,changelog,operations","id":"201031","self":"https://jira.uk.fid-intl.com/rest/api/2/issue/201031","key":"MDM-2300","fields":{"issuetype":{"self":"https://jira.uk.fid-intl.com/rest/api/2/issuetype/13","id":"13","description":"A technical task.","iconUrl":"https://jira.uk.fid-intl.com/images/icons/issuetypes/task_agile.png","name":"Technical task","subtask":true},"status":{"self":"https://jira.uk.fid-intl.com/rest/api/2/status/6","description":"The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.","iconUrl":"https://jira.uk.fid-intl.com/images/icons/statuses/closed.png","name":"Closed","id":"6","statusCategory":{"self":"https://jira.uk.fid-intl.com/rest/api/2/statuscategory/3","id":3,"key":"done","colorName":"green","name":"Complete"}}}}]}

Need to get value of issuetype & status for further reporting as in this case type is "Technical task" & status is "closed".

TAGS
AUG Leaders

Atlassian Community Events