53

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

Is this possible?

2
  • I'm not an expert, but that sounds like it would have massive security implications. Commented May 28, 2014 at 16:33
  • 2
    Yes, it should be possible, check out Google Apps Scripts, developers.google.com/apps-script Commented May 28, 2014 at 16:36

2 Answers 2

42

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

Sign up to request clarification or add additional context in comments.

2 Comments

Looks like function in your Sheet doesn't work anymore.
The script was added by someone else - it looks like Google now requires that permissions be granted but also the Facebook API he was using is now deprecated. I'll update the answer.
41

Yes, you can use IMPORTDATA. It's designed to work with CSV data but will load any URL you throw at it:

=IMPORTDATA("https://stackoverflow.com/q/23917189/209828")

New line characters start a new row in the spreadsheet and the values shown in the cells are referenceable. Put this formula in A1 of its own sheet and reference cells from different sheets.

Google Sheets showing example usage of IMPORTDATA function

1 Comment

Works great for simple GET request.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.