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?
Community moderators have prevented the ability to post new answers.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 )
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.