How to clear cookie after an Request

I have a use case’s, where I need to clear cookies after some set of requests.
but when I ran suite, cookies of 1 request is getting stored and the same cookie is being passed automatically in request headers.
this is causing all requests failing.

I used below script to clear the cookie but the cookie is still being stored

const jar = pm.cookies.jar();
jar.getAll(pm.request.url, function (error, cookies) {
// error -
// cookies -

});

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

Can someone help here?

1 Like

Have you whitelisted the domain?

You wouldn’t be able to get programmatic access to the cookies without doing that first.

Domain whitelisting doesn’t seem to work in version Version 8.0.6 (8.0.6) on macOs Catalina for some reason -

I went to manage cookies → whitelist domain → added my domain
Cleared my cookies
Sent the same request, and ‘set-cookie’ requests are still captured
Is there a way to keep them clear after each request?

saved

Have similar issue with Cookies (KeyCloack) for 7 and 8 Postman. But in my case, there is httpOnly flag is set. And the question is: according to

HttpOnly : If present, the cookie will not be accessible to the client-side scripts run on the page (e.g. via document.cookie in JavaScript). The cookie will only be added to the cookie header in requests that are made. This field does not have an effect on Postman’s behavior.

it is not possible to change cookies, well - how can I set/unset/clear cookies with httpOnly flag? Could you suggest any idea @danny-dainton?
The url is in Whitelist domains.

1 Like

I have the same issue with the latest version of postman. I write a function clear cookies after test but it not work. This is my code

// clear cookies
async function clearCookies() {
    const jar = pm.cookies.jar();
    if (jar) jar.clear(pm.request.url, function (error) {
        // error - <Error>
        throw (error);
    });
}
1 Like