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:
Important
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:
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.
Note
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:
Edit an existing environment
Update an environment using the env.assign method:
This method works for environments included in the Run in Postman button on creation, or environments added using the env.create method.
Important
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:
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:
The env.replace method returns true on success and false on failure.
Important
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:
The env.remove method returns true on success or false on failure.
Important
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:
If you enable segregateEnvironments, you must use runButtonIndex in all _pm() methods to reference each button according to its position in your page DOM:
Note
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:
The response contains the index location for all elements that match.
Get all environments
Use the get() method to retrieve all environments:
This returns a response containing an array of the available environments:
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.
- To learn how to add your documentation to your public workspaces, see Publish documentation in Postman.