Eugene Sergienko
Eugene Sergienko

Reputation: 47

JIRA do I have a way to get the list all ID of my transition steps?

I want to synchronize between two systems. However, to update the transition status of the bug I have to send a JSON file with my arguments (new status) something like this:

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

To set a new status I have to set it's id, How can I get the list of all the IDs and the description of each one.

Upvotes: 2

Views: 802

Answers (2)

edi_allen
edi_allen

Reputation: 1872

You can use the following python script to get the information you want.

#!/usr/bin/env python

from __future__ import print_function
import ConfigParser
import requests
import json
import base64
import sys

def print_error(*args, **kwargs):
  print(*args, file=sys.stderr, **kwargs)

def get_issue(user,password,search_url):
  user_auth = base64.b64encode(user+':'+password)
  headers = {'Authorization': 'Basic ' + user_auth}
  return requests.get(search_url, headers=headers)

def main():
  if len(sys.argv) < 2:
    usage_message = 'Usage: ' + sys.argv[0] + ' issue_number'
    print_error(usage_message)
    sys.exit(1)

  config = ConfigParser.RawConfigParser()
  config.read('config.properties')

  jira_user = config.get('Global', 'jira_user')
  jira_pass = config.get('Global', 'jira_pass')
  jira_base_url = config.get('Global', 'jira_base_url')
  issue_url = config.get('Global', 'issue_url')
  issue = sys.argv[1]
  issue_search_url = jira_base_url + issue_url + issue + '/transitions'

  response = get_issue(jira_user,jira_pass,issue_search_url)

  if response.status_code == 404:
    print_error(issue + ' NOT FOUND!')
    sys.exit(1)


  data = response.json()

  for transition in data['transitions']:
    print("%s %s" % (transition['id'], transition['name']))

main()

You need to have a configuration file (config.properties) in the same directory as the script with the following content:

[Global]
jira_user=username 
jira_pass=pass 
jira_base_url=http://your_jira_url.com
issue_url=/rest/api/2/issue/

Then you call the script like this:

./get_transitions.py your_ticket_number

Upvotes: 1

sintasy
sintasy

Reputation: 637

You can get a list of the transitions possible for this issue by the current user, along with fields that are required and their types by url /rest/api/2/issue/{issueIdOrKey}/transitions (get request)

Upvotes: 1

Related Questions