Javascript callout policy response this error. How can i resolve?

this is my js code

var payload = JSON.parse(request.content);
var headers = {'Content-Type' : 'application/json'};
var url = 'https://jsonplaceholder.typicode.com/posts';
var operation = "POST";
var req = new Request(url, operation, headers, payload);
var calloutResponse1 = httpClient.send(req);
context.session['calloutResponse1'] = calloutResponse1;

I use this curl for call proxy

curl -k https://xxxxxx/poc3 -d '{"name": "Apple MacBook Pro 16", "data": "s"}'

this is response error from js callout

{"fault":{"faultstring":"Execution of callapi1 failed on line callapi1_js#5 with error: Unexpected Type. Expected \"String\" got \"NativeObject\"","detail":{"errorcode":"steps.javascript.ScriptExecutionFailedLineNumber"}}}

@dchiesa1 

0 3 187
3 REPLIES 3

You’re trying to set a native object into the message context. That won’t work. 

what is your real goal? Why are you attempting to preserve the calloutResponse? 

Also, possibly related: have you considered using the callback approach?  Apigee documentation  recommends it over the callbackResponse approach. 

Using a callback approach, you will not save, examine, or assign the return value of httpClient.send().  You ignore that return value.  

my goal is to make asynchronous calls API.

suchansinee_0-1673274986311.png

Should I use the js callout policy or the service callout policy?

making multiple asynchronous calls via the JS callout and the httpClient will work.  Use the callback mechanism with httpClient. Search this community site for previous answers for hints.