Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Praveen July 7, 2013

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
Dipti Ranjan Behera
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.
July 7, 2013

@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.

Praveen July 7, 2013

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.

Nitram
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.
July 7, 2013

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

Nitram
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.
July 7, 2013

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" } }

1 vote
Nitram
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.
July 7, 2013

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.

Nitram
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.
July 7, 2013

Hi,

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

Nitram
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.
July 7, 2013

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

Praveen July 7, 2013

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.

0 votes
Nitram
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.
July 7, 2013

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() );

0 votes
Praveen July 7, 2013

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.

0 votes
Nitram
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.
July 7, 2013

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
AUG Leaders

Atlassian Community Events