External APIs

  • Google Apps Script can interact with various web APIs using the UrlFetch service.

  • For APIs requiring user authorization via OAuth, open source libraries for OAuth1 and OAuth2 are available.

  • Working with JSON responses involves using getContentText() and JSON.parse(), while creating JSON payloads uses JSON.stringify().

  • Handling XML responses and requests uses getContentText() and the XmlService methods.

Google Apps Script can interact with APIs from all over the web. Use this guide to work with different types of APIs in your scripts.

Connect to public APIs

Use the UrlFetch service to make API requests directly.

The following example uses the GitHub API to search for repositories with 100 or more stars that mention "Apps Script". This API request does not require authorization or an API key.

var query = '"Apps Script" stars:">=100"';
var url = 'https://api.github.com/search/repositories'
  + '?sort=stars'
  + '&q=' + encodeURIComponent(query);

var response = UrlFetchApp.fetch