Http-connector payload as json object not string

could someone please help me with this simple scenario?
I have a rest call (with payload) using the http-connector. And I am tryint to pass the payload to the connector as a JSON object variable.
The problem is when I try to pass the payload (as a spin json object) to the connector the camunda will show this error:

org.camunda.spin.impl.json.jackson.JacksonJsonNode cannot be cast to java.lang.String

I can bypass this exception by creating the json object directly in the script as parameter, but in that case I will not see what was the payload in the cockpit (because there is no process var as payload).

Or another “solution” is to remove the SPIN (example below), but in that case the payload would be string and that is not ok (2000 char limitations).

var myJson = JSON.stringify(
    "variables": {
      "firstVar" : {"value" : "first value", "type": "String"},
      "secondVar" : {"value" : "second value", "type": "String"}

The process looks like this:

And is available here: REST connector.bpmn (9.5 KB)

Any help greatly appreciated.

@lhofer87 i hope below format is more sufficient. Remove JSON.stringify() and check.

var myJson = S('{"variables": {"firstVar" : {"value" : "first value", "type": "String"},"secondVar" : {"value" : "second value", "type": "String"}}}');

Hi Aravindhrs,
I appreciate your time, but this won’t do the trick, the problem that I am trying to solve is not an invalid json format, the problem is that the http-connector does not accept the json object, as an input variable type for the payload parameter, it is only accepting the string.

Or did your proposal work when you tested it? It did not work for me, but maybe I have an incorrect version of camunda (tested it on comunity edition 7.11.0 and 7.9.0)

If you want to store it as a json string, it should be escaped json string format. You can’t store the json directly to engine. Have you tried below format?

var myJson = '{\"variables\": {\"firstVar\" : {\"value\" : \"first value\", \"type\": \"String\"},\"secondVar\" : {\"value\" : \"second value\", \"type\": \"String\"}}}';

thank you again, but you can store json as a process variable and as I said, the problem is that the http connector does not accept the json as an input and for some reason it want a string. So the problem is not in storing variable as json in the engine, which is btw very common thing.

Hi @lhofer87 were you able to pass json as payload to http-connector

sorry for the late reply, I only have this process, if you need to pass the payload as a variable we can try to figure it out (I remember that this was a problem) otherwise, the process is fully functional.

REST connector.bpmn (10.9 KB)

Hope this helps.


Any workaround for this issue? Were you able to send json payload in your request?
I have a similar use case, I am trying to post json data.

I am using external javascript for sending payload.

var request=execution.getVariable(‘request’)
print("Request data: “, request,” type of: ", typeof(request));
payload = S(request);
print("payload: ", payload, " type of: ",typeof(payload))

The type is printed as object but still not getting proper response

Thanks in advance