Friday 20 May 2022

How to set JWT Token as postman environment variable and use it for "Bearer Token" type in POST request Authorization

 Hi, 

Bearer token response body: 

{
	"token_field1": "TokenField1ValueInEncodedFormat",
	"token_lasts_for_howmanyms": 7200, //2 mins
	"type_of_token": "Bearer"
}

Write below script in "Tests" tab of SOAP POST request (not in Pre-request scripts)

NOTE:
Token generated will get stored in VarJWTToken where VarJWTToken is an environment variable created in the environment.  
var data = JSON.parse(responseBody);
postman.clearEnvironmentVariable("VarJWTToken");
postman.setEnvironmentVariable("VarJWTToken", data.token_field1);

Use the VarJWTToken environment variable in request Authorization as shown in below image: 
Postman collection format: 
Token  (Token generated in this request will get stored in environment variable)
   SOAP POST Request (using environment variable POST authentication will be done) 

No comments:

Post a Comment