# Automatic token capture

**URL:** <https://community.postman.com/t/automatic-token-capture/37963>\
**Category:** Help Hub\
**Created:** [August 7, 2022, 4:28am UTC](https://community.postman.com/t/automatic-token-capture/37963 "2022-08-07T04:28:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![navigation-astrono10](https://avatars.discourse-cdn.com/v4/letter/n/898d66/32.png) [@navigation-astrono10](https://community.postman.com/u/navigation-astrono10)\
**Post date:** [August 7, 2022, 4:28am UTC](https://community.postman.com/t/automatic-token-capture/37963/1 "2022-08-07T04:28:44Z")

</div>

Can anyone help me understand why my pre-request script is not defining the variable with the called token?

```auto
const echoPostRequest = {
  url: 'https://www.amilia.com/api/v3/authenticate/',
  method: 'get',
  header: `Authorization: Basic [base64]
};

pm.sendRequest(echoPostRequest, function (err, res) {
    const json = res.json()  
    pm.environment.set("token", json.token) 

```

I can see the correct token in the body being called when viewing the console. However, it is not adding the token to the variable in the authentication tab. Any help would be amazing. Thanks!
