How to close jira ticket via rest api?

李冲 September 3, 2018

I did some research and found this can be done by using /rest/api/2/issue/{issueIdOrKey}/transitions API.

For example, if there is one jira ticket `A`, and its current status is `Open`. Below is the step I followed.

Step 1: Get all the possible transitions through /rest/api/2/issue/A/transitions, say I get `Resolved` back.

Step 2: Update the ticket to `Resolved` status and call the API /rest/api/2/issue/A/transitions again to get the next possible transition status. Say this time I get `Closed` status back,

Step 3: Update the ticket status to close and Now `A` is closed.

 

 

My question:

1. There are many different issue types available for one project, such like `Bug`, `Support Request`, `Task` etc, and for each type, their transitions may be different. The close transition may call `Closed` for `Bug`, but it may call `Closed Issue` for `Support Request`. Is there a way to get which transition name means close?

2. Can I get all the transitions of one ticket back through one call ?Because /rest/api/2/issue/{issueIdOrKey}/transitions will only return the next available transition to me.  

3.  my request is to close the unclosed tickets, I hardcode some transitions name now to complete this but this should not a good way, is there a way i can get the relationships of all these transitions for one jira ticket? 

 Thanks.

1 answer

0 votes
Wouter Bruinings
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, 2018

Hi Christina, 

I experienced a similar challenge when developing a test automation tool for JIRA workflows. 

We have standardised statuses to prevent situations where there are multiple values representing the same state, such as "Closed" and "Closed Issue". 

To answer your questions:

1. My solution was to create a mapping for workflows and their end statuses, so that depending on the workflow I could read from the mapping what the end state should be.

2. I believe you cannot. 

3. Answer 2 and 3 result in this not being possible in a simple way. Closing unclosed tickets might be easier using the bulk change feature from JIRA.

Hope this helps. 

Kind regards,

Wouter

李冲 September 3, 2018

Thanks tons Wouter. :)  Regarding this, `Closing unclosed tickets might be easier using the bulk change feature from JIRA.` do we have an rest api for this ?

Wouter Bruinings
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, 2018

No this can only be done through the interface. 

 

Kind regards,

Wouter

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events