HTTP-Connector POST Payload configuration and GET URL Parameters with variables?

The docs for HTTP Connector indicate that you can use the method POST and the parameter payload to send a POST request: https://docs.camunda.org/manual/7.4/reference/connect/http-connector/#using-the-generic-api

The Payload does not seem to support the Map type, and you cannot seem to use script with JavaScript and generate something like: {“q”:“test one two three”}.

Here is a example of a POST Payload for the following URL:
https://stephenrussett.cartodb.com/api/v2/sql

{“q”:“SELECT name, number FROM montreal_boroughs WHERE ST_Intersects(montreal_boroughs.the_geom,CDB_LatLng(45.508948,-73.554454))”}

Could Camunda provide some further documentation on how to create payloads that are KeyValues to be used in a POST payload?

Also for GET requests, the engine does not like non-friendly URL characters and the engine won’t convert into a proper format for the web.
The GET issue was resolved by using Inline javascript for the URL field. For future reference by anyone else looking at this, make sure to use the encodeURIComponent rather than just the encodeURI.:
"https://stephenrussett.cartodb.com/api/v2/sql?q="+ encodeURIComponent ("SELECT name, number FROM montreal_boroughs WHERE ST_Intersects(montreal_boroughs.the_geom,CDB_LatLng(45.508948,-73.554454))");

Here is a example:
https://stephenrussett.cartodb.com/api/v2/sql/?q=SELECT name, number FROM montreal_boroughs WHERE ST_Intersects(montreal_boroughs.the_geom,CDB_LatLng(45.508948,-73.554454))

How do we convert the format in the config?
Additionally how can we inject variables? Standard ${} format?

Related pages/docs:
https://groups.google.com/forum/#!topic/camunda-bpm-users/CW3MCtMc_dA
https://groups.google.com/forum/#!topic/camunda-bpm-users/aGVJKXGFOLE (this user seemed to have same issue)

Issues Resolved.

1 Like

Okay did some more testing. Unless there is a blatant mistake in my config for this simple example, the docs are incorrect or the payload parameter does not work.

POST_WS_Test.bpmn (6.5 KB)

It is sending the requests to: http://requestb.in/1fe5xmz1?inspect, and the GET works, but the payload for POST never arrives.

Seems this issue was raised in 2014: https://groups.google.com/forum/#!topic/camunda-bpm-users/aGVJKXGFOLE

@menski was this ever identified as a issue?

GET Issue was resolved, but POST issue remains. see original post for GET resolution

Hi Stephen,

I checked your process and indeed, it didn’t work with requestb.in, but it worked with hookbin.
I have uploaded a simple maven project with your process, which uses mockserver to intercept and verify the requests and they are send correctly. Run the project with mvn test and you can inspect the log output afterwards.
I changed your process so your requests run against mockserver and also added the header content-type: application/json for the POST request.

Cheers,
Christian

@hawky4s were you also able to get it to function with: “https://stephenrussett.cartodb.com/api/v2/sql?q=”+ encodeURIComponent (“SELECT name, number FROM montreal_boroughs WHERE ST_Intersects(montreal_boroughs.the_geom,CDB_LatLng(45.508948,-73.554454))”); ?

See this commit how I store the query as an process variable and use it as payload.

Hi Stephen,

I updated the example with your URL and also showed how to use Camunda Spin / JsonPath with the http-connector.

Cheers,
Christian

@hawky4s Thanks for the details. Looks like it was the Content-Type header that was causing the problem.

On a related note, I see if your parseresults.js code you reference connector. Is there a list of internal names for referencing different objects in Camunda?

On related note, this is what the final code example looked like; used inline Javascript for the Payload:

var lat = execution.getVariable("Latitude");
var long = execution.getVariable("Longitude");

'{"q":"SELECT name, number FROM montreal_boroughs WHERE ST_Intersects(montreal_boroughs.the_geom,CDB_LatLng(' + lat + ',' + long + '))"}';

Response was inline Javascript that parsed as: S(response).prop("rows").elements().get(0).prop("number").numberValue();

(in this example did not need to provide any error handling)

If you have better implementation suggestions, happy to receive.

Hi Stephen,

If I am having a Url: “https://abc/xyz” and I will get a XML response from hitting it.
So for that what should be my http-connector configurations (Input and Output parameters) in the BPMN?

Thanks,
Tushar

@Tushar read through Camunda’s Spin documentation on how to parse XML responses: https://docs.camunda.org/manual/7.5/reference/spin/

Everything should be the same but how you parse will be tailored for the XML using SPIN.

Hi,

I am getting XML response from HTTP Connector (Service Task) as follows:

<product>
  <categories>
      <code>abc</code>
      <url>123</url>
  </categories>
  <categories>
      <code>xyz</code>
      <url>456</url>
  </categories>
</product>

Now, in output Parameter of the Service Task I configured as follows to fetch “abc” from the XML

          Name: myUrl
          Type: Script
          ScriptFormat: JavaScript
          ScriptType: Inline Script
          Script: var xml = S(response);
                       xmlName = xml.xPath("/product/categories[0]/code").element();
                      xmlName;

ERROR in TASKLIST:

Cannot instantiate process definition Hybris:38:d4b6fb29-a1ab-11e6-a73a-d43d7ec7ada1: Unable to evaluate script: sun.org.mozilla.javascript.internal.WrappedException: Wrapped org.camunda.spin.xml.SpinXPathException: SPIN/DOM-XML-01035 Unable to find XPath expression ‘/product/categories[0]/code’ (#2) in at line number 2

What exactly should I Write in SCRIPT to fetch abc???

Thanks,
Tushar

I haven’t tested your specific example, but XPath uses 1-based indices for collections, so the correct XPath should be “/product/categories[1]/code”.

2 Likes