Hi, try this JavaScript test script in Postman:
// Test if the response status code is 200
pm.test("Response status code is 200", function () {
pm.response.to.have.status(200);
});
// Test and filter the response based on product type and isBoundToConfigTemplate
pm.test("Filters the JSON response data to find networks with the 'wireless' product type that are not bound to a configuration template", function () {
// Parse the JSON response data
var jsonData = pm.response.json();
// Filter the array of networks based on specified conditions
var filteredNetworks = jsonData.filter(function (network) {
return network.productTypes.includes('wireless') && network.isBoundToConfigTemplate === false;
});
// Assert that the filteredNetworks array is not empty
pm.expect(filteredNetworks).to.be.an('array').and.not.empty;
// Store the filteredNetworks array in the environment as a JSON string
pm.environment.set('filteredNetworks', JSON.stringify(filteredNetworks));
});
This Postman test script validates an API response:
1. It checks if the response status code is 200.
2. It filters the JSON response data to find networks with the 'wireless' product type that are not bound to a configuration template.
3. The filtered network array is asserted to be non-empty, and the result is stored in the environment as a JSON string for further use.
Make sure that you have created an environment in Postman.
Feel free to ask!