2

I am trying to get the cookies in the pre request script to chain it with other request which returns as empty array using the example below.

With the latest release of postman v8, the cookies object cannot be fetched using the pm.sendRequest which would otherwise work in postman versions less than 8.

pm.sendRequest(url, function (err, response, { cookies }) {
    console.log(cookies.all());
});
girish
  • 305
  • 3
  • 16

1 Answers1

4

I think you might need something like this to see the cookies:

pm.sendRequest("https://postman-echo.com/get", function (err, response, options) {
    console.log(options.cookies.members);
});

From here you could loop through the members array to get what you need.

Danny Dainton
  • 23,069
  • 6
  • 67
  • 80
  • Thanks Danny for your answer. I am just deconstructing the cookies in my example while you are accessing it through options. Both of them will result in the same empty array. – girish Apr 09 '21 at 09:18
  • Did you try my example in a pre-request? I can see an array with a single cookie in it from that domain. – Danny Dainton Apr 09 '21 at 09:27
  • 1
    Yes I did just now and looks like it sets the cookie correctly. Thank you so much. I will check my example and debug it more. – girish Apr 09 '21 at 09:29