***
title: Customize your Run in Postman button
updated: 2026-01-12T00:00:00.000Z
topictype: reference
slug: docs/publishing-your-api/run-in-postman/customize-run-button
max-toc-depth: 2
----------------
As an API publisher, you can dynamically inject information as environment variables into the [**Run in Postman** button](/docs/publishing-your-api/run-in-postman/creating-run-button/). You can customize and embed this button in your website's client-side code so users can begin making calls to your API using Postman's `_pm()` method. The **Run in Postman** button enables users who click it to [fork](/docs/publishing-your-api/run-in-postman/creating-run-button/#use-a-run-in-postman-button) your collection and environment into their Postman workspace.
## Create a new environment
Create a new, empty environment using the `env.create` method:
```javascript
_pm('env.create', 'environment_name', {key: value}, runButtonIndex);
```
You can't use this method to duplicate environments. Any calls made using existing environment names will fail.
Create a new environment using API keys entered by your user:
```javascript
function () {
var stagingKey = document.getElementById('staging-key-input').value,
productionKey = document.getElementById('production-key-input').value,
runButtonIndex = 0,
envData = {
stagingKey: stagingKey,
productionKey: productionKey
};
_pm('env.create', 'API Keys', envData, runButtonIndex);
}
```
The `env.create` method returns the total number of environments associated with **Run in Postman** buttons on the page on success and `false` on failure.
This creates an environment, but doesn't set it as the active environment.
## Pass a user's sign-in credentials
Create an environment that contains the user's sign-in credentials:
```javascript
_pm('env.create', 'Spotify', {
user_id: 'spotifyuser',
authorization: 'Bearer 1234xyzd'
});
```
## Edit an existing environment
Update an environment using the `env.assign` method:
```javascript
_pm('env.assign', 'environment_name', {key: new_value, new_key: value}, preventOveride, runButtonIndex);
```
This method works for environments included in the **Run in Postman** button on creation, or environments added using the `env.create` method.
You can't use this method to create new environments. Any calls made using the `env.assign` method fail if the environment doesn't already exist.
Update an environment's API keys:
```javascript
function () {
var stagingKey = document.getElementById('staging-key-input').value,
productionKey = document.getElementById('production-key-input').value,
preventOveride = true,
runButtonIndex = 0,
envData = {
stagingKey: stagingKey,
productionKey: productionKey
};
_pm('env.assign', 'API Keys', envData, preventOveride, runButtonIndex);
}
```
The `env.assign` method returns `true` on success and `false` on failure.
## Replace an existing environment
Replace the entire contents of an environment using the `env.replace` method:
```javascript
_pm('env.replace', 'environment_name', {key: value}, runButtonIndex);
```
The `env.replace` method returns `true` on success and `false` on failure.
You can't use this method to replace an environment which doesn't exist.
## Remove an existing environment
Remove an existing environment using the `env.remove` method:
```javascript
_pm('env.remove', 'environment_name', runButtonIndex);
```
The `env.remove` method returns `true` on success or `false` on failure.
The environment must exist or this method will fail.
## Use multiple buttons with separate environments
You can embed multiple buttons on a single page. To include a different environment for each **Run in Postman** button, enable the `segregateEnvironments` property:
```javascript
_pm('_property.set', 'segregateEnvironments', true);
```
If you enable `segregateEnvironments`, you must use `runButtonIndex` in all `_pm()` methods to reference each button according to its position in your page [DOM](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model):
```javascript
var runButtons = Array.prototype.slice.call(document.getElementsByClassName('postman-run-button')),
runButtonIndex = runButtons.indexOf(elem);
```
Because `segregateEnvironments` is deactivated by default, `runButtonIndex` is optional by default.
### Use the index for jQuery
Use the following to return a jQuery object containing an index of all elements matching the `postman-run-button` query:
```javascript
var runButtonIndex = $('postman-run-button').index(elem);
```
The response contains the index location for all elements that match.
## Get all environments
Use the `get()` method to retrieve all environments:
```javascript
_pm('_property.get', 'environments');
```
This returns a response containing an array of the available environments:
```json
[
{
"button_index": 0,
"name": "env1",
"values": [
{
"key": "testKey",
"value": "testValue",
"enabled": true
}
]
}
]
```
## Next steps
After creating a **Run in Postman** button, you can share your API with users by creating documentation in a public workspace.
* To learn how to create API documentation in Postman, see [Document your APIs in Postman](/docs/publishing-your-api/api-documentation-overview/).
* To learn how to add your documentation to your public workspaces, see [Publish documentation in Postman](/docs/publishing-your-api/publishing-your-docs/).