How to automatically set a Bearer Token for your Postman requests?

Hi @d.rajkhowa02, welcome to our community! :vulcan_salute:

I use this in my context, I put this piece of code on my collection Pre-Request Scritps.

pm.sendRequest({
    url: YourURL
    method: 'POST',
    header: {
        'content-type': 'application/json'
    },
    body: {
        mode: 'raw',
        raw: JSON.stringify({ YOUR PARAM TO CREATE THE TOKEN IF NEED IT })
    }
}, (err, res) => pm.collectionVariables.set("TOKEN", res.json().accessToken));

Then on collection Authorization I insert the variable TOKEN and change the Type to Bearer Token. That will help on your problem.

:vulcan_salute:

2 Likes