Forums

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

How to change status of ticket via REST-API with issue key?

Lindsay Herron September 20, 2022

Hi Guys,

I'm struggling to change the status for a ticket using the REST-API.

I thought I needed to find the ID from the Issue key, and I do find an ID, but not the ID apparently needed to change the status.

I could be doing something dumb here, but any help would be appreciated.

Step 1: Find the Ticket

TICKET_STRING = r".../rest/api/2/issue/" #... is replaced with my JIRA tracker instace
link = TICKET_STRING + self.ticket
response = requests.get(link, headers=self.headers)
dictResponse = json.loads(response.content.decode("utf-8"))
self.ticket_id = dictResponse["id"]
Step 2: Change Status with ID
XRAY_STRING = r".../rest/raven/1.0/api/testrun/" #It is of type testrun, but not sure if that is really needed here.. I tried with TICKET_STRING but it also didn't work.
link = XRAY_STRING + self.ticket_id + "/status?status=" + status
response = requests.put(link, headers=self.headers)
But with response, I get ERROR: b'Test Run with Id #### was not found in the server' #where the symbols are of course replaced with the ID I found in Step1
Also, just in case it is relavent, but I don't think it is for the issue I'm facing:
self.headers = {
            "Authorization": "Basic " + self.user_password,
            "Content-Type": "application/json",
            "Accept": "application/json",
            "X-Atlassian-Token": "no-check",
        }

1 answer

1 accepted

3 votes
Answer accepted
Mohamed Benziane
Community Champion
September 20, 2022

Hi,

Welcome to the community

your link's variable should be something like this:

 <yourJiraInstance>/rest/raven/1.0/api/testrun/{id}/

then you need to create a json that you will attach to your request

https://docs.getxray.app/display/XRAY/Test+Runs+-+REST

https://requests.readthedocs.io/en/latest/user/quickstart/#more-complicated-post-requests

Lindsay Herron September 20, 2022

Are you referring to step 1 or step 2?

The issue is, I don't have the ID for step 1. I only have the key for the issue. When I tried to get the ID via Step 1, the ID is not valid in step 2.

The link you provided is also already what I have in step 2. In Step 1, if I try to use the testrun link instead with the key of the issue, I get a 404 Error.

The solution is either hopefully generic for all issue types, not just testrun, or it provides a way for me to get the proper ID.

Mohamed Benziane
Community Champion
September 20, 2022

If you want to update a testrun and you doesn't know it's id you'll need to make a call to this API with the testExec and testIssueKey

http://yourserver/rest/raven/1.0/api/testrun?testExecIssueKey=TEST-123&testIssueKey=TEST-321 

you will find the id of your test run and then you will be able to update it with this call

put ==> /rest/raven/1.0/api/testrun/{id}/

Lindsay Herron September 20, 2022

I also don't have the TestExec key. I only have the testrun key.

There is no generic way of changing the status? That is separate from whether it is a testrun, testexec or any other type?

Mohamed Benziane
Community Champion
September 20, 2022
Lindsay Herron September 20, 2022

I actually don't find this page so helpful for transition. I don't see how I can change the status here. They don't have a key defined for status except under SCHEMA, but even under the SCHEMA tab I only see types being defined as "string" for anything to do with the status.

In short, I don't understand what my json data would look like in this case.

data = {???}

link = ".../rest/api/2/issue/" + self.ticketKey + "/transitions?expand=transitions.fields"
response = requests.post(link, json=data, headers=self.headers) #where self.headers is already defined in my original post.
Lindsay Herron September 20, 2022

If data should just be:

data = {"transition": {
                    "id": "5"
                    },
                }
Then I don't know where the transition id comes from.
Any additional hints on that would be helpful.
Lindsay Herron September 20, 2022

I had found this ticket: https://community.atlassian.com/t5/Jira-questions/Cannot-transition-an-issue-via-Rest-API/qaq-p/1194157

But in doing the following, I get a 405 error:

 

self.headersStatus = {
            "Authorization": "Basic " + self.user_password,
            "Content-Type": "application/json"
        }
data = {"transition": {
                    "id": status # or "5", but I was hoping for "PASS" or some other string that means something to me instead of a number.
                    },
                }
link =  r".../rest/api/2/issue/"+ self.ticket + "/transitions"
response = requests.put(link, json=data, headers=self.headersStatus)
I also tried headers=self.headers from my intial definition, but it also didn't work.
Mohamed Benziane
Community Champion
September 20, 2022

You need to call this api:

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

It will give you all the information you need to make the transition then make the transition with the api below

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

Lindsay Herron September 20, 2022

Ah now I get it! Okay, perfect! Thank you!!

Like # people like this

Suggest an answer

Log in or Sign up to answer