Forums

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

how to call web service on workflow trigger (To Do to in progress).

kunti pawar May 15, 2018

I want call web service on workflow trigger (To Do to in progress)

So I am expecting any simple example to call web service using script runner(Custom script post-function)

1 answer

0 votes
Alexey Matveev
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 15, 2018
kunti pawar May 15, 2018

rest.png 

 rest.png 

kunti pawar May 15, 2018

I am getting like that MSG. 

Alexey Matveev
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 15, 2018

Change 

IssueManager issueManager = ComponentManager.getInstance().getIssueManager();

to

IssueManager issueManager = ComponentAccessor.getIssueManager();

 and import com.atlassian.jira.component.ComponentAccessor

kunti pawar May 15, 2018

Hi Alexey Matveev COMMUNITY CHAMPION

I am trying to execute below code using script runner but I am getting error

can not find http.client.addRequestInterceptor method.

Could you please help me ASAP.

import groovyx.net.http.RESTClient
import org.apache.http.HttpRequest
//import org.apache.http.client
import org.apache.http.HttpRequestInterceptor
import org.apache.http.protocol.HttpContext;
import org.apache.http.HttpRequestInterceptor;
import groovy.json.JsonSlurper;
import com.atlassian.jira.component.ComponentAccessor
import groovyx.net.http.Method

def constantsManager = ComponentAccessor.getConstantsManager()
def bugId = constantsManager.allIssueTypeObjects.findByName("Bug").id

def RESTClient http
def baseUrl = "http://localhost:8080/jira/"
http = new RESTClient(baseUrl)
http.client.addRequestInterceptor(new HttpRequestInterceptor() {
void process(HttpRequest httpRequest, HttpContext httpContext) {
httpRequest.addHeader('Authorization', 'Basic ' + 'admin:admin'.bytes.encodeBase64().toString())
}
})

def issue = http.request(POST, JSON) {
uri.path = '/jira/rest/api/2/issue'
body = [
fields: [
project: [
key: "JRA"
],
summary: "test issue for rest api",
issuetype: [
id: bugId
],
reporter: [
name: "admin"
]

]
]
}

Alexey Matveev
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 15, 2018

What is exactly the error? Maybe you passed wrong parameters to the method?

kunti pawar May 15, 2018

rest.png

kunti pawar May 15, 2018

line no. 14 

Alexey Matveev
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 15, 2018

Try to execute it.

kunti pawar May 15, 2018

I am trying to execute but I am getting below error

groovy.lang.MissingPropertyException: No such property: POST for class: Script198 at Script198.run(Script198.groovy:32) 

Suggest an answer

Log in or Sign up to answer