Variable mapping with Rest JS answer

Hello everyone.

In my process, I’m making a POST call, and the answer is set to an external JS, as shown on the Rest service task github. However I don’t understand well its syntax. As you know it looks like this:

// fetch execution variables
var response = connector.getVariable("response");
var date = connector.getVariable("date");

// parse response variable with camunda-spin
var holidays = S(response);

var query = "$.[?(@.datum=='" + date + "')]";

// use camunda-spin jsonPath to test if date is a holiday
!holidays.jsonPath(query).elementList().isEmpty();

My output parameter for the call is a script like this one. But my Rest response will be a JSON like this :
{
“creditSuccess”: “YES”,
“message”: “aMessage”
}

I’d like to map each of these two values in two process variables I already have. I’ve seen this topic :

But didn’t understand well the code samples. Here is a screenshot of my connector :

How can I achieve the mapping ? Thanks :slight_smile:

I still don’t understand the mapping mechanism of the script. What is extracted from process, and what is from Rest response :slight_smile:

@pvermeil based on your sample data:

{
   "creditSuccess": "YES",
   "message": "aMessage"
}

Your outputParameter script should read something like:

S(response).prop('creditSuccess').value();

and your second output would be:

S(response).prop('message').value();

The response variable is automatically available as per: https://docs.camunda.org/manual/7.6/reference/connect/http-connector/#using-the-generic-api-1

Don’t mean to hijack your post here, but is there any way to get the payload that was constructed by the HTTP connector so that we’ll know exactly what was sent? Otherwise you have to rely on a simulated value (as when you use Freemarker) or wire level capture (WireShark).

I got it for the script, using typically :

var response = connector.getVariable(“response”);
obj = JSON.parse(response);
obj.status

If I want “status” in REST response. However I’m not sure how to map, on the other side, a process var to JSON payload entries. For example, with groovy, the payload
{
“subscriptions”: ${subscriptions}
}
does not seem to work.

Thanks and have a good day