How to get on the number of items in the following response:

{
“Status”: 0,
“Message”: “Successfully received 47 items for Folder (Account_075), File (File_109) and IsBoolean (False) as expected”,
“Code”: 0

}

I need to get the value = 4 and set it as a test variable for the following row in my test:

pm.response.to.have.jsonBody(“Message”, “Successfully received… as expected”)

Thanks!!!

Postman uses JavaScript under the hood.

It appears that Message will be a string, therefore I recommend looking up string manipulation, as you’re going to have to slice and dice the string.

JavaScript String Methods (w3schools.com)

If the response is always xx items, then you may be able to assert on Includes(“47 items”) if that is acceptabe. Set the message (actual result) as its own variable.

var message = pm.response.json().Message;

pm.test("47 items", () => {
    pm.expect(message).to.include("47 items");
});
1 Like