Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

POST to Rest API Scriptrunner

Jee young-hoon May 29, 2018

Hi, 

want to use ScriptRunner to control issue with REST APIs.

So I use " api/2/issue/{issueIdOrKey}/transitions " this REST API

Tried to run Issue's transition.

An error has occurred, but I don't know why.

Can You help me?

Thanks.

 

In addition, the final goal is to receive an issue key using REST endpoint to change the transition id of that issue. 

 

test script : 

import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.JSON
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
import groovyx.net.http.HttpResponseException

@Grab (group = 'org.codehaus.groovy.modules.http-builder', module = 'http-builder', version = '0.5.0')
def client = new RESTClient('http://localhost:8080')
def jsonObj = new JsonSlurper().parseText('{"transition": {"id": "11"}}')
def response = client.post(path: "/rest/api/2/issue/CH-4/transitions?expand=transitions.fields",
contentType: JSON,
body: jsonObj,
headers: ['Content-Type': 'application/json; charset=UTF-8', 'Accept': 'application/json'])

 error message : 

groovyx.net.http.HttpResponseException: 
at groovyx.net.http.RESTClient.defaultFailureHandler(RESTClient.java:263)
at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:503)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:223)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:165)
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:515)
at groovyx.net.http.RESTClient.post(RESTClient.java:141)
at groovyx.net.http.RESTClient$post.call(Unknown Source)
at Script266.run(Script266.groovy:10)

 

1 answer

1 accepted

1 vote
Answer accepted
Daniel Yelamos [Adaptavist]
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.
May 30, 2018

Hi Jee.

I can help you out with this, if you are 100% sure that this is what want. To be honest, you really don't want to control issue transition through the REST API.

Using a post-function, or a listener, would be a lot easier, and it's functionality that you wouldn't have to code by yourself, since we've already provided that built-in. 

These documentation articles might be of help:

This is the fast-track listener, that does precisely what you want based on a condition.

It is also available as a post-funciton, if I'm not mistaken.

Cheers!

Dyelamos

Jee young-hoon May 30, 2018

Thank you for your answers.

I wanted to change the state of issue on an external build tool, not on an Atlassian product.
Is it possible to change the state externally?

Daniel Yelamos [Adaptavist]
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.
May 30, 2018

Sorry let me make sure that I understand you.

You want to open a rest endpoint in your instance, that in turn accepts request from an external build tool to transition issues.

Is this correct?

Cheers

Dyelamos

Jee young-hoon May 31, 2018

That's exactly what I want.

I've already solved it with curl.

Do you have any other ideas?

Daniel Yelamos [Adaptavist]
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.
May 31, 2018

What I think you are doing now is setting a REST endpoint, and within that REST endpoint, you are yet making another call to the JIRA rest api.

Instead of using the rest api from within your REST endpoint, use a normal transition method via java. Like my colleague Aidan does here.

I would heavily suggest using this over calling a JIRA endpoint while within your own rest API. It would make use of less resources, and it would me more reliable. 

Cheers

Suggest an answer

Log in or Sign up to answer