Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Capturing a Login Bearer Token for Subsequent Calls - Postman

RSS
Modified on Tue, Dec 01, 2020, 7:05 AM by Administrator Categorized as Visual Studio and Developer Tools

Overview

When working with Postman against APIs secured by a bearer token architecture, it is necessary to login first and submit the associated bearer token with the API call. This article presents a simple mechanism for doing so.

Acknowledgements

Thanks to Dan Williams for providing the code below!

Procedure

(1) Create a request for your Login API

(2) On the Tests tab, add the following code, which will capture the bearer token in the Postman variable "token".

pm.test("Extract Token", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData.token).to.not.equal(null);
    pm.environment.set("token", jsonData.token);
});

(3) For the secured API request, navigate to the Authorization tab.

(4) For the type, select "Bearer Token".

(5) For the Token, specify

{{token}}

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2021, Patrick Jasinski.