How to log query string parameters with Postman

2.5k views Asked by At

I'm using the tests of Postman to log into the console some of the details included in a JSON response. The part of the test that logs is the following:

var data = JSON.parse(responseBody);

if (data.result[0] !== undefined) {
console.log(data.result[0].number, "|", data.result[0].category;    
}
else console.log(QUERYSTRING_PARAMETER, "is not present");

I've tried many sintaxes/formats to have the value of the QUERYSTRING_PARAMETER passed to the test. However when data.result is empty with every sintax I've tried, the test simply logs QUERYSTRING_PARAMETER not defined. How can I pass the value from the query string parameters in the URL to the test to be evaluated/logged?

Thanks in advance

1

There are 1 answers

0
A.Joly On

I'm not sure if it corresponds to what you need, but if you want data from your query, you may use the 'request' object (refer to the Postman sandbox, paragraph 'Request/response related properties'). You can get request method, url, headers and (maybe the one for you) data.

Alexandre