Service Call Response is always [Object object]

Hello,

my api call response is alwys [Object object] no matter what object in the response i am trying to access.

The URL is: https://jsonplaceholder.typicode.com/posts/

And i am trying to access any object with: {{context.CheckLicensePlateServiceCall.response.body}}

What am i doing wrong?

Thank you

Hello @rpoledniok ,

If the API response is an array then you will have to use proper formatting to print the objects of the array.

For example:

If context.<servicenode>.response.body.queryResult – with queryResult being part of the response body has the relevant data which is an array then you may use script as below:

var data= context.<servicenode>.response.body.queryResult;
if (data.length>1)
{
    var data= context.<servicenode>.response.body.queryResult;
    for(var i=0;i<data.length;i++){
    var currentItem = {};
        CurrentItem = {
            Name: data[i].PersonName ,
            SSN: data[i].SSN ,
            Phone: data[i].Phone,
            Email: data[i].Email
    
        }
        context.session.BotUserSession.queryResult.push(CurrentItem)
    }
}

And when printing the data, use for loop to print data from context.session.BotUserSession.queryResult[i]

This is simply one of the ways to handle the response. You may use other scripting logics per your choice. Hope this helps :wink:

1 Like

What is api result is in this format
“statusCode”: 200,
“body”: {
“parsedTime”: [
{
“body”: “now”,
“start”: 0,
“value”: “2024-10-11T19:14:55.595+05:30”,
“end”: 3,
“dim”: “time”,
“latent”: false,
“grain”: “second”,
“formatted”: “11/10/2024”,

and I want to use “formatted” value to show in next message node…
context..response.body. have tried this, not working