Better Practices
Published in

Better Practices

Dynamically create custom environments with code

Reduce time to first call (TTFC) for your public API via Run in Postman

Six Key Things To Know About the Run in Postman Button

You can embed a collection in this tiny, unassuming button.

You can bundle an environment along with the collection.

You can use the button in your docs.

You can customize the form factor.

example of a stylized Run in Postman button in developer docs

The Run in Postman button has its own API.

Dynamically Create Postman Environments

Dynamically inject data into Postman environments

Step 1. Generate the button

Generate a live version of the Run in Postman button

Step 2. The HTML elements

<div class="postman-run-button" data-postman-action="collection/fork"  data-postman-var-1="1559979-8aa8a323-6308-429c-90ca-e85d1d0bb33e"  data-postman-collection-url="entityId=1559979-8aa8a323-6308-429c-90ca-e85d1d0bb33e&entityType=collection&workspaceId=ef3cdedd-f58c-4492-9ed0-4dcf456987b2"></div>
<form method="post" onsubmit="return createEnv();">  <label for="secretstring">Passphrase</label>  <input type="text" id="secret-string" name="secretstring"><br><br>  <input type="submit" value="Save"></form>

Step 3. The JavaScript functions

function createEnv() {  var secretString = document.getElementById('secret-string').value,    runButtonIndex = 0,    envData = {      passphrase: secretString  };  _pm('env.create', 'Passphrase', envData, runButtonIndex);  return false;}
(function (p, o, s, t, m, a, n) {  !p[s] && (p[s] = function () { (p[t] || (p[t] = [])).push(arguments); });  !o.getElementById(s + t) && o.getElementsByTagName("head")[0].appendChild((  (n = o.createElement("script")),  ( = s + t), (n.async = 1), (n.src = m), n  ));}(window, document, "_pm", "PostmanRunObject", ""));



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store