Save Access Token in Postman

IMPORTANT: USE ONLY ON COMPUTERS THAT ARE NOT SHARED WITH OTHERS AND YOU ARE SURE THAT OTHERS CANNOT ACCESS

I wanted to share this with the community as I find this approach very helpful while using Postman to access various APIs. If you have been copying and pasting the access token after getting a new one every time it expires (like I used to do) this approach could make your life a little easier.

Step 1: Create a Environment, by clicking on the tiny icon to the right of “No Environment” and click on “Add” (screen-snip below)

Step 2: Add details as shown below


Now click on 3 dots to the right of “Current Value” and click on Reset all. This will copy the values you entered under “Initial Value” column to “Current Value” column

Step 3: Create a new “POST” Request, with URL string https://{{tenant}}.api.identitynow.com/oauth/token

Update the Body of this request to as shown below:


And add the below code to “Tests” section

pm.environment.set(
    "access_token", 
    pm.response.json().access_token
);

Step 4: Now update the “Authorization” tab of your collection as below

And “Auth” tab of each request as below to inherit Auth from parent (ie the collection the request is under)
image

Once this is set up, every time you need a new JWT token, you can send the request created in Step 3 and it will automatically store the access_token under environment variables and directly linked to your collection.

TIP: With this setup, you can create multiple environments for various tenants and easily switch between tenants from the selector on right top (“No Environment” under Step 1)

2 Likes

Thanks for sharing this! @iamnithesh

There’s also something very similar in the official collection offered, which you can find here:

Since it is maintained by SailPoint, all you need is to fork the collection and keep pulling updates as they come. The collection comes with its own pre-request script that helps you get an access token without having to grab it from the session every time. Plus, you don’t even have to worry about missing an API call and add to your collection manually, as every API would already be in your collection.

2 Likes

Just a suggestion here -
Instead of doing this in Postman and using bearer token, you could have just setup oauth2.0 authorization using PAT and just click “generate new access token”

1 Like