Chaining Requests with previous headers

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))

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.

Let us know if that helps!