Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,298,354
Community Members
 
Community Events
165
Community Groups

Can anyone let me know if I can re open an incident using JIRA REST API

Hi,

I need to re-open an incident from my application using JIRA REST API. Can any one help me on this?

Any help regarding the same is highly appreciated.

Regards

Praveen.

5 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted

@praveen ,

To re-open an issue via code, you need to do two things

1. Ensure the workflow has a transition from closed to open/reopened/whereever

2. Run the workflow transition.

through jira rest api :

/rest/api/2/issue/{issueIdOrKey}/transitions?expand=transitions.fields

transistions.field is used if any field is configured in transition.

Hi Nitram/ Dipti,

When I give the url as http:<servername>/rest/api/2/issue/JIRA-1000/transitions?expand=transitions.fields in the browser it has me returned me a json like this.

{"expand":"transitions","transitions":[]}

Does this means there are no fields I can set? How can I add fields to the transition screen?

Regards

Praveen.

I will post a sample code if you are new to rest, wait for few mins

HI,

jus give this much to get the transitions of that issue

/rest/api/2/issue/{issueIdOrKey}/transitions

once you got the transitions, you will come to know whether the issue is capable of re-opening.

then if you want to do a post call, then supply a data like this to your post call request, then it will update JIRA and will give you a response

{ "update": { "comment": [ { "add": { "body": "Bug has been fixed." } } ] }, "transition": { "id": "5" } }

Hi @Praveen,

Please look into this link, https://docs.atlassian.com/jira/REST/latest/#idp1811072

This will help you.

You need to call the correct transition, then you will be able to reopen the incident.

Hope this helps.

Hi,

/rest/api/2/issue/{issueIdOrKey}/transitions?expand=transitions.fields, this is a post call

POST

Perform a transition on an issue. When performing the transition you can udate or set other issue fields.

The fields that can be set on transtion, in either the fields parameter or the update parameter can be determined using the /rest/api/2/issue/{issueIdOrKey}/transitions?expand=transitions.fields resource. If a field is not configured to appear on the transition screen, then it will not be in the transition metadata, and a field validation error will occur if it is submitted.

acceptable request representations:

  • application/json<abbr title="{http://research.sun.com/wadl/2006/10} "></abbr> [collapse]
    <h6>Example</h6>
    { "update": { "comment": [ { "add": { "body": "Bug has been fixed." } } ] }, "fields": { "assignee": { "name": "bob" }, "resolution": { "name": "Fixed" } }, "transition": { "id": "5" } }

available response representations:

  • 204<abbr title="{http://research.sun.com/wadl/2006/10} "></abbr> [collapse]

    Returned if the transition was successful.

  • 400<abbr title="{http://research.sun.com/wadl/2006/10} "></abbr> [collapse]

    If there is no transition specified.

  • 404<abbr title="{http://research.sun.com/wadl/2006/10} "></abbr> [collapse]

    The issue does not exist or the user does not have permission to view it

Hi Nitram,

Thanks for the quick response. I've tried this, but when I try to open the link (http:<servername>/rest/api/2/issue/JIRA-1000/transitions?expand=transitions.fields " from browser it says "Unable to download transitions from blrkec6347s. Unable to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later".

When I try to invoke the Url from my code by creating an object of HTTP web request it's failing with the below error.

"invalid uri the authority/host could not be parsed"

The code i'm using to create the HTTP web request object is as below.

HttpWebRequest request = WebRequest.Create(url) asHttpWebRequest;

where url is as above.

Can you let me know what i might be missing?

Thanks and Regards

Praveen.

Check this solution,

use REST::Client;
use MIME::Base64;
use JSON ;

#username and password
my $user = 'username';
my $pass = 'password';

#The basic use case
my $client = REST::Client->new();

#A host can be set for convienience
$client->setHost('url');

my $headers = { Authorization => 'Basic '. encode_base64($user . ':' . $pass)};

my $jsonparams ={ "update": { "comment": [ { "add": { "body": "Bug has been fixed." } } ] }, "transition": { "id": "5" } };

$client->Post( '/rest/api/2/issue/JIRA-1000/transitions',$jsonparams , $headers );

if( $client->responseCode() eq '200' ){
print "Updated\n";
}

# print the result
print $client->responseContent() . "\n";


# to convert the data into a hash, use the JSON module
my $res_data = from_json( $client->responseContent() );

Hi Nitram,

Thanks for clarifying me. This is what exactly I'm doing, but I've posted only one line of my code. Any idea why i'm getting that "invalid uri the authority/host could not be parsed" error.

Regards

Praveen.

Hi,

Actually from a browser you will not be able to call a post method without sending any data whatever it needs, thats why you are getting error, from your code if your trying then you need to do the following,

I have tried the rest-api using perl

So what I did is

1) I sent my username and password and I encoded it,

2) I set the url

3) using the client I called the respective post by sending the data in json format.

4) I received a response from my server.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

181 views 1 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you