Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to retrieve specific field using Jira Restful API

Jimmy Elsayed January 6, 2018

Hi,

I am using Jira Restful API to get the issue status for a specific issue. the returned JSON object contains a full description if the status (Name, Icon, Description, ...).

How can I get only the StatusID to minimize the network traffic?

1 answer

1 accepted

5 votes
Answer accepted
MoroSystems Support
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.
January 6, 2018

You can use fields property in your GET request:

{JIRA INSTANCE ADDRESS}/rest/api/latest/issue/ISSUE-1?fields=status

where ISSUE-1 is key of the issue.  You will not get only status ID but something like:

{"status":{"self":"https://helpdesk.morosystems.cz/rest/api/2/status/1","description":"Issue is opened","iconUrl":"https://helpdesk.morosystems.cz/images/icons/statuses/open.png","name":"Open","id":"1","statusCategory":{"self":"https://helpdesk.morosystems.cz/rest/api/2/statuscategory/2","id":2,"key":"new","colorName":"blue-gray","name":"To Do"}}}}

I guess response is small enough though :)

 

Martin

Jimmy Elsayed January 8, 2018

Thank you for your feedback. actually this is what I am doing now but it is not efficient if you have 

/rest/api/2/search?jql=project%20=%20ProjectName%20AND%20Application%20=%20ApplicationName&fields=description,issuetype,status

When you have too many results. So I was wondering how to get only the StatusID instead of StatusObject.

Thanks in advance,  

MoroSystems Support
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.
January 8, 2018

Jimmy, I don't think it is possible. The only possibility is to implement custom REST API with one endpoint or I found script runner allows you to implement simple REST API endpoints:

https://scriptrunner.adaptavist.com/latest/jira/rest-endpoints.html#_configuration

Like Boris likes this
Jimmy Elsayed January 8, 2018

It will be the same since the bottleneck is getting data from Jira REST API, so if I implemented my own REST API on top of Jira API, it will be the same since I am still requesting all the information from Jira and ignore what I do not need at my side. it will be more efficient to get what I need only from Jira and not everything.

Do you have any other ideas? 

Nic Brough -Adaptavist-
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.
January 8, 2018

You've misunderstood what the REST endpoint in ScriptRunner does.  It allows you to write an endpoint that does what you need it to.  You could easily code an endpoint that responds only with the Status ID and nothing else when it is poked with an issue ID.

You don't do any work on your side and a handful of lines of code is going to be far more quick than Jira processing all the fields you ask for and sending back status object you don't want.

Jimmy Elsayed January 8, 2018

Thank you so much for your feedback!

I see you your point! So ScriptRunner is built on top of Jira and I will just use it. however in order for ScriptRunner to work, it has to either consume Jira REST API and truncate the not needed data on its side (in this case it will be useless) or it will have direct access to Jira Database to get only the required information (in this case I will have dependency on Jira Database version and ScriptRunner version).

I was hoping to find something already built in Jira REST API to support this as it does not make sense if I am getting 100 issues with two status, I receive the same object for all the 100 issues. I can just get the StatusID and do the mapping at my end.

 

Thanks,

Nic Brough -Adaptavist-
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.
January 8, 2018

Not quite, it's neither of those approaches.  ScriptRunner is an add-on that works within the core of Jira.  One of its functions is to provide REST end points.  You write code that uses the internal Java API to get the data you need when something pokes that REST endpoint. 

Your code is dependent on Jira and  ScriptRunner versions, but it's generally quite stable - the last time I had to rewrite my code was because of the significant refactoring Atlassian did between Jira 6 and 7.

It might make sense for your end point to accept a set of issue IDs and respond with something structured like "status 1, these X issues, status 2, these Y issues, etc".

Jimmy Elsayed January 8, 2018

I appreciate your feedback!

So Jira RET API has no built-in support for such filtration and I have to use additional add-on like ScriptRunner for that? the problem is installing add-on is not that easy at my company and a lot of approvals will be required.

Like Richard Houde likes this
Nic Brough -Adaptavist-
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.
January 8, 2018

No.  The REST API uses "fields=" as you saw earlier to filter down what fields it sends back for each issue.

The reason we've suggested Script Runner is because you want status IDs rather than status objects, and it might be quicker and easier for you to get groups of issues, rather than a flat list.  The built in REST API doesn't do either of those.

Jimmy Elsayed January 8, 2018

Thank you so much for your feedback! Appreciated!!

Martin Bayer January 8, 2018

Thank you Nic, that's what I thought with script runner. Jimmy, you can always implement your own plugin to provide required functionality if it is easier to use in your company but it will require more effort to do it. So I think the script runner is still the easiest solution. 

Martin

Jimmy Elsayed January 8, 2018

Thank you Martin!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events