# Sample Post Execution script JavaScript Code to retrieve the 'Set-Cookie' header on Synthetic HTTP monitors.

**URL:** <https://community.dynatrace.com/t/sample-post-execution-script-javascript-code-to-retrieve-the-set-cookie-header-on-synthetic-http-monitors/39239>\
**Category:** Troubleshooting\
**Tags:** http-monitor, synthetic-monitoring\
**Created:** [April 11, 2023, 2:17pm UTC](https://community.dynatrace.com/t/sample-post-execution-script-javascript-code-to-retrieve-the-set-cookie-header-on-synthetic-http-monitors/39239 "2023-04-11T14:17:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mareeswaran](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@Mareeswaran](https://community.dynatrace.com/u/Mareeswaran)\
**Post date:** [April 11, 2023, 2:17pm UTC](https://community.dynatrace.com/t/sample-post-execution-script-javascript-code-to-retrieve-the-set-cookie-header-on-synthetic-http-monitors/39239/1 "2023-04-11T14:17:43Z")

</div>

You can use the below Sample Post Execution script JavaScript Code to retrieve the ‘Set-Cookie’ header on Synthetic HTTP monitors.

```javascript
var cookies = response.getHeaders().getAll('Set-Cookie');
var setcookie2 = cookies.get(1); //index-1
api.setValue("Set-Cookie", setcookie2);
var cookieslength = cookies.size();
api.info("cookies length " + cookieslength);
for(i=0;i<cookieslength;i++)
{
cookie = cookies.get(i);
api.info( i + ". cookie: " + cookie);
}

```

---

<div class="post-metadata">

**Author:** ![ChadTurner](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/chadturner/32/161_2.png) [@ChadTurner](https://community.dynatrace.com/u/ChadTurner)\
**Post date:** [May 12, 2023, 7:18pm UTC](https://community.dynatrace.com/t/sample-post-execution-script-javascript-code-to-retrieve-the-set-cookie-header-on-synthetic-http-monitors/39239/2 "2023-05-12T19:18:33Z")

</div>

Thank you&nbsp;[@Mareeswaran](https://community.dynatrace.com/user/40562)&nbsp;for sharing this!
