Customize your Run in Postman button

As an API publisher, you can dynamically inject information as environment variables into the Run in Postman 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 your collection and environment into their Postman workspace.

Create a new environment

Create a new, empty environment using the env.create method:

_pm('env.create', 'environment_name', {key: value}, runButtonIndex);

Create a new environment using API keys entered by your user:

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.

Pass a user’s sign-in credentials

Create an environment that contains the user’s sign-in credentials:

_pm('env.create', 'Spotify', {
  user_id: 'spotifyuser',
  authorization: 'Bearer 1234xyzd'
});

Edit an existing environment

Update an environment using the env.assign method:

_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.

Update an environment’s API keys:

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:

_pm('env.replace', 'environment_name', {key: value}, runButtonIndex);

The env.replace method returns true on success and false on failure.

Remove an existing environment

Remove an existing environment using the env.remove method:

_pm('env.remove', 'environment_name', runButtonIndex);

The env.remove method returns true on success or false on failure.

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:

_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:

var runButtons = Array.prototype.slice.call(document.getElementsByClassName('postman-run-button')),
  runButtonIndex = runButtons.indexOf(elem);

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:

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:

_pm('_property.get', 'environments');

This returns a response containing an array of the available environments:

[
  {
    "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.

Last modified: 2026/01/12