# Postman Automatic Auth Token

> Postman can run JavaScript commands when executing a request. These commands can be placed in the "Tests" tab inside a request.

- URL: https://graffino.com/til/postman-automatic-auth-token
- Author: Mihai Barbu
- Channel: javascript
- Published: 2021-08-24
- Updated: 2026-02-04

Postman can run JavaScript commands when executing a request. These commands can be placed in the "Tests" tab inside a request.
For example, to automatically set a token as a collection variable, the following commands are used: 

```
var auth = pm.response.headers.get("Authorization");
pm.collectionVariables.set('token', auth.split(" ")[1]);
```

The Docs regarding Postman scripting can be found here:

https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/
