new to this syntax, what about if the json had no root, how do you use the Json as Json Array length: pm.test(Count: ${pm.response.json().length}) seems to only look at the entire json?
In the above example he is storing the parsed response under the variable “data”
in your case it should be
const responseJson = pm.response.json();
var count = Object.keys(responseJson).length;
console.log("The number of expected keys in the response body is: " + count);
Our API fetches total records/total books. Further it provides details such book id, book name, author name etc. as a array in response.
Now I want to validate the pagination. Suppose the total books is equal to 768, and in the request body I have provided pageSize as 100 and pageNumber as 1, the response I get is something as below.
So ideally I should be getting 8 pages, first 7 pages should have 100 each and the last page should have 68. How can I validate the pagination that each page is having 100 books each.
@shivabagli I’d recommend opening a new topic since this is a different problem.
For what it’s worth the answer will highly depend on how the API is designed. Typically an API with pagination will give a token to the next page, if that’s the case for yours then you can loop over the request until there isn’t a next token anymore and keep count of the book items.