Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

Is this possible?

like image 783
Muhammad Hewedy Avatar asked May 28 '14 16:05

Muhammad Hewedy


People also ask

Can you embed code in Google Docs?

With the document open, click Add-ons and select Code Blocks from the menu. A new right sidebar will open (Figure A), where you can make use of the tool. Code Blocks is installed and ready to go. To use Code Blocks, write or paste your code in the document.

Can you call a REST API from Google Sheets?

Calling a REST API in Google Sheets is as easy as installing the Apipheny app, then opening the app in your Google Sheet, entering your API request, and clicking “Run”. Keep reading for instructions on how to import REST API data into Google Sheets.


2 Answers

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

like image 147
pherris Avatar answered Sep 25 '22 06:09

pherris


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

like image 28
Matthew Avatar answered Sep 25 '22 06:09

Matthew