Set a cookie for a test

I want to set a cookie for a test, which I try to do via a pre-request script.
I have set an environment variable for the value I want to set (on multiple tests) and have this pre-request script:

const cookieJar = pm.cookies.jar();
authcookie = pm.environment.get(“auth-cookie”);
cookieJar.clear(‘’, function (error) { console.log(error); });
{ “name”: “PHPSESSID”, “value”: authcookie, “httpOnly”: false },
function (error, cookie) { console.log(error); });

When I run the script, I get this error which I have no idea how to solve:

Object {message: “CookieStore: programmatic access to “” is denied”, name: “Error”, type: “Error”}

  1. message: “CookieStore: programmatic access to “” is denied”
  2. name: “Error”
  3. type: “Error”

Any idea how to solve that?

Update: I am trying this in the Postman app on mac.


Did you ever find a solution to your question?

No, not really. I implemented a workaround where postman now has a workaround to authenticate itself so the session cookie can get setup using the regular way.


I solved this by following these instructions (" Whitelisting domains for programmatic access of cookies"):

Note: the ‘Whitelist Domains’ button might not be visible, I had to close a message about an Interceptor Lesson in the ‘Manage Cookies’ popup to see it.

After whitelisting your domain you’ll be able to manage the cookies.