Getting response body of request when using pm.sendRequest

My question:
I have a test script where i run a GET request using pm.sendRequest in a loop. I want to get the response body of that request, so that I can check if the repsonse body has a specific value set to TRUE.

When I run the test script below, the data variable contains the respose body of the reqeust where I am running the test script and not from the request send by the pm.sendRequest. How do i get that response body?

Any help will be much appreciated

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);

    var jsonData = pm.response.json();
    var auth = pm.environment.get("Autherization");

    for (let i = 0; i < jsonData.length; i++) {
        pm.sendRequest({
            url: pm.environment.get("baseUrl") + "/sessions/" + jsonData[i].guid,
            method: 'GET',
            header: {
                'Authorization': auth,
            }
        }, (error, response) => {
            var data = JSON.parse(responseBody);
            console.log(data);
            if (response.active === true)
                pm.environment.set("site_active_guid", response.json().guid);
        
        });
    }

});

Hey @lastyousee, Welcome to the community :clap:

All you have to do is use the ‘response’ variable of your ‘pm.sendRequest’ method.
Your for loop should look something like this:

for (let i = 0; i < jsonData.length; i++) {
        pm.sendRequest({
            url: pm.environment.get("baseUrl") + "/sessions/" + jsonData[i].guid,
            method: 'GET',
            header: {
                'Authorization': auth,
            }
        }, (error, response) => {
            var data = response.json();
            console.log(data);
            //Can also use data variable to assert
            if (response.active === true)
                pm.environment.set("site_active_guid", response.json().guid);
        });
    }

Good luck!