Some notes when working with Google Apps Script



Here are some notes I took when working with Google Apps Script:

1. Global variables:


  • Can't change global variables's values.
  • If you want to change them, use scriptdb (removed on November 20, 2014), google spreadsheets (data < 10000 rows), or Google Cloud SQL (data > 10000 rows) instead.


2. Call external REST API(s)

To debug your script when calling an external REST API using UrlFetchApp.fetch, you can use this parameter of the options:

'muteHttpExceptions': true,

For example:

  var url = 'http://myapi.com';
  var options = {
    'method': 'POST',
    'headers': headers,
    'payload': 'This is the payload',
    'contentType': 'application/json',
    'muteHttpExceptions': true // use for debugging
  };
  var response = UrlFetchApp.fetch(api_url, options);


3. For loops:
For loops in Google Script looks a lot like python except for..., example:

for(item in mycollections) {...}

item here is the index of the item not the item of mycollections


(to be continued...)






Comments