How to pass token to subsequent APIs are token generated for user session

Hi,

Here is my scenario.

Auth type - OAuth2.0.

At collection level, When I click on Get New access token, I will get login page of my web application. After I enter user name and password, I will get the token.

Help required:

How will copy the token and pass it to subsequent request.

Please help me.

Hi!
Once the token is generated you click on ‘Use Token’ button and it will be available in the Current token section of the Authorization tab.

Each request in the collection has by default the auth type set to ‘Inherit auth from parent’. While this is selected all requests within the collection will use the token generated on the collection level.

Hi ,

Thank you for the response…

I wanted to know how to achieve this through API Automation.

Can you please help?

Hi @descent-module-tech8,

What do you mean by API automation?

If you are referring to using Postman CLI, this feature is not currently supported.

You have to add a pre-request script at the collection level to get the token (pm.sendRequest())
and store it as a variable for use on all your requests.

Cheers
Paul.

You can only use the Postman sendRequest() function with OAuth grant types that do not require browser interaction.

If the OAuth grant type requires browser interaction, then you can’t fully automate the workflow using sendRequest().

You cannot fully automate these work flows. I would recommend changing the authentication to something that can be automated.

The general premise here is that you are not testing the authentication but the API you hit after this. You can have a bunch of manual tests that test the authentication separately.