Hi Postman community
My question:
I’m trying to get the HTTP status code from a Response as an Integer. Right now I have:
var status = pm.response.status;
And I have tried a couple other options like responseBody.code; but I haven’t found the right one yet. When I try to parse this is an int, I see that it is not a number. So how do I get the http status as an integer?
Reason why I want this:
The calls in my collection are a bit flaky. In order to check the healthiness of those endpoints first (and fail fast in case they are not healthy) I want to add 2 healthcheck calls to my collection first. Then I want to check the http status code for the healtcheck calls
if it’s 200, fine, continue (using postman.setNextRequest())
if it’s not then I want to wait a bit and retry the healthcheck (while keeping a counter to limit the amount of times the calls will retry)
So this is roughly what I have, but the status is not a number and cannot be compared to 200:
var status = pm.response.status;
if (status == 200) {
postman.setNextRequest("Next healthcheck call");
} else {
//...some logic for waiting and retrying the healthchecks
}
Please let me know how to get that HTTP status as a integer or a different way to achieve this. Thank you!