How to check/debug HTTP calls in process?

Hello everyone.

I have implemented some service tasks with http-connector in my BPMN, and with it I make some call on a REST PHP API. Is there a way to see the payload built from FTL and the request response code and body, to reproduce fails and debug it from my postman ?

My script to treat the response seems to fail with a message : Caused by: :2 SyntaxError: Invalid JSON: :1:36 Expected eof but found <"{“status”:null,“message”:null}"

In the first REST task, “create credit note invoice”.

It expects an eof in my JSON but finds a
and I have no idea where it comes from. My JSON is formed with a json_encode on the PHP API side and returned in withBody() function (from Slim framework if you know this). The MIME type was returned too.

edit : BPMN file here : launchCancel.bpmn (35.2 KB)

Thanks and have a good day !

In a unit testing environment, wiremock can be nice for mocking the remote API you are connecting to. I think it can also record the requests it receives.

Thanks for the tip. It appears that when I hardcode my JSON response in my called API, the evaluation JS for REST response embedded in BPMN fails with it :

Here is JS : (it is inline in my file)
var response = connector.getVariable(“response”);
obj = JSON.parse(response);
obj.status;

And here is console output

Header for my HTTP task is Accept application/json. A
appears in response
Edit : I made sure my API response header was with correct MIME. No I’m stuck with the X gateway just behind, so have to test with Postman

@pvermeil can you confirm with something like Postman that you are not receiving HTML as part of the response?

Can you provide a example of what response contains?

I tested in postman and yes, I do receive some HTML parts.

I need to display what is the exact payload sent by my BPMN task to reproduce the error more closely, especially how one of my payload variable is serialized in JSON payload. How to display it ? In cockpit my creditPayload variable appears like this

I assume it’s automatically escaped. I’ll up if I find that problem is from my API

The process var “creditPayload” was passed to Camunda API at process start as
“creditPayload” => array(
“value” => null,
“type” => “Object”,
“valueInfo” => array(
“objectTypeName” => “payload.ProductsAmountsPercents”,
“serializationDataFormat” => “application/json”
)
)

I made my postman test with just an empty JSON. So my response is polluted with HTML and so I can’t map response to variable to go forward.
Thanks for you help :wink:

So step 1. Fix your system’s responses to send proper json responses.

step 2: use a script in your payload parameter of your http-connector to build your payload. Before the last line (if its JS, its usually JSON.stringify(payloadObject)), do a setVariable() with your payload object. This will store the data you want as a process var.

Stephen,

When you say “use a script” in the http-connector, what do you mean? Should the script be a listener, expression? Would you mind sharing an example if that’s convenient?

This is a question I’ve had for a long time because instead of being able to get the actual payload http-connector is going to send, I’ve used Groovy to construct a predicted “facsimile” of what is being sent. My only other option was something like WireShark.

I guess he means a freemarker script as payload in the connector configuration of the task.

The freemarker template files (.ftl) have JSON structure but with the ability to map values to process variables, using the groovy expression form, like
{
“something”: ${myVariable}
}

I’m still a novice with Camunda (and Java !) so correct me if I’m wrong :slight_smile:

edit : for my payload, I don’t use JS but freemarker

You may be correct here. I do in fact use Groovy to construct the facsimile, but Freemarker to build actual payload. I suppose I could capture the payload with WireShark once and compare it to the facsimile to judge its accuracy.

There is no “payloadObject” in the Camunda Javadoc, so I thought may there was a “secret” code to print it out.