dotnetco.de

Testing Login with Postman and store Bearer Access Token

If you use Postman for Api testing, you might want to store the token returned from your API after login so you could use the token in all further API requests. Here’s a short How-To.

  1. In your collection, go to the “Authorization” Tab. Select Auth Type “Bearer Token”. In the new “Token” field, enter “{{bearer-token}}”
  2. In the upper right of Postman, select your Environment or create a new one.
  3. Now click on “Environment” in the left navigation bar, select your environment and create a new variable “bearer-token”.
  4. In your login call, go to tab “Scripts” and select “Post-response”. Enter the following lines if the token is returned in a json with name “access-token”:
    • let responseData = pm.response.json();
    • pm.environment.set(“bearer-token”, responseData.accessToken);

That’s it already. Now all calls within the selected collection use the access token.

Leave a Comment