Sitemap
Better Practices

For individual engineers to the largest teams, Better Practices is intended to distill knowledge from the Postman community. This is a place to learn about modern software practices together! Read more: https://medium.com/better-practices/introducing-better-practices-e9cf14cf0c88

Dynamically create custom environments with code

Joyce Lin
5 min readDec 1, 2021

--

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")),  (n.id = s + t), (n.async = 1), (n.src = m), n  ));}(window, document, "_pm", "PostmanRunObject", "https://run.pstmn.io/button.js"));

--

--

Better Practices
Better Practices

Published in Better Practices

For individual engineers to the largest teams, Better Practices is intended to distill knowledge from the Postman community. This is a place to learn about modern software practices together! Read more: https://medium.com/better-practices/introducing-better-practices-e9cf14cf0c88

Joyce Lin
Joyce Lin

Written by Joyce Lin

coding and cats in San Francisco

No responses yet