How to set Authentication for all the APIs in my collection

I want to set the authentication only for once and it should be used for all of my APIs that are there in my collection.

Hi @pranavNathcorp,

Please explain what kind of authentication method your API is using. Kindly through the below link and try to provide as much as details you could, so that we can help you the right way.

@bpricilla
If I run the APIs individually its working fine and sending the response 200 OK, but when I run the same APIs in runner it says 401 Error.

@bpricilla,
I am using OAuth 2.0

@pranavNathcorp

Please try to save the token as a variable, like

postman.setEnvironmentVariable("accessToken", "token_value"); 

under pre-request script and try using the variable in your subsequent requests.

Hope this solves the issue.

@bpricilla,
No, it didn’t worked. :pensive:

@pranavNathcorp Can you please share more details/screenshot? So is the variable getting stored with the expected token value?

@bpricilla
Scenario 1: When running the API alone

Scenario 2: When running the API in runner

@pranavNathcorp:

Are you placing the token value manually? Or you are passing as variable and refreshing it every run?

@bpricilla


Selected the collection → Edit → and then entered the authToken

@pranavNathcorp Can you please try storing in a variable as I mentioned above and to access in further requests?

Hey @pranavNathcorp,

It looks like you have the wrong Authorization type selected in your collection settings. You should select Oauth 2.0 instead of Bearer Token.

I’m making an assumption that you automatically want to renew the token when it expires? If so, you can refer to the following post on how we generally set that up within Postman.

@allenheltondev,
I don’t want to automatic token ,
the problem is like when I run the API alone it shows 200 OK, but when I run it in runner it shows 401 Error and in the Authorization part null value is passed.

image

In the Authorization tab of the request you’re sending, is the selected option ‘Inherit from parent’?

Might be use this one request ?

https://www.postman.com/api-evangelist/workspace/collections/request/35240-15f03e39-97db-48b2-a536-6f87e3955ec3