# Unable to capture the response and set it as variable

**URL:** <https://community.postman.com/t/unable-to-capture-the-response-and-set-it-as-variable/23145>\
**Category:** Help Hub\
**Tags:** variables, collections\
**Created:** [April 27, 2021, 10:30am UTC](https://community.postman.com/t/unable-to-capture-the-response-and-set-it-as-variable/23145 "2021-04-27T10:30:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![suriyaprakashs](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@suriyaprakashs](https://community.postman.com/u/suriyaprakashs)\
**Post date:** [April 27, 2021, 10:30am UTC](https://community.postman.com/t/unable-to-capture-the-response-and-set-it-as-variable/23145/1 "2021-04-27T10:30:00Z")

</div>

Hello All,

Greetings!!.

I am trying to correlate the response of a GET request & set it as an environment variable. Unfortunately I am not able to capture the response & getting “There was an error in evaluating the test script: JSONError: Unexpected token ‘e’ at 1:1” error.

Please find more details below.

GET method  
Content-Type:application/json

ref screenshots:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/e/9/e9997a605075ffd3501d9a8d4349a0ab11c0f0a5.png)  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/6/f/6f83f87e115424a795b545b0c69cf0ec159b55ed.png)

I had tried the below snippets.  
1)  
var jsonData = JSON.parse(responseBody);  
pm.environment.set(“auth\_token”, jsonData.json().val);  
console.log(“auth\_token created”);

1. 

var auth\_token= JSON.parse(responseBody);  
pm.environment.set(“auth”,auth\_token);

1. 

var jsonData = JSON.parse(responseBody);  
pm.environment.set(“auth\_token”, jsonData.responseBody);.

Any suggestions would be helpful.

Thanks in Advance.

---

<div class="post-metadata">

**Author:** ![neilstudd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/neilstudd/32/8213_2.png) [@neilstudd](https://community.postman.com/u/neilstudd)\
**Post date:** [April 27, 2021, 11:49am UTC](https://community.postman.com/t/unable-to-capture-the-response-and-set-it-as-variable/23145/2 "2021-04-27T11:49:09Z")

</div>

Hi there,

The reason that this is erroring is because you are trying to read the response using `JSON.parse` but the response is not in JSON format. (It complains about the token ‘e’, because this is the first character in the response, when it was expecting to find a `{` to indicate the start of some JSON.)

If you want to capture the entire response body as your auth token, you should be able to achieve it like this:

`pm.environment.set("auth_token", pm.response.text())`

---

<div class="post-metadata">

**Author:** ![suriyaprakashs](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@suriyaprakashs](https://community.postman.com/u/suriyaprakashs)\
**Post date:** [April 27, 2021, 11:54am UTC](https://community.postman.com/t/unable-to-capture-the-response-and-set-it-as-variable/23145/3 "2021-04-27T11:54:31Z")

</div>

> [@suriyaprakashs](#):
>
> console.log(“auth\_token created”);

@neilstudd Thanks for the reply, It worked.
