How to reject issue based on issue id using REST API/Jira Python?

kumar August 12, 2024

Hi all,

 

I am trying to change the status of Jira issue using it's ID.

 

Below is the code snippet, I am using-. Unfortunately, it is not working. 

 
for issue_id in issue_ids:

    JIRA().transition_issue(issue=issue_id, transition='Rejected')

Can anyone help me with this?

Thanks in advance

2 answers

0 votes
Vijay Dadi
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.
September 3, 2024

The transitions will not work when there are approvals attached to any status.

 

First do REST api call to get the approval ID using the below endpoint with GET method.

https://<CUSTOMER>.atlassian.net/rest/servicedeskapi/request/{{issue.key}}/approval

approval id from the response and store it in a variable {{approvalid}}

 

Now do an approval call to a below endpoint with POST method to approve the request

https://<CUSTOMER>.atlassian.net/rest/servicedeskapi/request/{{issue.key}}/approval/{{approvalid}}

 

with the body as 

 

{
      "decision":"approve"
}
This is a working automation which I am using, let me know if it works.

 

 

0 votes
Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 12, 2024

Hello @kumar 

What is the result of trying to execute that code? Do you get an error?

Based on the example provided here:

https://jira.readthedocs.io/examples.html#transitions

...you should not be including issue= and transition= in the parameters. The parameters should be just the actual values.

kumar August 13, 2024

Hi @Trudy Claspill 

 

Thank you for your response.

 

Unfortunately, I can not use Jira Python library. Therefore, I have written REST API based script. please check below. But still it is not working. Am I missing something here?

 

url = "<domain-name.atlassian.net/rest/api/2/issue/{id}/transitions?expand=transitions.fields"

headers = {

  "Accept": "application/json"

}

for issue_id in issue_ids:

    response = requests.request(

   "POST",

   url.format(id=issue_id),

   data={

        "update": {

        "comment": [

            {

                "add": {

                    "body": "Issue is rejected."

                }

            }

        ]

    },

   "transition": {

     "id": "161"

   }

  },

   headers=headers,

   auth=auth

   )
The above script is not working. 
Can you help me with this please?
Thanks in advance

 

 

 

 

 

 

 

 

 

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 13, 2024

What is the result of trying to execute that code? Do you get an error?

In the first line are you replacing <domain-name.atlassian.net with the actual base URL for you site?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events