# Use Environment.Set Variable in URL and Body

**URL:** <https://community.postman.com/t/use-environment-set-variable-in-url-and-body/17987>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [November 24, 2020, 4:32pm UTC](https://community.postman.com/t/use-environment-set-variable-in-url-and-body/17987 "2020-11-24T16:32:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Everett\_Comstock](https://avatars.discourse-cdn.com/v4/letter/e/43a26b/32.png) [@Everett\_Comstock](https://community.postman.com/u/Everett_Comstock)\
**Post date:** [November 24, 2020, 4:32pm UTC](https://community.postman.com/t/use-environment-set-variable-in-url-and-body/17987/1 "2020-11-24T16:32:31Z")

</div>

I’m attempting to create a request that uses a custom variable in both the request URL and Body. If I create a **Pre-request Script** variable like this:

`pm.environment.set("Id", "test");`

then everything works just fine. However, if I do something like this:

`pm.environment.set("Id", "{{$guid}}");`

then I end up with a different value in the URL and the Body.

I assume this has something to do with the the `{{$guid}}` variable value being created by a function. With this in mind, I updated my **Pre-request Script** to assign the `{{$guid}}` variable result to a const local variable… but I still see the same behavior.

```
const value = "{{$guid}}";
pm.environment.set("Id", value);

```

 ![Postman_Variable_1](https://us1.discourse-cdn.com/getpostman/original/3X/6/b/6b086c55f8012a0af6ec67902571369c69b7e73b.png) ![Postman_Variable_2](https://us1.discourse-cdn.com/getpostman/original/3X/a/9/a9ea07069985603d73d0e672e00cba7b3a12c5f7.png)

Is it possible to use the `{{$guid}}` variable in this case?

Thanks!

---

<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 24, 2020, 5:15pm UTC](https://community.postman.com/t/use-environment-set-variable-in-url-and-body/17987/2 "2020-11-24T17:15:40Z")

</div>

Hey @Everett_Comstock

> [@Everett\_Comstock](#):
>
> `const value = "{{$guid}}";`

This would need to be like this in the script:

```auto
const value = pm.variables.replaceIn("{{$guid}}")

```

You cannot directly use the `{{...}}` syntax in the sandbox so that’s where `.replaceIn()` comes in to help out.

> **[Manage API data and workflows using Postman JavaScript objects | Postman...](https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#using-variables-in-scripts)**
>
> Manage API data and workflows using Postman JavaScript objects: documentation for Postman, the collaboration platform for API development. Create better APIs—faster.

---

<div class="post-metadata">

**Author:** ![Everett\_Comstock](https://avatars.discourse-cdn.com/v4/letter/e/43a26b/32.png) [@Everett\_Comstock](https://community.postman.com/u/Everett_Comstock)\
**Post date:** [November 24, 2020, 5:18pm UTC](https://community.postman.com/t/use-environment-set-variable-in-url-and-body/17987/3 "2020-11-24T17:18:45Z")

</div>

@danny-dainton,

Thanks very much! That made quick work of my issue!

---

<div class="post-metadata">

**Author:** ![amenibt](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@amenibt](https://community.postman.com/u/amenibt)\
**Post date:** [November 25, 2020, 9:25am UTC](https://community.postman.com/t/use-environment-set-variable-in-url-and-body/17987/4 "2020-11-25T09:25:46Z")

</div>

that may help you :[https://learning.postman.com/docs/sending-requests/managing-environments/](https://learning.postman.com/docs/sending-requests/managing-environments/) @Everett_Comstock
