How does Postman generate the Cookie for the request to work?

This isn’t really an Elixir question, moreso a general Postman question.

I’m using Postman to HTTP GET this URL:

https://redsky.target.com/redsky_aggregations/v1/web/plp_search_v2?key=9f36aeafbe60771e321a7cc95a78140772ab3e96&category=0snqs&channel=WEB&count=24&default_purchasability_filter=true&faceted_value=55e6uZakkosZ5tdv0Z55dgnZnqueqc6d44fZ54jftZ4bmrplmkj9nZpyq1lZwlkrxZkpg5pZ4bmrpllkdobZ56ds9Zfmt6gZ4bmrpli4j3qZ57yv4Z55kh9Z4bmrplqkc0lZpu2iyZftml9&include_sponsored=true&new_search=false&offset=48&page=%2Fc%2F0snqs&platform=desktop&pricing_store_id=746&scheduled_delivery_store_id=746&sort_by=newest&store_ids=746%2C1075%2C3424%2C2843%2C2848&useragent=Mozilla%2F5.0+(Windows+NT+10.0%3B+Win64%3B+x64)+AppleWebKit%2F537.36+(KHTML%2C+like+Gecko)+Chrome%2F119.0.0.0+Safari%2F537.36&visitor_id=018C306A752F02019455A6119EB0FB86&zip=33196

The request works and it returns the JSON I’m expecting. When I use the “copy as curl” feature, the request works in my Terminal.

curl --location ‘https://redsky.target.com/redsky_aggregations/v1/web/plp_search_v2?key=9f36aeafbe60771e321a7cc95a78140772ab3e96&category=0snqs&channel=WEB&count=24&default_purchasability_filter=true&faceted_value=55e6uZakkosZ5tdv0Z55dgnZnqueqc6d44fZ54jftZ4bmrplmkj9nZpyq1lZwlkrxZkpg5pZ4bmrpllkdobZ56ds9Zfmt6gZ4bmrpli4j3qZ57yv4Z55kh9Z4bmrplqkc0lZpu2iyZftml9&include_sponsored=true&new_search=false&offset=48&page=%2Fc%2F0snqs&platform=desktop&pricing_store_id=746&scheduled_delivery_store_id=746&sort_by=newest&store_ids=746%2C1075%2C3424%2C2843%2C2848&useragent=Mozilla%2F5.0%2B(Windows%2BNT%2B10.0%3B%2BWin64%3B%2Bx64)%2BAppleWebKit%2F537.36%2B(KHTML%2C%2Blike%2BGecko)%2BChrome%2F119.0.0.0%2BSafari%2F537.36&visitor_id=018C306A752F02019455A6119EB0FB86&zip=33196
–header ‘Cookie: mitata=ZDY4NmU2NDA3NjFlNGE2YjQ0YjAxY2NkMzY1OTU3MmRiNDFiOTAyY2UzOTRmMmQ3NTBlZDZlNDE3M2IxZTY2ZA== /@#/1701625898_/@#/cttujxbBJYtyKSbd_/@#/NGZhODVhZmNjY2UyZmJhOWE3MTk1MzQ0NWI5NmQwNDk4YTBhZTY2MWI0YjI1ZjQ5YzFhNmEwMjVhOWZmYzNlOA==_/@#/000’

After a few minutes the CURL request breaks, and I have to use Postman to make the GET request again because I noticed that the Cookie value is being changed automatically by Postman.

My question is how is Postman automatically refreshing this cookie value and how can I do this myself in Elixir code?

Is it doing some kind of preflight hit to the URL?

Progress!

By doing curl -c mycookies.txt yada yada I’m able to save the cookie value and then use it to make the original request work.

Now to automate this…

Have you checked the Set-Cookie header in the response? This is the mechanism used to store cookies in the browser.

1 Like

Turns out Req does this automatically for me, so I was worrying ahead of time over this for nothing. :laughing:

Thanks @wojtekmach !