# Chaining Requests with previous headers

**URL:** <https://community.postman.com/t/chaining-requests-with-previous-headers/18993>\
**Category:** Help Hub\
**Tags:** variables, collections, chain\
**Created:** [January 9, 2021, 2:12am UTC](https://community.postman.com/t/chaining-requests-with-previous-headers/18993 "2021-01-09T02:12:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sam.hai](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@sam.hai](https://community.postman.com/u/sam.hai)\
**Post date:** [January 9, 2021, 2:12am UTC](https://community.postman.com/t/chaining-requests-with-previous-headers/18993/1 "2021-01-09T02:12:54Z")

</div>

Hey everyone,

Day 2 using Postman and REST APIs in general. I’m trying to chain a few requests together that need to happen sequentially, and depends on outputs from other requests.

**Rubber Duck explanation:**

- Log in every hour
- Extract XSRF Token and set as an environment variable (this changes every login, and need to be inserted as a Header all subsequent requests)
- List projects
- List Machines
- Get status of all machines from all projects
- Trim/truncate outputs to only relevant data

The request URLs are simple and straightforward. What I’m having trouble doing is automatically inserting the Header. The issue is that the XSRF Token isn’t listed in the body of the Login output. It’s a Cookie, so I’m not sure what command I need to run to extract that, then insert it as a header in subsequent request. Is this the right way?

var jsonData = JSON.parse(responseBody)  
pm.setEnvironmentVariable(“XSRF”, pm.cookies(XSRF-TOKEN))

---

<div class="post-metadata">

**Author:** ![arlem](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/arlem/32/3078_2.png) [@arlem](https://community.postman.com/u/arlem)\
**Post date:** [January 12, 2021, 10:57am UTC](https://community.postman.com/t/chaining-requests-with-previous-headers/18993/2 "2021-01-12T10:57:43Z")

</div>

Hey @sam.hai and welcome to the Postman Community!

According to the learning center, you’d need to use `pm.cookies.get("cookieName")` (instead of `pm.cookies(cookieName)`)to get the value of the cookie.

> **[Postman JavaScript reference | Postman Learning Center](https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#scripting-with-request-cookies)**
>
> Postman JavaScript reference: documentation for Postman, the collaboration platform for API development. Create better APIs—faster.

Let us know if that helps!
