Please help, fetch data url is long time and time out

26 views
Skip to first unread message

Semut Merah

unread,
Jul 4, 2020, 11:13:11 PM7/4/20
to Google Apps Script Community
first I tried to retrieve data from GAS using a simple method, the results are time out.

myFunction () function {
var url = UrlFetchApp.fetch ("https://www.tokopedia.com/freeknight");
var content = url.getResponseCode ();
Logger.log (content);
}
then I try to add the GET method, the results remain the same.

myFunction () function {
var option = {
'method': 'GET'
}
var url = UrlFetchApp.fetch ("https://www.tokopedia.com/freeknight", option);
var content = url.getResponseCode ();
Logger.log (content);
}
out of curiosity, I tried using a POSTMAN and API TESTER with the same method the result of the response is 200, why is that?

Chris Tales

unread,
Jul 5, 2020, 5:49:28 AM7/5/20
to Google Apps Script Community
Well you're requesting a response code for the GET request with .getResponseCode(), so everything is working as expected with 200 code.
https://www.restapitutorial.com/httpstatuscodes.html

Use .getContentText() instead

Chris Tales

unread,
Jul 5, 2020, 10:15:20 AM7/5/20
to Google Apps Script Community
On top of that the website you mentioned https://www.tokopedia.com/freeknight doesn't seem to be RESTful - a web scraper might come in handy there
Reply all
Reply to author
Forward
0 new messages