K6 setup function issue

Hi, i am stuck in a problem, so basically i am trying to execute an end to end scenario. In which i login in to a website and when i login a redirect url sets a cookie using which i can perform various operations in the app. I am able to do all this.
The issue comes when i move the login api calls function to the setup () function and i return the cookie from it and try to use it in default function. The cookie is successfully passed to the default function but it does not work and gives error 400 bad request.
Dont know what exactly is causing this as same scenario executed all in one default function works fine but with addition of setup function it fails.
Any suggestions or possible solution would be great
Thanks

The cookie is successfully passed to the default function but it does not work and gives error 400 bad request.

How do you pass this? Can you share some of the code, or a reproducible example with something like https://httpbin.test.k6.io/?

I am asking because setup() is executed in its own transient VU, it doesn’t share any state with the rest of the VUs. The only the data you return from setup() will be accessible as the first parameter of the regular test iteration functions.

Specifically, every VU has its own global HTTP cookie jar. And, if you implicitly relied on the cookie being saved there, moving your login logic from the iteration function to setup() will break it. You’d need to manually set that cookie in the VU cookie jars again, or manually pass it in every request as part of the request params.

Thanks for that info. Problem was at my end i guess. I was trying to pass the cookie the headers request and which was not working correctly. I passed the cookie as ,{cookies : mycookie} in the http request and it worked.