Forums

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

How to change the status of a Jira ticket (from OPEN to Under Review) using Python Rest API's?

Jovna Jetto
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 22, 2020

Hi Team,

So far I have been able to raise a Jira Ticket through Python using Jira REST API's. I am also able to add comments to an already existing ticket through Python. Now i need to change status of a ticket from Open to Under Review through API's. 

After seeing a couple of similar questions on the forum, I made a get request to the link below to find out the transition ID's.

jira_url = "https://<project_name>.atlassian.net/rest/api/3/issue/<issueKey>/transitions?expand=transitions.fields"

JSON Response Snippet:

{'expand': 'transitions', 'transitions': [{'id': '131', 'name': 'Under review', 'to': {'self': 'https://<project-name>.atlassian.net/rest/api/3/status/10036', 'description': '', 'iconUrl': 'https://<project-name>.atlassian.net/', 'name': 'Under review', 'id': '10036', 'statusCategory': {'self': 'https://<project-name>.atlassian.net/rest/api/3/statuscategory/2', 'id': 2, 'key': 'new', 'colorName': 'blue-gray', 'name': 'To Do'}}, 'hasScreen': False, 'isGlobal': True, 'isInitial': False, 'isAvailable': True, 'isConditional': False, 'fields': {}}]}

I have two questions:

1. We don't have any workflow defined. Is it necessary to have a workflow defined to be able to change the status of a ticket ?

2. If Transition ID's are to be used for changing the status of the ticket. I tried the below JSON payload to change the status of the ticket

{
    "update": {
        "comment": [
            {
                "add": {
                    "body": "Under Review"
                }
            }
        ]
    },
    "fields": {
        "resolution": {
            "name": "Duplicate"
        }
    },
    "transition": {
        "id": "10036"
    }
}

 

But it didn't work and gave the response as 

<Response [400]>
{'errorMessages': ["Transition id '10036' is not valid for this issue."], 'errors': {'worklog': "Field 'worklog' cannot be set. It is not on the appropriate screen, or unknown."}}

Am I using the right transition ID?

Please help us with this issue.

Thanks in advance!!

 

1 answer

1 accepted

1 vote
Answer accepted
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 26, 2020

Hi Jovna,

I can see that you are looking to change an issue status using the REST API.  In Jira, in order to do this, we cannot simply edit the issue to change the status field.  Instead we need to execute an existing transition in this workflow.

I believe your json payload is very close, however the transition id is not 10036.  That '10036' is the id number of the status.  You actually have to use the id of '131'.  The confusing part here is that frequently status and transition name have the same values.  That is the case here where both transition and status are called 'Under review' here.  That is not always the case with Jira as transitions can have any name.

Try again with the

    "transition": {
        "id": "131"
    }

instead and see if you get a different response back from REST.

I hope this helps.

Andy

Supriya Prasad _IN_
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 2, 2020

Thank you Andy. This worked for us!

S
Contributor
September 21, 2021

@Supriya Prasad _IN_ @Andy Heinzer 

Hey, were you able to get your comments updated & fields? I am getting bad request error

MyJson

{"update":{"comment":[{"add":{"body":"Rocket Science"}}]},"transition":{"id":"1"}}

 

Transition is working fine... for me

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 23, 2021

Hi @S 

Not all transitions will have a comment field appearing as an option.  I would first want to make sure that your transition in question is using a transition screen.  Outside of using the REST API, if you make this transition in the Jira web UI, is there a screen that appears with a comment field on it? 

If not, then you need to follow steps such as Map a screen to a workflow transition in Jira server before you can expect to add a comment during a transition be that in the Web UI or via the REST API.

Andy

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events