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

Page History: Capturing a Login Bearer Token for Subsequent Calls - Postman

Compare Page Revisions



« Older Revision - Back to Page History - Current Revision


Page Revision: Tue, Sep 14, 2021, 1:46 PM


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) Within a Postman Collection, 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-2024, Patrick Jasinski.