AnsweredAssumed Answered

Calling RESTClient from Script Task

Question asked by mike.waldrop on Mar 23, 2015
Latest reply on Mar 24, 2015 by jbarrez
I'm trying to find the most simple way to make outbound REST calls from a script task.  I was hoping to keep it all simple with groovy with something like:


import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.*

def client = new RESTClient( 'https://hooks.slack.com/services/' )
def resp = client.post( path : 'testpath',
                        body : [channel: "test", username: "test content"],
                        requestContentType : JSON
                       )
assert resp.status == 200  // HTTP response code; 404 means not found, etc.
println resp.getData()

So, the problem I have initially is just to get the correct http-builder jar in the class path that will get picked up.  I don't have a completely mavenized development environment, and I'm trying to keep it simple.

I tried dynamically loading the dependencies via grape with something like:

@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )
import static groovyx.net.http.ContentType.*

def client = new groovyx.net.http.RESTClient( 'https://hooks.slack.com/services/' )
def resp = client.post( path : 'test path',
                        body : [channel: '#stest',
                                username: 'mike',
                                text: 'test message'],
requestContentType : JSON
                       )
assert resp.status == 200  // HTTP response code; 404 means not found, etc.
println resp.getData()

But I still get some class not found errors.  I can generally get these scripts working fine from a normal groovy command line in the OS.  Any pointers on how to keep it simple ?

Outcomes