Getting access tokens for multiple APIs w/o changing token URL?

Hi: I have a few collections. Each request in the folder uses ‘Inherit auth from parent’ to use the folder’s auth.

To get a new token, I right-click on the folder, click Edit, click Auth, and click Get New Access token, but here is the problem: Postman only seems to be able to save one Access Token URL (and set of access token params e.g. username), even though each folder pertains to a different API with different token URLs.

I have to manually change the Access token URL, and password each time I switch between APIs.

Is there a way to store a different access token URL per folder, or some other way of approaching this?

Thank you.

Hello @wells.oliver, Welcome to the community :wave:

Yes definitely there’s a way to do.

In your auth request, under test section

var resp = JSON.parse(responseBody);
postman.setEnvironmentVariable("accessToken", resp.access_token);

paste this snippet based on your token field name as in your response.

And in the subsequent requests pass this as a variable like below:

Hope this helps.

Welcome to the community, @wells.oliver !

You need to parameterize these values you’re using to do auth.

I’d recommend reading this blog post on how to automate Token Gen/Renewal.

To take that a step further, like in your use case, you will need to override the variables per folder. From within Postman, right click each folder and select Edit. Click on the Pre-request Scripts tab and add the following snippet - replacing the placeholder values with the specific url/password for the API.

pm.environment.set('Auth_Url', '<the auth url for this API>');
pm.environment.set('Basic_Auth', '<The login credentials for this API>');

This will automatically update the variables whenever requests in this folder runs. PLUS, if you add the script from the blog post, it will automatically generate and use an auth token :slight_smile: