Using Postman how can I stop doing repetitive tasks like copy pasting a token or changing the hostname for several requests |
This knowledge article may contain information that does not apply to version 21.05 or later which runs in a container environment. Please refer to Article Number 000385088 for more information about troubleshooting BMC products in containers. Using Collections and Environments In this postman screenshot we can see that Collections tab is seleted and "SampleCollection" has 5 requests If we were not using "environments" Changing from "localhost" to a "domain name would require 5 manual changes 1. Create a Collection by clicking on the Folder+ Icon You'd be prompted for a Name and once you enter it you 'd see your collection on the left panel 2. Create Requests using variables Instead of creating URLS like https://localhost:8443/api/jwt/login create them like {{protocol}}://{{host}}:{{port}}{{loginpath}} In this way changes to https , host, port or login path would be centralized on your environment variables You can use {{variable}} notation in URLs, Headers and Body at least 3. Access environments clicking this eye Icon Click edit on the Environment Menu Then Cancel and Add (yes its weird) You'd get to this screen Enter a name and click "Bulk Edit" Then paste the following text ---ignore this line / don't copy it jwt:authtoken host:localhost port:443 protocol:https prefix:AR-JWT loginpath:/api/jwt/login v1path:/api/arsys/v1 ---ignore this line / don't copy it and click "Update" You'd have created an environment with these basic variables, please fine tune them for your environment 4. Login by executing a POST request to {{protocol}}://{{host}}:{{port}}{{loginpath}} Having header key: Content Type value: application/x-www-form-urlencoded With Body key> username value> any AR server username and a second key> password value> corresponding password If all is correct you'd get a 200 HTTP response and a token such as eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJCYWJK_TRIMMED_y2i-wik4 Select the token completely and right click on the highlighted section You'd get a menu to save the highlighted text as a variable In this case , set it to JWT 5. Make a second Request to GET this URL {{protocol}}://{{host}}:{{port}}{{v1path}}/entry/User Set Authoritzation header to value {{prefix}} {{jwt}} and Content-Type header to application/json If everything is in place you'd get HTTP 200 status and JSON response 7. Then you can export your collections and environments or duplicate them to test on multiple servers / development stages Attached is a Sample Collection and sample environment |