UrlFetchApp Unexpected Error

109 views
Skip to first unread message

Roy

unread,
Mar 23, 2017, 5:10:52 PM3/23/17
to AdWords Scripts Forum
This function:

function checkStock(url, adGroupName) {
  var res = encodeURI(url);
  var htmlCode = UrlFetchApp.fetch(res, {
    muteHttpExceptions: true,
    escaping: false
  }).getContentText();
  var i = 0;
  for (var x in OUT_OF_STOCK_TEXTS) {
    if (htmlCode.indexOf(OUT_OF_STOCK_TEXTS[x]) !== -1) {
      i = i + 1
    }
  }
  if (i !== 0) {
    Logger.log("The " + adGroupName + " isn't in stock yet.");
  }
  return i;
}

is giving me this error:

Unexpected error: http://www.[DOMAIN-NAME].com/new-cars/2017/nissan/frontier/sort-price-asc/?_vsrefdom=semnissan (line 343)

Line 343 is the first line below:

  var htmlCode = UrlFetchApp.fetch(res, {
    muteHttpExceptions: true,
    escaping: false
  }).getContentText();


Do you know what I'm doing wrong?

Vincent Racaza (AdWords Scripts Team)

unread,
Mar 23, 2017, 11:29:32 PM3/23/17
to AdWords Scripts Forum
Hi Roy,

Based on the error itself, the url you are passing in the UrlFetchApp.fetch() contains '[DOMAIN-NAME]' which is not the actual value of the url's domain name. To check the actual url value you are passing, you may put a logger before UrlFetchApp.fetch():
Logger.log('URL: ' + res);

With this, please correct the url value first. If the issue still persists after correcting it, please provide your CID and the name of the script (Reply privately to author) so I could further investigate.

Thanks,
Vincent Racaza
AdWords Scripts Team
Reply all
Reply to author
Forward
0 new messages