In postman, I have a pre-request scenario where I have to take a cookie value and store it in the environment variable, say csrf in my case, and use it for the API request. As shown in the image, I have 2 cookies for the domain namely XSRF-TOKEN and _d. I have to take only the XSRF-TOKEN for the particular domain and store it in csrf variable. I have to exclude Path, Domain and the Secure fields
My pre-request script:
pm.environment.set("csrf", pm.cookies.get('XSRF-TOKEN'))

With this, the environment variable csrf is stored as null, and I don't understand where I have gone wrong. Any help is appreciated.
const jar = pm.cookies.jar()
jar.get('example.com', 'cookieName', (err, cookie) => {
console.log(cookie)
})
See: https://learning.postman.com/docs/postman/sending-api-requests/cookies/#get-a-cookie
You'll also need to whitelist the domain you're trying to get the cookie from: https://learning.postman.com/docs/postman/sending-api-requests/cookies/#whitelisting-domains-for-programmatic-access-of-cookies
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With