The response is an array, which contains objects so in order to access them you need to specify which object you want using [0] - Then it’s just a case of adding the key to the value you need.
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
let jsonData = JSON.parse(responseBody);
pm.test("Apple Wallet Feature is retrived with success.", function(){
pm.expect(jsonData.items).to.have.length>2;
pm.expect(jsonData[2][code]).to.eql("AppleWallet");
});
What do you see logged in the console when you use console.log(pm.response.json())
The script should probably be more like:
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
let jsonData = pm.response.json();
pm.test("Apple Wallet Feature is retrived with success.", function(){
pm.expect(jsonData.length).to.be.above(2);
pm.expect(jsonData[2].code).to.eql("AppleWallet");
});
Are those assertions not going to break if there are more objects pushed to that array?
I will be filtering the API call with Odata, hence the “AppleWallet” is always in 3rd place. So it should not break the assertion when more objects are pushed.