Is it possible to send HTTP request from inside Google docs?

Muhammad Hewedy picture Muhammad Hewedy · May 28, 2014 · Viewed 26.1k times · Source

I want to send an HTTP request to some REST service from Google drive spreadsheet.

Is this possible?

Answer

pherris picture pherris · May 28, 2014

Using Google Apps Script, you can make HTTP requests to external APIs from inside Google Docs/Sheets/etc. using the UrlFetchApp class:

var url = 'https://gdata.youtube.com/feeds/api/videos?'
    + 'q=skateboarding+dog'
    + '&start-index=21'
    + '&max-results=10'
    + '&v=2';
var response = UrlFetchApp.fetch(url);
Logger.log(response);

Note that:

This service requires the https://www.googleapis.com/auth/script.external_request scope. In most cases Apps Script automatically detects and includes the scopes a script needs, but if you are setting your scopes explicitly you must manually add this scope to use UrlFetchApp.

ref: https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app