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