0
votes

I am sending this request in postman https://postman-echo.com/get?record=aaaa

The tests contain the below code:

let arr = ['aaaa'];
pm.globals.set("arr",arr);
let url = "";
for(i=0;i<arr.length;i++)
{
    url="https://postman-echo.com/get?record="+arr[i];
    pm.sendRequest(url,(err, response)=>{
            console.log("sadsadassdWDEW"+response.json());


    });

}

Output in console:

sadsadassdWDEW[object Object]

What I am expecting: response json

{"args":{"record":"aaaa"},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-604a4c29-4708d1643484d5cf445fb170","user-agent":"PostmanRuntime/7.26.10","accept":"/","cache-control":"no-cache","postman-token":"95ef5af8-5188-4869-ab97-1fcc77f3ff8e","accept-encoding":"gzip, deflate, br","cookie":"sails.sid=s%3ABdpZH_SPae8c7hYqFC_mC-17gASiTxNA.WZtCgV36HDHPyFpP7uKyD9AOOBZnh6UbaCpXTCYUP4U"},"url":"https://postman-echo.com/get?record=aaaa"}

Can you tell me where am I going wrong?

1

1 Answers

0
votes
let arr = ['aaaa'];
pm.globals.set("arr",arr);
let url = "";
for(i=0;i<arr.length;i++)
{
    url="https://postman-echo.com/get?record="+arr[i];
    pm.sendRequest(url,(err, response)=>{
            console.log("sadsadassdWDEW"+response.text
            ());


    });

}

use response.text() instead or use JSON.stringify(response.json()) . Insdie console.log we should give string representation of an object, not the object itself