Console.log responsebody

I’m not an expert, I’m sorry I wasn’t able to find this but I’m trying to include a test in order to console.log the response body of the json after the api response comes back.

I attempted the following:

var jsonData = pm.response.json();
console.log(JSON.stringify(jsonData.results))

I think this might have to do with needing to do a function now?
Does everything need to be in a function like:

pm.test(“console log”, function () {
var jsonData = pm.response.json();
console.log(JSON.stringify(jsonData.results))
});

Thanks for your help

Hey @Maniwar619,

Welcome to the community :wave:

If you just wanted to log the whole response body to the Postman console, this would be all you need.

console.log(pm.response.json())

You can also see this information in the without adding the console.log() statement to the sandbox environment. If you expand the network information for the request, from the console, you will be able to see the response body data.

Did you want to capture some specific values from the response? If so, could you add a sample of the response to the question and we can work out a solution for this too. :grin:

1 Like

Hello Danny, thank you so much for your reply!

I’m running the collection runner through a list of ids I need to have the user account either created, or suspended in Zendesk in this user case. the output i’m looking for is the response body for each instance.

{
    "job_status": {
        "id": "",
        "url": ",
        "total": 1,
        "progress": 1,
        "status": "completed",
        "message": "Completed at 2019-10-22 19:46:16 +0000",
        "results": [
            {
                "action": "update",
                "status": "Updated",
                "success": true,
                "id": 
            }
        ]
    }
}

Could I get just the “results” for each instance in the console log so I can verify everything worked?

Something like this, added to the Tests tab would get you the first object in the results array:

console.log(pm.response.json()["job_status"].results[0])

If there’s more than 1 object in that array, you would need to loop through it to log all the separate objects.