Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting cookies in postman programmatically

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.

like image 636
Ben Avatar asked Jul 24 '17 18:07

Ben


1 Answers

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

like image 105
tobias Avatar answered Oct 20 '22 03:10

tobias