Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # How to automatically set a Bearer Token for your Postman requests
- ### 1. Create `access_token` variables
- i. Click `Manage Environments` on the right side of postman application.
- ii. Add new environment and insert `access_token` keyword under `VARIABLE` field only.
- ### 2. Create Authentication API
- i. Insert `your oauth url` with `POST` method.
- ii. Click Headers tab and set the key parameter (depends on your):-
- ```
- Content-Type : application/x-www-form-urlencoded
- ```
- ```
- Authorization : Basic <<secret>>
- ```
- iii. Click Body tab and set the key parameter:-
- ```
- grant_type : password
- ```
- ```
- username : <<secret>>
- ```
- ```
- password : <<secret>>
- ```
- iv. Select the environment name that we create in `Step 1`.
- ### 3. Create Tests script
- i. Click `Tests` tab and put this code:-
- ```
- var data = pm.response.json();
- pm.environment.set("access_token", data.access_token);
- ```
- ### 4. Create a new API
- i. Select the environment name that we create in `Step 1`.
- ii. Insert the API URL and the method.
- iii. make sure the API already save in postman.
- iii. Click Headers tab and set the key parameter:-
- ```
- Authorization: Bearer {{access_token}} // Choose the variable name we create in Step 1
- ``` `
Add Comment
Please, Sign In to add comment