Address Unavailable UrlFetchApp

3,453 views
Skip to first unread message

Bharat Tarachandani

unread,
May 25, 2016, 10:37:57 PM5/25/16
to AdWords Scripts Forum
Hi there,

Trying to build a script to review landing pages.

UrlFetchApp keeps giving this exception even while using 'muteHttpExceptions: true' condition.

Error Message Address unavailable: http://subdomain.domain.<?> (line 49)

One of the URL does have a problem but that shouldn't prevent the script from moving forward.

Any help would be greatly appreciated.

Many Thanks,

Bharat




Here is the script ( some parts stripped off )

  var SPREADSHEET = "GoogleSheetURL";

function main() {
  var youremail = "email"
  var html = []   
    html.push("<html>",
                "<head>");
    html.push('</head>');
    html.push('<body bgcolor="white">');
    html.push('<table style="width=1000px; border: .5px solid #808080; border-collapse: collapse;border-spacing: 0;width: 100%;height: 100%;margin: 0px;padding: .5px;">');
    html.push("<tbody>");
    html.push('<tr style="background-color:#458B00;color:white;border: .5px dotted #ffffff; border-width: 0px 1px 1px 0px;text-align: left;padding: 10px;font-size: 12px;font-family: Arial Black;font-weight: normal">');
    html.push('<td style="width: 250px;  ">Landing Page</td>');
    html.push('<td style="width: 150px; ">Status</td>');
    html.push('</tr>');  
  
  var spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET);
  // Logger.log(spreadsheet.getName());
   var rawData = spreadsheet.getDataRange().getValues();  
   
 // Logger.log(rawData.length)
 
 //Logger.log(rawData)
  var data = [];  
  for (var i = 0; i < rawData.length; i++) {
//    for (var i = 0; i < 451; i++) {
    data.push({
      landingpage: rawData[i][0],
//      accountbudget: rawData[i][1],
    });
    var url = rawData[i][0]
    Logger.log('url ' + url)
    var queryend = url.indexOf("?");
    var querystart = url.indexOf(":");
    var querystart1 = (querystart+3);
    var HTTP_OPTIONS = {muteHttpExceptions: true, followRedirects: false}
    if (queryend == -1) {
     var landingpage = url }
    else {
    var landingpage = url.slice(querystart1,queryend)
//    Logger.log('querystart' + querystart);
//      Logger.log('querystart1' + querystart1);
    Logger.log('landing page' + landingpage);
    }
    if (landingpage != null) {
    
// Logger.log('landingpage ' + landingpage)
      // response = UrlFetchApp.fetch(landingpage, {followRedirects: false, muteHttpExceptions: true}); 
      var response = UrlFetchApp.fetch(landingpage, HTTP_OPTIONS).getResponseCode(); 
// Logger.log(landingpage + '     Status: ' +response.getResponseCode());
 
      if (response != 200) {
      
   html.push('<tr style="background-color:#E5E4E2; vertical-align: middle;text-align: left;padding: 5px;font-size: 9px;font-family: Georgia;font-weight: normal;color: #000000">');
   html.push('<td style="width: 250px;  ">' + landingpage +' </td>');
   html.push('<td style="width: 150px;  ">' + response +' </td>');
   html.push('</tr>');
      }
    }
 }
  html.push("</tbody>");
  html.push("</table>");
  html.push("<br>");
  html.push("<br>");
  html.push("</body>",
              "</html>");
   MailApp.sendEmail({
        to: youremail,
        subject: 'Landing Page Audit',
        htmlBody: html.join("\n")
    });  
}

Jaren Callo (AdWords Scripts Team)

unread,
May 26, 2016, 11:12:38 AM5/26/16
to AdWords Scripts Forum
Hi Bharat,

This is working as designed. muteHttpExceptions: true will handle URL if the HTTPResponse code is error. But in this case, the URL provided has no response at all hence, the script can't handle the exception handling. What I can suggest is to have try-catch to handle such scenario and proceed with the rest.

Thanks,
Jaren P. Callo
AdWords Scripts Team
Reply all
Reply to author
Forward
0 new messages