JIRA transition through Python REST API

How to mark a JIRA problem as resolved or closed using REST API (version 2) using Python ?

I found the documentation at http://docs.atlassian.com/jira/REST/latest/#id199544 , but I had various errors, including:

  • HTTP Error 415: unsupported media type
  • HTTP Error 400
+4
source share
1 answer

After a long search, I found a solution that I am posting here for anyone interested in creating a Git / Gerrit hook to do such a thing as me:

First, open http://example.com/rest/api/2/issue/<ISSUE>/transitions?expand=transitions.fields in your browser for your site and release number to find the transition ID.

Suppose 1000:

 import urllib import urllib2 import base64 import json key = 'JIRA-123' comment = "It done!" username = 'username' password = 'password' # See http://docs.atlassian.com/jira/REST/latest/#id199544 url = 'http://example.com/rest/api/2/issue/%s/transitions' % key auth = base64.encodestring('%s:%s' % (username, password)).replace('\n', '') data = json.dumps({ 'transition': { 'id': 1000 # Resolved (for my setup) }, 'update': { 'comment': [ { 'add': { 'body': comment } } ] }, }) request = urllib2.Request(url, data, { 'Authorization': 'Basic %s' % auth, 'Content-Type': 'application/json', }) print urllib2.urlopen(request).read() 

You can completely omit the comment section if you do not want to add a comment.

+5
source

Source: https://habr.com/ru/post/1435101/


All Articles