title: Creating Multiple Google Sheets PDFs throws 429 error
body: <p>I'm stuck.  I'm hoping someone out there has figured out a way to generate a bunch of <strong>PDF's</strong> off of <strong>Google Sheets</strong>.  </p>
  
  <p>I run the same report for a list of companies and generate PDF snapshots of each report which are saved in Drive.  I get a <em>429 error</em> every time with the only difference being how many <strong>PDFs</strong> I generate before getting the error. </p>
  
  <p>The number of PDFs generated is directly correlated to how long I put in the <code>Utilities.sleep</code> function but still only a fraction of the total number of reports (i.e more sleep = slightly more <strong>PDFs</strong> generated before error).  </p>
  
  <p>I've made several attempts at using exponential backoff, but my attempts have been futile.</p>
  
  <p>Any insights on how to avoid the following 429 are appreciated:</p>
  
  <p><code>Request failed for docs.google.com/a/[redacted]/spreadsheets/d/[redacted]/… returned code 429. Truncated server response: &lt;!DOCTYPE html&gt;&lt;html lang="en"&gt;&lt;head&gt;&lt;meta name="description" content="Web word processing, presentations and spreadsheets"&gt;&lt;meta name="viewport" c... (use muteHttpExceptions option to examine full response</code></p>
  
  <p>Here's the relevant code:</p>
  
  <pre><code>var foldersave = DriveApp.createFolder('New Reports').getId()
  var request = {method:"GET",headers:{"authorization":"Bearer "+ ScriptApp.getOAuthToken(), muteHttpExceptions: true}};
  
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  var gid = sheet.getSheetId();
  
  var values = ss.getActiveSheet().getRange(2, 8, sheet.getLastRow()-1, 1).getValues();
  
  for (var i = 0; i &lt; values.length; i++) {
  
  //set up the new report
  var org = sheet.getRange(5,4);
  org.setValue(values[i])
  
  //set the PDF parameters
  var pdfOpts = '&amp;size=0&amp;fzr=false&amp;portrait=true&amp;fitw=true&amp;gridlines=false&amp;printtitle=false&amp;sheetnames=false&amp;pagenum=CENTER&amp;attachment=false&amp;gid='+gid;
  var printRange = '&amp;c1=0' + '&amp;r1=0' + '&amp;c2=4' + '&amp;r2=42'; 
  var url = ss.getUrl().replace(/edit$/, '') + 'export?format=pdf' + pdfOpts + printRange;
  
  //create the PDF
  var response = UrlFetchApp.fetch(url, request).getBlob().setName(values[i] + ".pdf"); 
  var dir = DriveApp.getFolderById(foldersave); 
  var file = dir.createFile(response);
  Utilities.sleep(5000);
  }
  </code></pre>