UrlFetchApp - trying to handle 'Cookie' in request

1,115 views
Skip to first unread message

Mateusz Krajewski

unread,
Aug 9, 2022, 4:43:02 AM8/9/22
to Google Apps Script Community
Hi everyone, 
like in the topic - I am trying to handle 'Cookie' in GET request using UrlFetchApp.fetch() but it doesn't work. 

When I tried to handle that 'Cookie'  in postman or cURL on my mac terminal it worked perfectly. What is more when I tried to make this request using some online online API testing tool, it also failed - the same case: blank response + error 400.

Everytime I try it with GAS I get blank response and without parameter {muteHttpExceptions: true} error 400...

This is how code looks like:

function getHistory() {

var url = 
'https://steamcommunity.com/market/pricehistory/?country=EN&currency=1&appid=730& market_hash_name=Stockholm%202021%20Finalists%20Autograph%20Capsule';

var opt =
{
headers: {
'Cookie':
'steamLoginSecure=76561199310953453%7C%7CACABCC40A4305172D2B1632FA6DD91941B32341F',
},
muteHttpExceptions: true,
credentials : 'include'
};

var request = UrlFetchApp.getRequest(url, opt);
var response = UrlFetchApp.fetch(url, opt);

Logger.log(request['headers']);
Logger.log(response.getAllHeaders());
Logger.log(response.getContentText())

}

These are the Logger.log() results:

Zrzut ekranu 2022-08-9 o 10.36.52.png

This is the 'Cookie' I need to handle in my request

Zrzut ekranu 2022-08-9 o 10.41.22.png

Am I missing something? I am totally stuck with it.
Thanks in advance!

Clark Lind

unread,
Aug 9, 2022, 7:38:00 AM8/9/22
to Google Apps Script Community
I haven't progressed to that level yet, but you may find something useful in this playlist. He does a lot of Javascript/Apps script videos.

Clark Lind

unread,
Aug 9, 2022, 7:41:49 AM8/9/22
to Google Apps Script Community
This guy is also one of my favorites... https://www.youtube.com/watch?v=j0PpT96EFeg

Clark Lind

unread,
Aug 9, 2022, 7:56:38 AM8/9/22
to Google Apps Script Community

Mateusz Krajewski

unread,
Aug 9, 2022, 8:06:16 AM8/9/22
to Google Apps Script Community
Thank you so much I really appreciate that! Let's dig in those videos. Hope will find answer there.
Reply all
Reply to author
Forward
0 new messages