Skip to content

Instantly share code, notes, and snippets.

@mhawksey
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mhawksey/cd972b6e4e00d3fc3423 to your computer and use it in GitHub Desktop.
Save mhawksey/cd972b6e4e00d3fc3423 to your computer and use it in GitHub Desktop.
import.io with Google Apps Script example (sending data as email)
function getImportio() {
var url = "YOUR_IMPORTHTML_URL";
/*
* Class UrlFetchApp
*
* Fetch resources and communicate with other hosts over the Internet. This service allows
* scripts to communicate with other applications or access other resources on the web by
* fetching URLs. A script can use the URL Fetch service to issue HTTP and HTTPS requests
* and receive responses. The URL Fetch service uses Google's network infrastructure for
* efficiency and scaling purposes.
*
* https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app
*
* UrlFetchApp.fetch(url)
*
* @param {string} url String the URL to fetch
* @return {object} HTTPResponse — the HTTP response data
*/
var resp = UrlFetchApp.fetch(url); // fetches the http response from the import.io API
// the response object includes headers, response code and content we are getting the
// content which in this case is a html table
var table = resp.getContentText();
/*
* Class MailApp
*
* Sends email.
* This service allows users to send emails with complete control over the content of the
* email. Unlike GmailApp, MailApp's sole purpose is sending email. MailApp cannot access
* a user's Gmail inbox.
*
* https://developers.google.com/apps-script/reference/mail/mail-app
*
* MailApp.sendEmail(recipient, subject, body, options)
*
* @param {string} recipient String the addresses of the recipients, separated by commas
* @param {string} subject String the subject line
* @param {string} body String the body of the email
* @param {onject} options Object a JavaScript object that specifies advanced parameters,
* - in this example we are including htmlBody String if set, devices capable of rendering
* - HTML will use it instead of the required body argument; you can add an optional inlineImages
* - field in HTML body if you have inlined images for your email
*
*/
MailApp.sendEmail("recipient_addresss@example.com", "Latest from import.io", "", {htmlBody:table});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment