Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Send data to external API using scriptrunner

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

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

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)

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)

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

266 views 7 7
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you