Passing cookies/headers between requests

What’s the best way to extract unknown cookies form response and pass them on to the next request?
I can do it easily when I know the names of cookies, but I need to be able to do it for dynamically generated cookie names.
For example, response will have:
set-cookie:d9847d_Cluster1=C1894.d9847

I can see it in Postman’s cookies and in responseCookies array:
Array:[]

  • 0:{}
    • name:“d9847d_Cluster1”
    • value:“C1894.d9847”

Then next request should have header d9847d_Cluster1=C1894.d9847

UPDATE: as it turns out, Postman does it automatically, so I am fine. However, I would still like to know how to do it manually.

Did you ever get a response for this? I’m trying to pass a cookie using CURL in PHP, but no luck, even when I send this:

curl_setopt($ch, CURLOPT_COOKIE, $cookie);

Hey @rgasioro. Sorry for the delay in response, answering here in case someone stumbles upon it in the future.

The sandbox actually exposes a pm.cookies.toObject() function. From the docs:

Get a copy of all cookies and their values in the form of an object. The cookies returned are the ones defined for the requested domain and path.

So you’d get all the cookies as an object in this format:

{
  cookieName: 'cookieValue'
}

Once you get this, you can iterate over the object keys and manipulate them as per your needs to be used in subsequent requests.

Hope this helps, feel free to reach out in case you have additional querries.

1 Like

Good to know, thanks!