title: Is there a way to speed up/batch Google Calendar read/writes?
body: <p>I am new to Google Apps Script and learning javascript as I go about this project. Over the course of the introductory codelabs I noted the <a href="https://developers.google.com/apps-script/guides/support/best-practices" rel="nofollow noreferrer">best practice</a> to read all the data into an array with one command, perform operations, and then write it with one command.</p>
  <p>I understood how to do this working with Google Sheets but how do I achieve this working with Google Calendar? I have come across a few links discussing <a href="https://developers.google.com/calendar/batch" rel="nofollow noreferrer">batching with Google Calendar API</a> and <a href="https://developers.google.com/apps-script/advanced/calendar" rel="nofollow noreferrer">Advanced Google Services</a> but I didn't understand how to make use of the information.</p>
  <p>I basically hope to batch edit events instead of accessing Google Calendar repeatedly in a <code>for</code> loop.</p>
  <pre><code>function deleteMonth() {
  
    //  Set Date range to delete 
    var today = new Date();
    var firstDay = new Date(today.getFullYear(), today.getMonth(), 1);
    var lastDay = new Date(today.getFullYear(), today.getMonth() + 1, 0);
  
    //  read spreadsheet data and get User Info from ss
    var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
    var idSheet = spreadsheet.getSheetByName('User Info');
    //Get users from sheet in array of objects with properties from column header in 
    //'User Info' (name, email, year, calName, calID, early, late)
    var userInfo = getSheetData(idSheet);
    var deletedNames = &quot;&quot;;
    for (i = 0; i &lt; userInfo.length; i++) {
      var calID = userInfo[i].calID;
      //    if we have calID proceed to delete events
      if (calID) {
        console.time(&quot;get events&quot;);
        var calendar = CalendarApp.getCalendarById(calID);
        var events = calendar.getEvents(firstDay, lastDay);
        console.timeEnd(&quot;get events&quot;);
        //    Delete events and add deleted name to string 
        //    deletedNames     
        for (i = 0; i &lt; events.length; i++) {
          console.time(&quot;delete event&quot;);
          deletedNames += events[i].getTitle() + &quot;, &quot;;
          events[i].deleteEvent();
          console.timeEnd(&quot;delete event&quot;);
        }
      }
    }
    spreadsheet.toast(&quot;Deleted events: \n&quot; + deletedNames);
  }
  </code></pre>
  <p>Time output from <code>console.time()</code>:</p>
  <p><a href="https://i.stack.imgur.com/cRR1E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cRR1E.png" alt="Time output from console.time()" /></a></p>
  <p><strong>Other related links which sounded relevant:</strong></p>
  <ol>
  <li><a href="https://developers.google.com/apps-script/guides/services/advanced" rel="nofollow noreferrer">Using advanced google services</a> (apps script resource)</li>
  <li><a href="https://developers.googleblog.com/2018/03/discontinuing-support-for-json-rpc-and.html" rel="nofollow noreferrer">Google Developer blog?</a></li>
  </ol>