Javascript HTTPS POST in Listener

I would like to make an HTTPS POST to a REST endpoint within a TASK listener using a script. I have a working script in javascript, but it uses fetch, which I suspect may not be supported within Camunda.

Is this possible with javascript or should I refactor this to groovy?

You can use something like: Replacing Http-Connector with Jsoup usage

or whatever your flavour of client is, and use the Nashorn JS Java interop to access the java libs for HTTP

The Forum is FULL of JS code examples and how to use nashorn for various complex and simple use cases. (mostly posted by myself over the years), so would recommend some searching around the forum for Nashorn examples.

That looks like a good option. A little more complicated than ‘out-of-the-box’, but it sounds like people have had issues with the standard http-connector. It’s been a long time since I worked with java, so I’m a little lost in understanding what my options and limitations are.

But I’m continually amazed at how extensible Camunda is.

HTTP-Connector is not typically designed to be used in a script form.
You can access it through the script, but HTTP-Connector’s impl is fairly old and not many updates. There are features missing, such as timeouts, binary support, (And prob some others i am forgetting).

“Out of the Box Support” is being able to add a java lib and then being able to use that Java lib in a JS script. Jsoup is a example of this, but you can of course use any lib you like that provides the API style that best fits your needs.

It can be as simple as:

var Jsoup = Java.type("org.jsoup.Jsoup")
var doc = Jsoup.connect('http://date.jsontest.com')
                  .method(Java.type('org.jsoup.Connection.Method').POST)
                  .header('Accept', 'application/json')
                  .header('Content-Type', 'application/json')
                  .requestBody(JSON.stringify(body))
                  .timeout(30000)
                  .ignoreContentType(true) // This is used because Jsoup "approved" content-types parsing is enabled by default by Jsoup
                  .execute()

  var resBody = doc.body()
  var resStatusCode = doc.statusCode()

JSoup did the trick. Thanks so much for your help.

:+1: glad it worked out