# Issue with Environment Variable Resolution

**URL:** <https://community.postman.com/t/issue-with-environment-variable-resolution/51549>\
**Category:** Help Hub\
**Tags:** tests, variables\
**Created:** [September 8, 2023, 3:27pm UTC](https://community.postman.com/t/issue-with-environment-variable-resolution/51549 "2023-09-08T15:27:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hooper7775](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@hooper7775](https://community.postman.com/u/hooper7775)\
**Post date:** [September 8, 2023, 3:27pm UTC](https://community.postman.com/t/issue-with-environment-variable-resolution/51549/1 "2023-09-08T15:27:53Z")

</div>

I am currently experiencing an issue with environment variable resolution within a pre-request script in Postman. Here are the details of the problem:

**Description:** I have set up an environment variable named `organization_url`, with an initial value of `{{base_url}}/organizations`. When I use this variable in a request URL, the value resolves correctly. However, when I attempt to retrieve the value of `organization_url` within a pre-request script using `pm.variables.get("organization_url")`, it does not return the resolved value; instead, it returns “{{base\_url}}/organizations.”

**Steps I’ve Taken:**

1. Ensured that the variable name in the script matches the name in the environment (`organization_url`).
2. Confirmed that I am running the request within the correct environment.
3. Verified that the environment variable’s value is correctly set to `{{base_url}}/organizations`.
4. Attempted to use a different variable name in the script (`test_variable`) with the same value to isolate the issue, and encountered the same problem.

**Expected Behavior:** I expect the pre-request script to retrieve the resolved value of `organization_url`, which should be `https://test-api.teamplay.studio/organizations`.

**Actual Behavior:** The pre-request script currently returns “{{base\_url}}/organizations” instead of the resolved value.

I would greatly appreciate your assistance in resolving this issue. Please let me know if you need any further information or if there are any troubleshooting steps I should follow.

---

<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:** [September 8, 2023, 3:41pm UTC](https://community.postman.com/t/issue-with-environment-variable-resolution/51549/2 "2023-09-08T15:41:54Z")

</div>

Hey @hooper7775 👋

Welcome to the Postman Community! :postman:

To use the variable like that in a script, you’re going to need to use `pm.environment.replaceIn('{{organization_url}}')` so that it can resolve the variable, that you have within that string.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/3/6/3636212aeb7f1072dc60055c8f53f0ebf66d29c9.png)

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/8/8/889f039530f40d161887eb9817ad994fb61701d4.png)

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

---

<div class="post-metadata">

**Author:** ![hooper7775](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@hooper7775](https://community.postman.com/u/hooper7775)\
**Post date:** [September 8, 2023, 4:49pm UTC](https://community.postman.com/t/issue-with-environment-variable-resolution/51549/3 "2023-09-08T16:49:09Z")

</div>

Wow, thanks, you are the best i was trying with pm.environment.replaceIn({{organization\_url}}), but it didn’t work right cause i haven’t used “”. Why in documentation it is written so strange? ```  
pm.variables.replaceIn(variableName:String):function:

---

<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:** [September 8, 2023, 5:03pm UTC](https://community.postman.com/t/issue-with-environment-variable-resolution/51549/4 "2023-09-08T17:03:39Z")

</div>

You’re welcome. 🏆

That page only shows which `datatype` is required in the function. A better page with an example, would have maybe been this one:

> **[Dynamic variables | Postman Learning Center](https://learning.postman.com/docs/writing-scripts/script-references/variables-list/)**
>
> Dynamic variables: documentation for Postman, the collaboration platform for API development. Create better APIs—faster.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [September 11, 2023, 5:04pm UTC](https://community.postman.com/t/issue-with-environment-variable-resolution/51549/5 "2023-09-11T17:04:06Z")

</div>

Closed on September 11, 2023, 5:04pm UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
