I'm trying to acquire two fields of information of a response body from a VTEX API.
In tests, I currently have:
tests[` ${responseBody}`] = true;
In return I receive:
[{"categoryId":"default","categoryName":"null","categoryFullPath":null,"productCommissionPercentage":12.00,"freightCommissionPercentage":12.00}]
I'm looking to extract productCommissionPercentage and freightCommissionPercentage numbers from a list of sellers that I upload via postman runner.
The uploaded CSV looks like this:
sellerId
xxxx
yyyy
zzzz
I'm looking to have in return something like this, the intent is to easily keep track of seller commisions
sellerId productCommissionPercentage freightCommissionPercentage
xxxx 10 12
yyyy 12 8
zzzz 11 10
You can access the response json in your tests via pm.response.json() if that's all you're looking for.
If you want to display the results as a table, add the following to your request's Tests section:
var template = `
<table bgcolor="#FFFFFF">
<tr>
<th>sellerId</th>
<th>productCommissionPercentage</th>
<th>freightCommissionPercentage</th>
</tr>
{{#each response}}
<tr>
<td>{{sellerId}}</td>
<td>{{productCommissionPercentage}}</td>
<td>{{freightCommissionPercentage}}</td>
</tr>
{{/each}}
</table>
`;
// Set visualizer
pm.visualizer.set(template, {
// Pass the response body parsed as JSON as `response`
response: pm.response.json()
});
This assumes the response contains the sellerId as a field as well. If it doesn't, you'll need to match it with the ids from your request body, assuming they're in the same order.