postmanpostman-collection-runner

How do I set up a bearer token in Postman from an environment variable?


I have set up a collection in Postman and am able to save my bearer token value to an environment variable successfully using the following test:

var jsonData = JSON.parse(responseBody);
pm.environment.set("mytoken", jsonData.token);

But how do I set up a new call to use it?

I have tried adding a Header with

Authorization Bearer <mytoken>

But when I post, the status is 401 Unauthorized.


Solution

  • In the headers, I needed to use:

    For the key:

    Authorization
    

    For the value

    Bearer {{mytoken}}