How to automatically inject tokens in postman calls without copy pasting it in every request call ??

  • One of the annoying task while making postman calls , is to generate the access token and then copying it and pasting it in every request call.
  • One of the easy way to handle this is , by using the postman variables.
  • Basically, you can generate a token or any other value and can store it in a postman variable and can use the variable name .
  • In this example, i will show how to store a token in a variable, but the environment and variable feature of POSTMAN can be used for many other things as well.
  • Click on environment
  • Click on Global
  • Give any name to the variable and click Save
  • Now assuming your response looks something like below

  • Click on test tab
  • Paste the below code, which parses the response and stores access token in the variable name defined at global level
var data = JSON.parse(responseBody);
postman.setGlobalVariable("dev-okta-token", data.access_token);
  • Now when you generate a token, it gets stored in the variable and you just need to use the variable name instead of using the response.
  • Example

Thank You !!!

Leave a Reply