# Set response as variable in tests

**URL:** <https://community.postman.com/t/set-response-as-variable-in-tests/7449>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [August 27, 2019, 9:39am UTC](https://community.postman.com/t/set-response-as-variable-in-tests/7449 "2019-08-27T09:39:59Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![singhsivcan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/singhsivcan/32/1595_2.png) [@singhsivcan](https://community.postman.com/u/singhsivcan)\
**Post date:** [August 27, 2019, 11:43am UTC](https://community.postman.com/t/set-response-as-variable-in-tests/7449/2 "2019-08-27T11:43:18Z")

</div>

Is your response a string?  
Exactly like the one that you shared?

If yes, you can write something like this:

```javascript
let s = pm.response.text(),
 id = s.slice(s.indexOf("Id: ") + 4);

pm.environment.set('id', id);

```

* * *

_Edit:_  
Updated the incorrect syntax.

Considering the response is received as shown in screenshot:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/0/c/0ce17d484c8fa980eedc24bf6ce258d61f984024.png)

---

_[View the full topic](https://community.postman.com/t/set-response-as-variable-in-tests/7449)._
