Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Transition an Issue Using Jira Rest API

OdedP October 2, 2014

Hi, 

I'm trying to transition an issue using the following groovy code 

import groovy.json.JsonSlurper;
import org.apache.http.HttpRequest;
import org.apache.http.protocol.HttpContext;
import org.apache.http.HttpRequestInterceptor;
@Grab(value = 'org.codehaus.groovy:groovy-all:1.7.5', 
      initClass = false)
@Grapes([
@Grab(group = 'org.codehaus.groovy.modules.http-builder', 
      module = 'http-builder', version = '0.5.1'),
@GrabExclude('org.codehaus.groovy:groovy')
])
issueKey = "ICTST-655"
def jiraApiUrl = 'http://jira.hostname.local/jira/rest/api/2/'
def jiraClient = new RESTClient(jiraApiUrl);
def basic = 'Basic ' + 
'user:passwd'.bytes.encodeBase64().toString()
jiraClient.client.addRequestInterceptor(
  new HttpRequestInterceptor() {
    void process(HttpRequest httpRequest, 
                 HttpContext httpContext) {
      httpRequest.addHeader('Authorization', basic)
  }
})
def uriPath = 'issue/${issueKey}/transitions'
params = [transitionId : 581]
def transition  = jiraClient.post( requestContentType : JSON,
									   path: uriPath,
									   body : params)

But I continue to get "

Caught: groovyx.net.http.HttpResponseException: Bad Request
groovyx.net.http.HttpResponseException: Bad Request

Any Idea What am I doing wrong? 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
JamieA
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.
October 2, 2014

I normally reach for Fiddler, and set the httpclient to proxy through fiddler. Can't remember the syntax but it's very straightforward. This will show you the full request and response, and you can tweak it a bit then update your code.

Also check the logs on the receiving jira. If you specify just contentType: JSON, it should encode it properly and set the Accept header to accept json. Just setting the requestContentType might be sending json but not setting the Accept header. Again, check with Fiddler.

Oded Priva October 6, 2014

Thanks Jamie !

Vineela Durbha April 23, 2019

Hi @JamieA 

I am trying as below but I am even getting Bad request error continuously

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager;
import groovyx.net.http.RESTClient;
import static groovyx.net.http.ContentType.*;

log.setLevel(org.apache.log4j.Level.DEBUG)

 

def http = new RESTClient('http://cvwepr01/dalwebapiuatlinux/')
http.headers['Authorization'] = 'Basic '+"xxx:XXX".getBytes('iso-8859-1').encodeBase64()

def resp = http.post(
path: 'UpdateSwdevTicket',
body: [ IssueNumber:'SWXXX-4563',
summary:'test summary1'],
requestContentType: JSON )

TAGS
AUG Leaders

Atlassian Community Events