# How to not send param if postman variable is not set

**URL:** <https://community.postman.com/t/how-to-not-send-param-if-postman-variable-is-not-set/8986>\
**Category:** Help Hub\
**Tags:** collections\
**Created:** [November 13, 2019, 3:29pm UTC](https://community.postman.com/t/how-to-not-send-param-if-postman-variable-is-not-set/8986 "2019-11-13T15:29:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![empire29](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/empire29/32/3235_2.png) [@empire29](https://community.postman.com/u/empire29)\
**Post date:** [November 13, 2019, 3:29pm UTC](https://community.postman.com/t/how-to-not-send-param-if-postman-variable-is-not-set/8986/1 "2019-11-13T15:29:51Z")

</div>

I have a problem where I have an optional HTTP Header that specifies which sandbox my API call should hit. leaving this field blank resolves to the production “sandbox”.

Ideally i’d like to create a Postman Env that doesn’t have this field at all, but create collections that include it. It seems that if I set my HTTP Header to have: x-sandbox : {{SANDBOX\_NAME}} and SANDBOX\_NAME env variable is not set, it will send the actual string value of `{{SANDBOX_NAME}}` in the http header, which of course confuses/breaks the API.

Is there some way I can denote my x-sandbox HTTP header to only send if the associated variable is defined?

My collection is re-used across a large team, so I’d like to make this declaration IN the postman collection itself (rather than in a Postman app config, or in the Postman env file since those are not shared across the users of this collection)

---

<div class="post-metadata">

**Author:** ![odanylewycz](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/odanylewycz/32/3240_2.png) [@odanylewycz](https://community.postman.com/u/odanylewycz)\
**Post date:** [November 14, 2019, 4:55am UTC](https://community.postman.com/t/how-to-not-send-param-if-postman-variable-is-not-set/8986/2 "2019-11-14T04:55:26Z")

</div>

Hi @empire29,

Welcome to the community! 👏

Yes this is possible! Doing some quick testing, I was able to produce the following for you:

```
if (pm.environment.get("SANDBOX-NAME") === "") {
    
    pm.request.headers.remove("x-sandbox")

} 

```

If you place the above in a Pre-Request script, you will see your desired behavior.

Here I check if that variable has no value assigned to it. If it does not, it removes the “x-sandbox” header, just as desired. Then otherwise, It will leave the header in there and it gets passed along with the resolved value.

For further reference, check out this video I made on Pre-Request and Test Scripts.

[![](https://img.youtube.com/vi/NA2nfftMC5E/maxresdefault.jpg "Postman Pre Request and Test Scripts Tutorial - Introduction to Postman") ](https://www.youtube.com/watch?v=NA2nfftMC5E)

Let me know if this works!

Regards,  
Orest

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [November 14, 2019, 11:56am UTC](https://community.postman.com/t/how-to-not-send-param-if-postman-variable-is-not-set/8986/3 "2019-11-14T11:56:40Z")

</div>

You could also use the `.has()` function but reverse this so that it would be `true` if it didn’t have the `SANDBOX-NAME` environment variable.

```
if (!pm.environment.has("SANDBOX-NAME")) {
    pm.request.headers.remove("x-sandbox")
}
```

---

<div class="post-metadata">

**Author:** ![empire29](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/empire29/32/3235_2.png) [@empire29](https://community.postman.com/u/empire29)\
**Post date:** [November 18, 2019, 3:22pm UTC](https://community.postman.com/t/how-to-not-send-param-if-postman-variable-is-not-set/8986/4 "2019-11-18T15:22:12Z")

</div>

Thanks - i was hoping for a simple JSON key/value - ill see if i can figure out how to get this into my Swagger -\> Postman Collection conversion script in a sane way. Appreciate the feedback!
