Skip to content

Instantly share code, notes, and snippets.

@markcam1
Created February 28, 2019 19:57
Show Gist options
  • Save markcam1/8f183af48d3d1f0db7d4fb9d5245df6c to your computer and use it in GitHub Desktop.
Save markcam1/8f183af48d3d1f0db7d4fb9d5245df6c to your computer and use it in GitHub Desktop.
Google App Scripts | Sheets Tutorial | aerobatic auth
/*
Google App Scripts - Sheets Tutorial
Author: Mark Cameron
*/
function showMessageBox() {
Browser.msgBox('You touched me!');
getWebsite();
}
function getWebsite() {
var attValue = '';
//in order to login to a website we need to pass our credentials in the Options object
var options = {};
options.headers = { "Authorization": "Basic " + Utilities.base64Encode("aerobatic" + ":" + "aerobatic") };
//making a call to the target website using the jira rest api endpoint for projects
//https://developer.atlassian.com/server/jira/platform/rest-apis/
var response = UrlFetchApp.fetch("https://auth-demo.aerobaticapp.com/protected-custom/", options);
//logging response from target website - In Script Editor > View > Logs
Logger.log(response.getContentText());
//parsing the response data from website
//https://developers.google.com/apps-script/reference/url-fetch/http-response
var rawData = response.getContentText();
//setting the spreadsheet and cell location to place the website data
//make sure to open a new sheet
//Link: https://developers.google.com/apps-script/reference/spreadsheet/sheet#getrangerow-column
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.setActiveSheet(spreadsheet.getSheets()[1]);
var cell = sheet.getRange(1, 1);
cell.setValue(rawData);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment