I was able to use these 2 lines in âTestâ tab:
var xsrfCookie = postman.getResponseCookie(âcsrftokenâ); postman.setEnvironmentVariable(âcsrftokenâ, xsrfCookie.value);
But after I relog, the code return âundefinedâ
That looks like the older sandbox syntax so we might need to change that but it also looks like the response doesnât have any cookies so it would be undefined.
You may need to expand on the implementation details a little bit to help people understand what youâre doing.
Iâm using postman to call a POST API in my backend source (Python using Django), since it requires csrftoken, I put this script in the âTestsâ tab and it worked. But after I re-log my postman, I got this error, right now I have to turn off the csrf check in the backend but this is not a good way to do it, Iâm not sure why this happen, is it because postman clear my cookie after I log out? if so, how can I get it generated?
So not really sure how youâre generating that cookie in your code, Postman wouldnât be creating that for you.
That image shows that for that particular request, there were no cookies in the response. Being that there are no cookies that script is failing before thereâs nothing defined at that reference.