11

I'm using Newman and the native Windows Postman app to test a REST API. It stores the session cookie between requests, allowing me to access information that requires authorization without providing correct authorization. I would like to be able to delete the cookie within the pre-request script section. Is this possible? I know how to delete cookies using the GUI through reading questions such as How to delete session cookie in Postman? and the official postman documentation but that doesn't help me deal with this issue.

Ben
  • 111
  • 1
  • 5
  • 1
    I'm using a workaround where I set the cookie value into a global variable, and use the variable in the headers of the requests. I then clear them using `postman.setGlobalVariable(VAR_NAME)`, which removes it completely. – rj93 Jul 26 '17 at 10:10

2 Answers2

1

Postman v7.6.0 has added support for programmatic cookie access. Hence, if you want to delete a cookie in the pre-request script, you can do the following:

Remove a single cookie

const jar = pm.cookies.jar();

jar.unset(pm.request.url, 'cookie name', function (error) {
  // handle error
});

Remove all cookies

const jar = pm.cookies.jar();

jar.clear(pm.request.url, function (error) {
  // handle error
});

You can find a detailed overview of the API here: https://learning.getpostman.com/docs/postman/sending-api-requests/cookies/#programmatic-accees-of-cookies

tobias
  • 934
  • 8
  • 17
0

This is not currently possible with Postman, it's an open feature request at the moment:

https://github.com/postmanlabs/postman-app-support/issues/3312#issuecomment-413750185

so cal cheesehead
  • 2,515
  • 4
  • 29
  • 50