# Unable to copy response header to an environment var

**URL:** <https://community.postman.com/t/unable-to-copy-response-header-to-an-environment-var/58887>\
**Category:** Help Hub\
**Tags:** tests, variables, scripts\
**Created:** [March 15, 2024, 3:44pm UTC](https://community.postman.com/t/unable-to-copy-response-header-to-an-environment-var/58887 "2024-03-15T15:44:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben\_Plunkett](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@Ben\_Plunkett](https://community.postman.com/u/Ben_Plunkett)\
**Post date:** [March 15, 2024, 3:44pm UTC](https://community.postman.com/t/unable-to-copy-response-header-to-an-environment-var/58887/1 "2024-03-15T15:44:08Z")

</div>

Hello,

I am trying to chain some requests together by copying some data from an API call into the environment variables, using tests

I have written the following test. The first retrives a value from the JSON response body. this is working as expected.

The response header value however does not work.

This is the test I have written and below is a screenshot showing the test, the response header and the variables logged in the console

```auto
var jsonData = JSON.parse(responseBody);
pm.environment.set("form_instance_id", jsonData.id);
var resHeaders = pm.response.headers.get('Etag');
pm.environment.set("eTag", resHeaders.Etag);

```

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

Thanks in advance for your assistance.

Ben

---

<div class="post-metadata">

**Author:** ![Ben\_Plunkett](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@Ben\_Plunkett](https://community.postman.com/u/Ben_Plunkett)\
**Post date:** [March 15, 2024, 3:46pm UTC](https://community.postman.com/t/unable-to-copy-response-header-to-an-environment-var/58887/2 "2024-03-15T15:46:41Z")

</div>

So as soon as I posted this, I tweaked the test and it worked 🤦‍♂️

I removed the .Etag from the “pm.environment.set(“eTag”, resHeaders.Etag);”

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/b/1/b103f2a5a69ea4a3bfee6a7a641327ca4aa99047.png)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [March 18, 2024, 3:47pm UTC](https://community.postman.com/t/unable-to-copy-response-header-to-an-environment-var/58887/3 "2024-03-18T15:47:01Z")

</div>

Closed on March 18, 2024, 3:47pm UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
