UrlFetchApp Invalid Argument Error

1,700 views
Skip to first unread message

Roy

unread,
Jan 20, 2017, 5:01:13 PM1/20/17
to AdWords Scripts Forum
I'm getting an invalid argument when I try to use UrlFetchApp in the following function:

function checkStock(url, adGroupName) {
  var htmlCode = UrlFetchApp.fetch(url).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;
}

It works for most links, but it's getting hung up on one. It has a pipe ("|") in it. Would that cause an error?

Could someone tell me why that is?


Joyce Lava (AdWords Scripts Team)

unread,
Jan 23, 2017, 12:50:06 AM1/23/17
to AdWords Scripts Forum
Hello Roy,

Special characters might be causing the issue, that said, could you please try the below script which uses the encodeUri for those failing urls:

function checkStock(url, adGroupName) {
 
var res = encodeURI(url);
 
var htmlCode = UrlFetchApp.fetch(res, {muteHttpExceptions: true, escaping: false}).getContentText();
 
//var htmlCode = UrlFetchApp.fetch(url).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;
}

Regards,
Joyce Lava
AdWords Scripts Team

Roy Harmon

unread,
Jan 23, 2017, 9:38:16 AM1/23/17
to AdWords Scripts Forum on behalf of Joyce Lava (AdWords Scripts Team)
That worked. Thanks!



--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to a topic in the Google Groups "AdWords Scripts Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-scripts/pIzEDFGBW7I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/9b728a52-2b0b-484e-aaa0-b9252cac0f6c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


ROY HARMON | CHUMNEY & ASSOCIATES
DIGITAL ADVERTISING SPECIALIST
1200 WOODRUFF RD, SUITE A-8, GREENVILLE, SC 29607 
OFFICE: (864) 297-7022 x427 | FAX: (864) 297-7024
Reply all
Reply to author
Forward
0 new messages