Hello, I’ve been struggling to get the csrftoken cookie. My use case is I’m trying to set the X-CRSFToken
header to the csrftoken
cookie value before sending the request. It’s just a regular cookie that is stored in the cookie manager. I have added my domain to the allowlist, tried using cookie jar, interceptor to no avail. Although, the cookie is marked as Secure so I’m not sure if the impacts the ability to get the cookie. Here’s what I’m trying.
In pre-request scripts:
var csrfToken = pm.cookies.get('csrftoken');
console.log(csrfToken);
// If the cookie exists, set the X-CSRFToken header
if (csrfToken) {
pm.request.headers.add({key: 'X-CSRFToken', value: csrftoken.value});
}
However, csrftoken is undefined in console.
Here’s proof that the cookie is indeed in the cookie manager:
Header:
Allowlist:
I have tried adding interceptor as well, but it didn’t change anything.
I must be missing something obvious. I simply just want to retrieve the csrftoken
cookie and set the X-CSRFToken
header to that value before sending the request.