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

changing the status of jira using rest api

ashen shanaka December 31, 2012

Hi

i have built a email client that to integrate with jira

i want to change the status of the selected task using rest. but i cannot do it like i did in changing the summary or the assignee.i know i have to use the transition api. but cannot seems to figure it out. if anyone can help its really appreciated.

this is the code im working on.this is my class jira.php function relating the update issue.

public function updateTransition($issueKey,$json){
$this->request->openConnect('https://'.$this->host.'/rest/api/latest/issue/11090/transitions?', 'POST', $json);
$this->request->execute();

}

and this is how i call it.

$resolution->transition->id="4";
$resolution->transition->id->to->id="3";
$update= array($resolution);

$updateIssue = new Jira($config);
$updateIssue ->updateTransition($query,$update);

what am i doing wrong here please answer.thanks

UPDATE

when i use this url
/rest/api/latest/issue/REC-143/transitions

it returns me with a array of the transitions

stdClass Object
(
    [expand] => transitions
    [transitions] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 4
                    [name] => Start Progress
                    [to] => stdClass Object
                        (
                            [self] => https://eyepax.atlassian.net/rest/api/2/status/3
                            [description] => This issue is being actively worked on at the moment by the assignee.
                            [iconUrl] => https://eyepax.atlassian.net/images/icons/statuses/inprogress.png
                            [name] => In Progress
                            [id] => 3
                        )

                    [fields] => stdClass Object
                        (
                        )

                )

            [1] => stdClass Object
                (
                    [id] => 5
                    [name] => Resolve Issue
                    [to] => stdClass Object
                        (
                            [self] => https://eyepax.atlassian.net/rest/api/2/status/5
                            [description] => A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.
                            [iconUrl] => https://eyepax.atlassian.net/images/icons/statuses/resolved.png
                            [name] => Resolved
                            [id] => 5
                        )

                    [fields] => stdClass Object
                        (
                            [customfield_10300] => stdClass Object
                                (
                                    [required] => 
                                    [schema] => stdClass Object
                                        (
                                            [type] => string
                                            [custom] => com.atlassian.jira.plugin.system.customfieldtypes:textarea
                                            [customId] => 10300
                                        )

                                    [name] => Email ID
                                    [operations] => Array
                                        (
                                            [0] => set
                                        )

                                )

                            [assignee] => stdClass Object
                                (
                                    [required] => 
                                    [schema] => stdClass Object
                                        (
                                            [type] => user
                                            [system] => assignee
                                        )

                                    [name] => Assignee
                                    [autoCompleteUrl] => https://eyepax.atlassian.net/rest/api/latest/user/assignable/search?issueKey=REC-143&username=
                                    [operations] => Array
                                        (
                                            [0] => set
                                        )

                                )

                            [fixVersions] => stdClass Object
                                (
                                    [required] => 
                                    [schema] => stdClass Object
                                        (
                                            [type] => array
                                            [items] => version
                                            [system] => fixVersions
                                        )

                                    [name] => Fix Version/s
                                    [operations] => Array
                                        (
                                            [0] => set
                                            [1] => add
                                            [2] => remove
                                        )

                                    [allowedValues] => Array
                                        (
                                        )

                                )

                            [resolution] => stdClass Object
                                (
                                    [required] => 1
                                    [schema] => stdClass Object
                                        (
                                            [type] => resolution
                                            [system] => resolution
                                        )

                                    [name] => Resolution
                                    [operations] => Array
                                        (
                                            [0] => set
                                        )

                                    [allowedValues] => Array
                                        (
                                            [0] => stdClass Object
                                                (
                                                    [self] => https://eyepax.atlassian.net/rest/api/latest/resolution/1
                                                    [name] => Fixed
                                                    [id] => 1
                                                )

                                            [1] => stdClass Object
                                                (
                                                    [self] => https://eyepax.atlassian.net/rest/api/latest/resolution/2
                                                    [name] => Won't Fix
                                                    [id] => 2
                                                )

                                            [2] => stdClass Object
                                                (
                                                    [self] => https://eyepax.atlassian.net/rest/api/latest/resolution/3
                                                    [name] => Duplicate
                                                    [id] => 3
                                                )

                                            [3] => stdClass Object
                                                (
                                                    [self] => https://eyepax.atlassian.net/rest/api/latest/resolution/4
                                                    [name] => Incomplete
                                                    [id] => 4
                                                )

                                            [4] => stdClass Object
                                                (
                                                    [self] => https://eyepax.atlassian.net/rest/api/latest/resolution/5
                                                    [name] => Cannot Reproduce
                                                    [id] => 5
                                                )

                                        )

                                )

                            [worklog] => stdClass Object
                                (
                                    [required] => 
                                    [schema] => stdClass Object
                                        (
                                            [type] => array
                                            [items] => worklog
                                            [system] => worklog
                                        )

                                    [name] => Log Work
                                    [operations] => Array
                                        (
                                            [0] => add
                                        )

                                )

                        )

                )

            [2] => stdClass Object
                (
                    [id] => 2
                    [name] => Close Issue
                    [to] => stdClass Object
                        (
                            [self] => https://eyepax.atlassian.net/rest/api/2/status/6
                            [description] => The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.
                            [iconUrl] => https://eyepax.atlassian.net/images/icons/statuses/closed.png
                            [name] => Closed
                            [id] => 6
                        )

                    [fields] => stdClass Object
                        (
                            [customfield_10300] => stdClass Object
                                (
                                    [required] => 
                                    [schema] => stdClass Object
                                        (
                                            [type] => string
                                            [custom] => com.atlassian.jira.plugin.system.customfieldtypes:textarea
                                            [customId] => 10300
                                        )

                                    [name] => Email ID
                                    [operations] => Array
                                        (
                                            [0] => set
                                        )

                                )

                            [assignee] => stdClass Object
                                (
                                    [required] => 
                                    [schema] => stdClass Object
                                        (
                                            [type] => user
                                            [system] => assignee
                                        )

                                    [name] => Assignee
                                    [autoCompleteUrl] => https://eyepax.atlassian.net/rest/api/latest/user/assignable/search?issueKey=REC-143&username=
                                    [operations] => Array
                                        (
                                            [0] => set
                                        )

                                )

                            [fixVersions] => stdClass Object
                                (
                                    [required] => 
                                    [schema] => stdClass Object
                                        (
                                            [type] => array
                                            [items] => version
                                            [system] => fixVersions
                                        )

                                    [name] => Fix Version/s
                                    [operations] => Array
                                        (
                                            [0] => set
                                            [1] => add
                                            [2] => remove
                                        )

                                    [allowedValues] => Array
                                        (
                                        )

                                )

                            [resolution] => stdClass Object
                                (
                                    [required] => 1
                                    [schema] => stdClass Object
                                        (
                                            [type] => resolution
                                            [system] => resolution
                                        )

                                    [name] => Resolution
                                    [operations] => Array
                                        (
                                            [0] => set
                                        )

                                    [allowedValues] => Array
                                        (
                                            [0] => stdClass Object
                                                (
                                                    [self] => https://eyepax.atlassian.net/rest/api/latest/resolution/1
                                                    [name] => Fixed
                                                    [id] => 1
                                                )

                                            [1] => stdClass Object
                                                (
                                                    [self] => https://eyepax.atlassian.net/rest/api/latest/resolution/2
                                                    [name] => Won't Fix
                                                    [id] => 2
                                                )

                                            [2] => stdClass Object
                                                (
                                                    [self] => https://eyepax.atlassian.net/rest/api/latest/resolution/3
                                                    [name] => Duplicate
                                                    [id] => 3
                                                )

                                            [3] => stdClass Object
                                                (
                                                    [self] => https://eyepax.atlassian.net/rest/api/latest/resolution/4
                                                    [name] => Incomplete
                                                    [id] => 4
                                                )

                                            [4] => stdClass Object
                                                (
                                                    [self] => https://eyepax.atlassian.net/rest/api/latest/resolution/5
                                                    [name] => Cannot Reproduce
                                                    [id] => 5
                                                )

                                        )

                                )

                            [worklog] => stdClass Object
                                (
                                    [required] => 
                                    [schema] => stdClass Object
                                        (
                                            [type] => array
                                            [items] => worklog
                                            [system] => worklog
                                        )

                                    [name] => Log Work
                                    [operations] => Array
                                        (
                                            [0] => add
                                        )

                                )

                        )

                )

        )

)

what should be my next step?

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Faisal
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.
December 31, 2012

Hi Ashen,

I did a quick test on this, and I believe that you may change an issue status by running the following cURL command:
curl -D- -u admin:admin -X POST --data @/Users/BaBs/Desktop/test.json -H "Content-Type: application/json"http://localhost:8080/jira/rest/api/2/issue/JC-11/transitions?expand=transitions.fields

Basically, you could try to run the same command by switching the user credentials, the location of the JSON data and also the hostname and I hope that it will help. For your reference, the content of the JSON file is pasted below:

{
    "update": {
        "comment": [
            {
                "add": {
                    "body": "Comment added when resolving issue"
                }
            }
        ]
    },
    "transition": {
        "id": "5"
    }
}

In my local instance, the transition with the ID 5 will resolve an issue.

You may kindly refer to the following documentation for more info on transitioning issue via REST:
http://docs.atlassian.com/jira/REST/latest/#id342828

However, my expertise in PHP is very limited. Perhaps you may try to convert the JSON data provided above into your code, and see if it helps?

Thanks.

0 votes
Renjith Pillai
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.
December 31, 2012

As expected, the 'Start Progress' transition does not support updating of any fields. To do that first change the workflow to include a screen for this transition which shows the fields that you want to update.

Otherwise directly update the issue using the REST interface as explained here http://docs.atlassian.com/jira/REST/latest/#id342606

Please read the docs about the usage. The same section also tells you which all fields are update by calling the editmeta api.

ashen shanaka December 31, 2012

so as you are saying, if i manually made the transition of the issue to start progress, then i can thereafter change the issue status as in rest like i have tried before? if so how can i make the start progress transition editable? i cannot seem to get this doc correctly.it would be really great if you can tell me. thanks.

ashen shanaka December 31, 2012

my goal is to update the status of the tasks. nothing else.i will manage the others. can you tell me a step by step procedure perhaps, to do so..thanks.

Renjith Pillai
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.
December 31, 2012

Before that, tell me your end goal. As I read from your comment, you need to transition as issue to 'In Progress' state and also update some values of the issue. Is that right?

ashen shanaka December 31, 2012

which means once a task is created i should be able to change it to in progress resolved and closed repoened likewise...please answer.thanks

Renjith Pillai
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.
December 31, 2012

Ah. I am confused now. If you need to just update the 'status', you need to call the transitions REST interface which you are doing. I am not sure about how to write this in PHP, and hence cannot validate your code. Read the tutorials here:

https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Edit+issues

https://confluence.atlassian.com/display/DOCSPRINT/The+Simplest+Possible+JIRA+REST+Examples

ashen shanaka December 31, 2012

thanks. maybe you can help me afterall if you dont know php. the thing is i was able to change the resolution of a open status task and was able to make it in progress state automatically. i couldnt change the status. maybe its because you said its not allowed. when i updated my question a second time you told me that its not allowed. im thinking maybe if i can make it allowable then i'll be able to change the status like i changed the resolution.i dont know what i am saying here is practical or not. but its what i have in my mind atm. no one else who knows php is not answering here it seems. so you're my only hope for the moment..:)

Renjith Pillai
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 1, 2013

Quite frankly, it is not about not helping you, the description of the problem is quite confusing to me. You said, you were able to change an 'Open' task to 'In Progress' and next line you say, you cannot change status. When you change an issue from 'Open' to 'In Progress' what you are changing is the status itself. And resolution and status are two different things. A resolution is a value that is set during a transition from one status to another. I am still not able to figure out what operation is failing for you.

Could you please write the problem description again (please carefully use the words, 'resolution', 'status', 'task' as each of them have a definite meaning in JIRA) ? If you can get the screenshots of the issue that before and after the change you want to achieve we will try our best to help you.

0 votes
Renjith Pillai
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.
December 31, 2012

The code that you have posted only has the transition value in the JSON. To update the fields, you also need to provide that.

Can you post the output of the transitions GET request along with "expand=transitions.fields" to know what is supported?

Read the doc at http://docs.atlassian.com/jira/REST/latest/#id342828

ashen shanaka December 31, 2012

hi
i have changed the code i previously posted in to the new one you have requested

0 votes
Renjith Pillai
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.
December 31, 2012

Are you able to change the summary and assignee using the web interface for the same transition? The REST api allows to change only the fields that are visible in the transition screen.

ashen shanaka December 31, 2012

umm..i didnt try that.to tell you the truth im really in the beginng process in this. i used this php classes that i found in github to do my work.
https://github.com/FayP/JIRA-php

i just chnaged the url in the update method. whats wrong with what i dd?

Renjith Pillai
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.
December 31, 2012

You have to first find the right transition ids for your JIRA instance. Also please perform the transition as I said in the previous comment and verify that the fields that you are updating are shown in the screen.

ashen shanaka December 31, 2012

i have updated my question

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