*** title: How to dynamically set the initial value for a variable description: >- Using the Postman API , you can modify the initial value of a variable from a script. This article explains how to use the endpoint Replace an environment's ... --- Using the [Postman API](https://www.postman.com/postman/postman-public-workspace/collection/i2uqzpp/postman-api), you can modify the initial value of a variable from a script. This article explains how to use the endpoint [Replace an environment's data](https://www.postman.com/postman/workspace/postman-public-workspace/request/12959542-9f175bea-1df5-44e6-af33-bf2de7f85bb5) to replaceĀ an existing environment. 1. Get the [Environment ID](/help/faqs/collections-and-workspaces/how-to-find-the-id-of-an-element-in-postman) of the target environment and copy it. 2. [Create a fork](/docs/collaborating-in-postman/using-version-control/forking-elements/#create-a-fork) of the [Postman API collection](https://www.postman.com/postman/workspace/postman-public-workspace/collection/12959542-c8142d51-e97c-46b6-bd77-52bb66712c9a?ctx=documentation) in your workspace. ![fork.png](https://files.buildwithfern.com/postman.docs.buildwithfern.com/9e36e86779d9b7c94a6cd4703dd397aa852245b6794b282aad43271b1e1568b5/docs/assets/help/34024068320535.png) 3. When the fork is created in your workspace, go to the Postman API collection > Environments > **PUT Replace an environment's data** . 4. Hover over the unresolved variable \{\{environmentId}} in the Path Variables Section. ![pathvariablenv.png](https://files.buildwithfern.com/postman.docs.buildwithfern.com/af73d231da1e9c3e482a2bfe39e18b1115f95cfa924fcd27d9f57304d57e1092/docs/assets/help/34024068322839.png) 5. Paste the **Environment ID** copied in step 1 in the **Enter** **Value** field. 6. Generate a [Postman API](/docs/developer/postman-api/authentication/#generate-a-postman-api-key) key for your account and add it to the **Authorization** tab to [authorize](/docs/sending-requests/authorization/authorization/) this request. 7. Open the **Body** tab and duplicate the format to match the existing number of variables currently in your environment, plus the number of variables you would like to add. 8. Enter the Name, Key, Value, [Type](/docs/sending-requests/variables/variables/#variable-types), and enabled status for each of the variables. * **Note:** The [PUT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT) request will delete everything that is not specified in the request, and only the key-value pairs that are passed will be stored in the environment. Make sure that any existing variables are added with the same name to avoid breaking any requests already using the environment and its variables. 9. Select **Send Request** . * **Note:** The `pm.environment.set` code snippet only exposes access to the current value of a variable. *** Have more questions? [Submit a request](/help/submit-request) ***