help with REST using groovy

Hi, 

I'm trying to run this groovy script but all i get is a "bad request" 

How can I debug it? ( Using Mac ) 

How can I solve it? 

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import groovyx.net.http.RESTClient;
import groovyx.net.http.HttpResponseDecorator;
import org.apache.http.HttpRequest;
import org.apache.http.protocol.HttpContext;
import org.apache.http.HttpRequestInterceptor;
import groovy.json.JsonSlurper;
import static groovyx.net.http.Method.*
import static groovyx.net.http.ContentType.*
// IssueManager issueManager = ComponentManager.getInstance().getIssueManager();
// MutableIssue myIssue = issueManager.getIssueObject("JIRA-248");
    
myIssue = issue

if ( myIssue.isSubTask() &&  myIssue.parentObject.statusObject.name == "Backlog" ) {
	
	def issueParentId = myIssue.parentObject.key
	def transitionNum = "731"
	def  JIRA_REST_URL = "http://****.local/jira/rest"
	def  JIRA_API_URL = JIRA_REST_URL + "/api/2/"
    def params = [ transition  : transitionNum ]
    def jira = new RESTClient(JIRA_API_URL);
	def basic = 'Basic ' + '*****:*****'.bytes.encodeBase64().toString()
	jira.client.addRequestInterceptor(
	  	new HttpRequestInterceptor() {
	    	void process(HttpRequest httpRequest, HttpContext httpContext) {httpRequest.addHeader('Authorization', basic) }
		}
	)
	def resource = "issue/${issueParentId}/transitions"
    println "resource " + resource
    def resp = jira.post(
        requestContentType : JSON,
        path : resource,
        body : params
    )
}

1 answer

0 vote

uriPath  should include the full path from the root, eg /jira/rest/api/2/issue/${parentKey}/transitions

I know you specified it as the base url but that's not the way httpbuilder works.

Best way to debug is fiddler, if not available on your OS then wireshark.


Thanks Jamie, your tip helped alot .. BUT :) When I'm running the script from the console it works O.k .. But when I try to implement it in a transition It faisl on Property 'issueParentId' not found

I forgot to mention that i updated the code above to the 'working' one

I also checked it from a file and it is working, Any reason it is not working from the inline script?

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

182 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you