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

Send data to external API using scriptrunner

Sergio Palacio February 6, 2018

Hi I need to create a script  using groovy to send data to an external API app. in a postfunction. 

I need to it using the PUT method. 

Anyone kwnos any documentation or a simple example to do it?

thanks in advance.

2 answers

Suggest an answer

Log in or Sign up to answer
0 votes
turbobox
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 7, 2018

I am using your exact code, just with the url and the channel changed.

Getting these errors

 

There was an error during the execution of your script

Message:
groovy.lang.MissingMethodException: No signature of method: groovyx.net.http.HTTPBuilder.request() is applicable for argument types: (groovyx.net.http.Method, groovyx.net.http.ContentType, script15283798434881196727310$_run_closure1) values: [POST, text/plain, script15283798434881196727310$_run_closure1@2b2f527c]
Possible solutions: request(groovyx.net.http.Method, groovy.lang.Closure), request(groovyx.net.http.Method, java.lang.Object, groovy.lang.Closure), request(java.lang.Object, groovyx.net.http.Method, java.lang.Object, groovy.lang.Closure)
0 votes
Thanos Batagiannis [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.
February 26, 2018

Hello Sergio,

Bellow is an example of a script that makes use of the HttpBuilder and posts a message to Slack. 

import groovy.json.JsonBuilder
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method

def http = new HTTPBuilder("https://hooks.slack.com")
http.request(Method.POST, ContentType.TEXT) {
uri.path = "/services/XXXX/YYYYY/ZZZZZ" // <1>
body = new JsonBuilder([
channel : "#dev",
username : "webhookbot",
text : "Hello World !",
icon_emoji: ":ghost:",
mrkdwn : true,
]).toString()
}

Hope that helps. 

Regards, Thanos

turbobox
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 7, 2018

I am using your exact code, just with the url and the channel changed.

Getting these errors

 

There was an error during the execution of your script

MESSAGE:
groovy.lang.MissingMethodException: No signature of method: groovyx.net.http.HTTPBuilder.request() is applicable for argument types: (groovyx.net.http.Method, groovyx.net.http.ContentType, script15283798434881196727310$_run_closure1) values: [POST, text/plain, script15283798434881196727310$_run_closure1@2b2f527c]
Possible solutions: request(groovyx.net.http.Method, groovy.lang.Closure), request(groovyx.net.http.Method, java.lang.Object, groovy.lang.Closure), request(java.lang.Object, groovyx.net.http.Method, java.lang.Object, groovy.lang.Closure)
TAGS
AUG Leaders

Atlassian Community Events