# Put Output key to environment variable

**URL:** <https://community.postman.com/t/put-output-key-to-environment-variable/8309>\
**Category:** Help Hub\
**Created:** [October 11, 2019, 7:34am UTC](https://community.postman.com/t/put-output-key-to-environment-variable/8309 "2019-10-11T07:34:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ger0001p](https://avatars.discourse-cdn.com/v4/letter/g/f14d63/32.png) [@ger0001p](https://community.postman.com/u/ger0001p)\
**Post date:** [October 11, 2019, 7:34am UTC](https://community.postman.com/t/put-output-key-to-environment-variable/8309/1 "2019-10-11T07:34:35Z")

</div>

Hi Postman Community,

I´ve got one question. My request gets following response in XML format.

"  
  
  
LUFRPT1yaDN6T09CZ0dXNlRzSkFZcFRORVI5VkwzOWs9VEp1bS9YWDR2Q05BYmVvcGRuUlJwa2xTd0x0QVFtOGRNRUNiTm1rSm15TWV2S3FPeFVJREZkU2t2cUgrS29xdw==  
  
  
"

How can I set the key to the environment variable “TOKEN”?

Thanks and best regards  
Philipp

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [October 11, 2019, 12:12pm UTC](https://community.postman.com/t/put-output-key-to-environment-variable/8309/2 "2019-10-11T12:12:29Z")

</div>

Hey @ger0001p,

Welcome and thank you for the question! 🏆

Are you able to post an image of the response body?

The syntax to set the variable value would be something like `pm.environment.set("TOKEN", pm.response.text())` but without seeing the full response and the way that it’s presented, it’s difficult to know for sure.

---

<div class="post-metadata">

**Author:** ![ger0001p](https://avatars.discourse-cdn.com/v4/letter/g/f14d63/32.png) [@ger0001p](https://community.postman.com/u/ger0001p)\
**Post date:** [October 11, 2019, 12:24pm UTC](https://community.postman.com/t/put-output-key-to-environment-variable/8309/3 "2019-10-11T12:24:58Z")

</div>

Hi @danny-dainton

thanks for your reply. Yes of course. Attached a screenshot of the response body.

Greetings  
Philipp

 ![Postman_Body](https://us1.discourse-cdn.com/getpostman/original/2X/b/b6c03993b3b68971bc877deda6a594226b4aaa1a.png)

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [October 11, 2019, 12:38pm UTC](https://community.postman.com/t/put-output-key-to-environment-variable/8309/4 "2019-10-11T12:38:50Z")

</div>

You could try something like this:

```
let res = xml2Json(pm.response.text());

pm.environment.set("TOKEN", _.get(res, 'response.result.key'))

```

I’m sure there are many different ways to get that value though. 🙂

---

<div class="post-metadata">

**Author:** ![ger0001p](https://avatars.discourse-cdn.com/v4/letter/g/f14d63/32.png) [@ger0001p](https://community.postman.com/u/ger0001p)\
**Post date:** [October 15, 2019, 6:54am UTC](https://community.postman.com/t/put-output-key-to-environment-variable/8309/5 "2019-10-15T06:54:29Z")

</div>

> [@danny-dainton](#):
>
> let res = xml2Json(pm.response.text()); pm.environment.set(“TOKEN”, \_.get(res, ‘response.result.key’))

Perfect. Works just fine. Thank you Dannydainton 🙂
