# How to get the HTTP status code from a response as a integer in the test script?

**URL:** <https://community.postman.com/t/how-to-get-the-http-status-code-from-a-response-as-a-integer-in-the-test-script/25131>\
**Category:** Help Hub\
**Created:** [June 23, 2021, 12:49pm UTC](https://community.postman.com/t/how-to-get-the-http-status-code-from-a-response-as-a-integer-in-the-test-script/25131 "2021-06-23T12:49:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kesorup](https://avatars.discourse-cdn.com/v4/letter/k/5e9695/32.png) [@kesorup](https://community.postman.com/u/kesorup)\
**Post date:** [June 23, 2021, 12:49pm UTC](https://community.postman.com/t/how-to-get-the-http-status-code-from-a-response-as-a-integer-in-the-test-script/25131/1 "2021-06-23T12:49:52Z")

</div>

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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![neilstudd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/neilstudd/32/8213_2.png) [@neilstudd](https://community.postman.com/u/neilstudd)\
**Post date:** [June 23, 2021, 1:24pm UTC](https://community.postman.com/t/how-to-get-the-http-status-code-from-a-response-as-a-integer-in-the-test-script/25131/2 "2021-06-23T13:24:09Z")

</div>

Hi @kesorup,

To cut a long story short, what you’re look for is `pm.response.code` - this will be a numeric value e.g. `200`.

For more details of the response values that are available, you can review the “Scripting with response data” reference documentation:

> **[Postman JavaScript reference](https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#scripting-with-response-data)**

---

<div class="post-metadata">

**Author:** ![kesorup](https://avatars.discourse-cdn.com/v4/letter/k/5e9695/32.png) [@kesorup](https://community.postman.com/u/kesorup)\
**Post date:** [June 24, 2021, 9:12am UTC](https://community.postman.com/t/how-to-get-the-http-status-code-from-a-response-as-a-integer-in-the-test-script/25131/3 "2021-06-24T09:12:42Z")

</div>

Thank you Neil! I’ve read that page but somehow still managed to miss it. My collection is working as I wanted now 🙂
