Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Google Sheets Scripts with the Meraki Dashboard API
// Settings - Modify this with your values
// *************************
// User Defined in the Script
var API_KEY = '';
var ORG_ID = '';
var NET_ID = '';
var TIMESPAN = '';
// User Defined in a Sheet
var SHEET_NAME = "settings"
var API_KEY_SHEET_CELL = "B3";
var API_KEY_SHEET_CELL_LABEL = "A3";
var ORG_ID_SHEET_CELL = "B4";
var ORG_ID_SHEET_CELL_LABEL = "A4";
var NET_ID_SHEET_CELL = "B5";
var NET_ID_SHEET_CELL_LABEL = "A5";
var TIMESPAN_SHEET_CELL = "B6";
var TIMESPAN_SHEET_CELL_LABEL = "A6";
// *************************
// Initialize Settings Sheet and Environment Variables
// find or create settings sheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
if (ss.getSheetByName(SHEET_NAME) == null){
ss.insertSheet(SHEET_NAME);
ss.getRange(API_KEY_SHEET_CELL_LABEL).setValue('API KEY:');
ss.getRange(ORG_ID_SHEET_CELL_LABEL).setValue('Org ID:');
ss.getRange(NET_ID_SHEET_CELL_LABEL).setValue('Net ID:');
ss.getRange(API_KEY_SHEET_CELL).setValue('YourAPIKey');
ss.getRange(ORG_ID_SHEET_CELL).setValue('YourOrgId');
ss.getRange(NET_ID_SHEET_CELL).setValue('YourNetId (optional)');
ss.getRange(TIMESPAN_SHEET_CELL_LABEL).setValue('Timespan:');
ss.getRange(TIMESPAN_SHEET_CELL).setValue(7200);
}
var settingsSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(SHEET_NAME);
// assign settings
var settings = {};
settings.apiKey = settingsSheet.getRange(API_KEY_SHEET_CELL).getValue() || API_KEY;
settings.orgId = settingsSheet.getRange(ORG_ID_SHEET_CELL).getValue() || ORG_ID;
settings.netId = settingsSheet.getRange(NET_ID_SHEET_CELL).getValue() || NET_ID;
settings.timespan = settingsSheet.getRange(TIMESPAN_SHEET_CELL).getValue() || TIMESPAN;
function setApiKey(apiKey){
settings.apiKey = apiKey;
settingsSheet.getRange(API_KEY_SHEET_CELL).setValue(apiKey)
}
function setOrgId(orgId){
settings.orgId = orgId;
settingsSheet.getRange(ORG_ID_SHEET_CELL).setValue(orgId)
}
function setNetId(netId){
settings.netId = netId;
settingsSheet.getRange(NET_ID_SHEET_CELL).setValue(netId)
}
function setTimespan(timespan){
settings.timespan = timespan;
settingsSheet.getRange(TIMESPAN_SHEET_CELL).setValue(timespan)
}
// Toolbar Menu Items
function onOpen() {
loadMenu();
}
//var orgFunctions = {};
function loadMenu() {
// Main Menu
var ui = SpreadsheetApp.getUi();
var mainMenu = ui.createMenu('Meraki-Reports');
// Reports
mainMenu.addItem('Organizations','callOrgs')
mainMenu.addItem('Networks','callNetworks')
mainMenu.addSubMenu(SpreadsheetApp.getUi().createMenu('Org-Wide')
.addItem('Admins','callAdmins')
.addItem('Clients','callClientsOfOrg')
.addItem('Clients Details','callClientsOfOrgDetails')
.addItem('Configuration Templates','callConfigTemplates')
.addItem('Devices Details','callDevices')
.addItem('Device Loss and Latency History','callDeviceLossAndLatencyHistory')
.addItem('Devices Status','callDevicesStatuses')
.addItem('Devices Uplink Details','callUplinkInfos')
.addItem('License State','callLicenseState')
.addItem('License State all Orgs','callLicenseStateForOrgs')
.addItem('License State Details','callLicenseStateDetails')
.addItem('Organization Loss Latency','callOrganizationUplinksLossAndLatency')
.addItem('Group Policies','callGroupPoliciesOfOrg')
.addItem('Inventory','callInventory')
.addItem('Networks','callNetworks')
.addItem('Organizations','callOrgs')
.addItem('Organization','callOrg')
.addItem('SSIDs','callSsidsOfOrg')
.addItem('StaticRoutes','callStaticRoutes')
.addItem('Wireless Health Connection Stats','callConnectionStatsOfOrg')
.addItem('Wireless Health Latency Stats','callLatencyStatsOfOrg')
.addItem('Traffic Analysis','callTrafficOfOrg') // Testing
.addItem('VLANS','callVlansOfOrg')
.addItem('VPN','callSiteToSiteVpn'));
mainMenu.addSubMenu(SpreadsheetApp.getUi().createMenu('Network-Wide')
.addItem('Clients','callClientsOfNet')
.addItem('Clients Details','callClientsOfNetDetails')
.addItem('Wireless Health Failed Connections','callFailedConnections')
.addItem('Wireless Health Connection Stats by Device','callConnectionStatsByNode')
.addItem('Wireless Health Connection Stats by Client','callConnectionStatsByClient')
.addItem('Wireless Health Latency Stats by Device','callLatencyStatsByNode')
.addItem('Wireless Health Latency Stats by Client','callLatencyStatsByClient'));
mainMenu.addSubMenu(SpreadsheetApp.getUi().createMenu('Settings')
.addItem('Set API Key','promptApiKey')
.addItem('Set Org ID','promptOrg')
.addItem('Set Net ID','promptNet')
.addItem('Set Timespan','promptTimespan'));
mainMenu.addToUi() ;
}
/*
function selectOrg(id){
var ui = SpreadsheetApp.getUi();
settings.orgId = id;
ui.alert('Organization Set To: '+settings.orgId, ui.ButtonSet.YES_NO);
}
*/
function promptApiKey(){
var ui = SpreadsheetApp.getUi();
var response = ui.prompt('Meraki API Key', 'Required to run reports.', ui.ButtonSet.OK_CANCEL);
// Process the user's response.
if (response.getSelectedButton() == ui.Button.OK) {
// save key and refresh menu
setApiKey(response.getResponseText());
//ui.alert('API Key Set: '+settings.apiKey, ui.ButtonSet.YES_NO);
loadMenu();
} else if (response.getSelectedButton() == ui.Button.CANCEL) {
Logger.log('The user didn\'t want to provide an API key.');
} else {
Logger.log('The user clicked the close button in the dialog\'s title bar.');
}
}
function promptOrg(){
var ui = SpreadsheetApp.getUi();
var response = ui.prompt('Organization ID', 'Run the Organizations report to get this info.', ui.ButtonSet.OK_CANCEL);
// Process the user's response.
if (response.getSelectedButton() == ui.Button.OK) {
Logger.log('The user\'s Org Id is %s.', response.getResponseText());
// save key and refresh menu
setOrgId(response.getResponseText());
loadMenu();
} else if (response.getSelectedButton() == ui.Button.CANCEL) {
Logger.log('The user didn\'t want to provide an Org Id.');
} else {
Logger.log('The user clicked the close button in the dialog\'s title bar.');
}
}
function promptNet(){
var ui = SpreadsheetApp.getUi();
var response = ui.prompt('Network ID', 'Sets the network for "network-wide" reports. Run the org-wide "Networks" report to get this info.', ui.ButtonSet.OK_CANCEL);
// Process the user's response.
if (response.getSelectedButton() == ui.Button.OK) {
Logger.log('The user\'s Net Id is %s.', response.getResponseText());
// save key and refresh menu
setNetId(response.getResponseText());
loadMenu();
} else if (response.getSelectedButton() == ui.Button.CANCEL) {
Logger.log('The user didn\'t want to provide an Net Id.');
} else {
Logger.log('The user clicked the close button in the dialog\'s title bar.');
}
}
function promptTimespan(){
var ui = SpreadsheetApp.getUi();
var response = ui.prompt('Timespan', 'Used by some reports to get range of data', ui.ButtonSet.OK_CANCEL);
// Process the user's response.
if (response.getSelectedButton() == ui.Button.OK) {
Logger.log('The user\'s timespan is %s.', response.getResponseText());
// save key and refresh menu
setTimespan(response.getResponseText());
loadMenu();
} else if (response.getSelectedButton() == ui.Button.CANCEL) {
Logger.log('The user didn\'t want to provide a timespan');
} else {
Logger.log('The user clicked the close button in the dialog\'s title bar.');
}
}
function isObject(obj) {
return obj === Object(obj);
}
function toActiveCellOverwrite(csvData) {
Logger.log("toActiveCellOverwrite");
Logger.log(JSON.stringify(csvData));
sheet = SpreadsheetApp.getActiveSheet();
sheet()
.getRange(
sheet()
.getActiveCell()
.getLastRow(),
sheet()
.getActiveCell()
.getColumn(),
csvData.length,
csvData[0].length
)
.setValues(csvData);
}
// Display Data on a Google Sheet
var sheet = function() {
return SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
};
function parseJsonToCsv(json, keys){
var values = [];
//values.push(title + "\n");
// Parse JSON Object
if(!Array.isArray(json)){
// Get Values
var v = [];
keys.forEach(
function (k){
v.push(json[k]);
}
);
values.push(keys.toString())
values.push("\n"+v)
//Logger.log('Parse Object values '+values);
} else {
// Parse JSON Array of Objects
for (i = 0; i < json.length; i++) {
var data = json[i];
// Get Values
var v = [];
keys.forEach(
function (k){
v.push(data[k]);
}
);
// Create a new line
if(i > 0){
values.push("\n"+v)
}else{
values.push(keys.toString())
values.push("\n"+v);
}
//Logger.log('Parse Array of Object values '+i + " : " +v);
}
}
return values;
}
function displayJSON(json,keys,title) {
var location = "";
if (!json) {
Logger.log("writeCsvData no csvContent");
return;
}
Logger.log("csvContent", json.toString());
try {
var csvContent = parseJsonToCsv(json, keys);//.toString();
/*
// fix the bug on Utilities.parseCsv() google script function which does not allow newlines in csv strings @simonjamain
csvContent = csvContent.replace(
/(["'])(?:(?=(\\?))\2[\s\S])*?\1/g,
function(e) {
return e.replace(/\r?\n|\r/g, " ");
}
);
//
*/
// set title
if(title){
csvContent = title + "\n" + csvContent;
}
csvData = Utilities.parseCsv(csvContent);
//Logger.log("parsed csvData ", csvData);
switch (location) {
case "overwrite":
toActiveCellOverwrite(csvData);
break;
case "newSheet":
toNewSheet(csvData);
break;
case "newRows":
toNewRows(csvData);
break;
default:
toActiveCellOverwrite(csvData);
}
// Insert new rows
// TO DO
} catch (error) {
Logger.log("writeCsvData error: " + error);
}
}
function toNewRows(csvData) {
//const sheet = SpreadsheetApp.getActiveSheet();
sheet().insertRows(
sheet()
.getActiveCell()
.getLastRow(),
csvData.length
);
sheet()
.getRange(
sheet()
.getActiveCell()
.getLastRow(),
sheet()
.getActiveCell()
.getColumn(),
csvData.length,
csvData[0].length
)
.setValues(csvData);
}
function toActiveCellOverwrite(csvData) {
Logger.log("toActiveCellOverwrite csvData" + csvData.toString())
//const sheet = SpreadsheetApp.getActiveSheet();
sheet()
.getRange(
sheet()
.getActiveCell()
.getLastRow(),
sheet()
.getActiveCell()
.getColumn(),
csvData.length,
csvData[0].length
)
.setValues(csvData);
}
//to use still
var spreadsheet = function() {
return SpreadsheetApp.getActiveSpreadsheet();
};
function toNewSheet(csvData) {
const sheet = SpreadsheetApp.getActiveSpreadsheet();
const datetime = getDateTimeString();
const title = csvData.toString().split(",")[0] + " : " + datetime;
Logger.log("creating sheet with title ", title);
sheet.insertSheet(title);
const newSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(title);
newSheet
.getRange(
sheet.getActiveCell().getLastRow(),
sheet.getActiveCell().getColumn(),
csvData.length,
csvData[0].length
)
.setValues(csvData);
}
function toActiveCellNewRows() {
const sheet = SpreadsheetApp.getActiveSheet();
var lRow = sheet.getLastRow();
var lCol = sheet.getLastColumn(),
range = sheet.getRange(lRow, 1, 1, lCol);
sheet.insertRowsAfter(lRow, 1);
range.copyTo(sheet.getRange(lRow + 1, 1, 1, lCol), { contentsOnly: false });
}
function getDateTimeString() {
var currentdate = new Date();
var datetime =
currentdate.getDate() +
"/" +
(currentdate.getMonth() + 1) +
"/" +
currentdate.getFullYear() +
" @ " +
currentdate.getHours() +
":" +
currentdate.getMinutes() +
":" +
currentdate.getSeconds();
return datetime;
}
/*
function displayJSON(json, keys, noHeaders){
if (!Array.isArray(json) || !keys.length) {
// array does not exist, is not an array, or is empty
Logger.log('displayJson did not receive json data');
return;
}
if (!Array.isArray(keys) || !keys.length) {
// array does not exist, is not an array, or is empty
Logger.log('displayJson did not receive keys');
return;
}
//json = [{"id":"1234","name":"sample"},{"id":"9876","name":"sample 2", "extra":"more info"}];
Logger.log('displayJSON'+ JSON.stringify(json));
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheets = ss.getSheets();
var sheet = ss.getActiveSheet();
var values = [];
var row = sheet.getActiveCell().getLastRow();
var column = sheet.getActiveCell().getColumn();
var numRows = 1;
var numColumns = 1;
...
*/
function flattenObject(ob) {
var toReturn = {};
for (var i in ob) {
if (!ob.hasOwnProperty(i)) continue;
if ((typeof ob[i]) == 'object') {
var flatObject = flattenObject(ob[i]);
for (var x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;
toReturn[i + '.' + x] = flatObject[x];
}
} else {
toReturn[i] = ob[i];
}
}
return toReturn;
};
// **************************
// Meraki API
// **************************
function getAdmins(apiKey, orgId) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/organizations/"+orgId+"/admins", {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
function getOrgs(apiKey) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/organizations", {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
data = data.replace(/([\[:])?(\d+)([,\}\]])/g, "$1\"$2\"$3");
var json = JSON.parse(data);
return json;
}
function getOrg(apiKey, orgId) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/organizations/"+orgId, {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
data = data.replace(/([\[:])?(\d+)([,\}\]])/g, "$1\"$2\"$3");
var json = JSON.parse(data)
return json;
}
function getNetworks(apiKey, orgId) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/organizations/"+orgId+"/networks", {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
function getDevicesStatuses(apiKey, orgId) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/organizations/"+orgId+"/deviceStatuses", {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
function getDevices(apiKey, netId) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/networks/"+netId+"/devices", {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
function getDeviceLossAndLatencyHistory(apiKey, netId, serial, timespan) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/networks/"+netId+"/devices/"+serial+"/lossAndLatencyHistory?timespan="+timespan+"&ip=8.8.8.8&uplink=wan1", {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
function getOrganizationUplinksLossAndLatency(apiKey, orgId, timespan) {
// https://api.meraki.com/api/v0/organizations/:organizationId/uplinksLossAndLatency?timespan={{timespan}}
Logger.log("running getOrganizationUplinksLossAndLatency");
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/organizations/"+orgId+"/uplinksLossAndLatency", {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
Logger.log(data);
var json = JSON.parse(data);
return json;
}
function getLicenseState(apiKey, orgId) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/organizations/"+orgId+"/licenseState", {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
function getConfigTemplates(apiKey, orgId) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/organizations/"+orgId+"/configTemplates", {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
function getClient(apiKey,netId, clientMac) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/networks/"+netId+"/clients/"+clientMac, {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
function getClients(apiKey,serial) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/devices/"+serial+"/clients?timespan="+settings.timespan, {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
function getInventory(apiKey, orgId) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/organizations/"+orgId+"/inventory", {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
function getGroupPolicies(apiKey, netId) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/networks/"+netId+"/groupPolicies", {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
function getSsids(apiKey, netId) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/networks/"+netId+"/ssids", {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
function getStaticRoutes(apiKey, netId) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/networks/"+netId+"/staticRoutes", {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
function getUplinkInfo(apiKey, netId, serial) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/networks/"+netId+"/devices/"+serial+"/uplink", {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
function getVlans(apiKey, netId) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/networks/"+netId+"/vlans", {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
function getSiteToSiteVpn(apiKey, netId) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/networks/"+netId+"/siteToSiteVpn", {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
// Requires Meraki Network to be configured with Hostname Visibility to work
function getTraffic(apiKey, netId) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/networks/"+netId+"/traffic?timespan=7200", {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
// Wireless Health
function getConnectionStats(apiKey, netId, t0, t1) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/networks/"+netId+"/connectionStats?t0="+t0+"&t1="+t1, {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
function getConnectionStatsByNode(apiKey, netId, t0, t1) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/networks/"+netId+"/devices/connectionStats?t0="+t0+"&t1="+t1, {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
function getConnectionStatsByClient(apiKey, netId, t0, t1) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/networks/"+netId+"/clients/connectionStats?t0="+t0+"&t1="+t1, {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
function getLatencyStats(apiKey, netId, t0, t1) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/networks/"+netId+"/latencyStats?t0="+t0+"&t1="+t1, {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
function getLatencyStatsByNode(apiKey, netId, t0, t1) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/networks/"+netId+"/devices/latencyStats?t0="+t0+"&t1="+t1, {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
function getLatencyStatsByClient(apiKey, netId, t0, t1) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/networks/"+netId+"/clients/latencyStats?t0="+t0+"&t1="+t1, {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
function getFailedConnections(apiKey, netId, t0, t1) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/networks/"+netId+"/failedConnections?t0="+t0+"&t1="+t1, {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}
// **************************
// Reports
// **************************
function callOrgs(){
var data = [];
var keys = [];
var result = getOrgs(settings.apiKey, settings.orgId);
if(!Array.isArray(result)){return}
result.forEach(function(obj){
var flat = flattenObject(obj);
data.push(flat);
// set keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
displayJSON(data,keys);
}
function callOrg(){
var data = [];
var keys = [];
var result = getOrg(settings.apiKey, settings.orgId);
var flat = flattenObject(result);
data.push(flat);
// set keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
displayJSON(data,keys);
}
function callAdmins(){
var data = [];
var keys = [];
var result = getAdmins(settings.apiKey, settings.orgId);
if(!Array.isArray(result)){return}
result.forEach(function(obj){
var flat = flattenObject(obj);
data.push(flat);
// set keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
displayJSON(data,keys);
}
function callNetworks(){
var data = [];
var keys = [];
if(!settings.orgId){
promptOrg();
}
var result = getNetworks(settings.apiKey, settings.orgId);
if(!Array.isArray(result)){return}
result.forEach(function(obj){
var flat = flattenObject(obj);
data.push(flat);
// set keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
displayJSON(data,keys);
}
function callDevices(){
var data = [];
var keys = [];
var nets = getNetworks(settings.apiKey, settings.orgId);
// Get Devices for each network in the organization
for (var i = 0; i <= nets.length; i++){
try{
var result = getDevices(settings.apiKey, nets[i].id);
if(!Array.isArray(result)){continue}
result.forEach(function(obj){
// flatten object and add network info
var flat = flattenObject(obj);
flat['networkId'] = nets[i].id;
flat['networkName'] = nets[i].name;
data.push(flat);
// set keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
}catch(e){
Logger.log('error'+e);
continue;
}
}
displayJSON(data,keys);
}
function callDeviceLossAndLatencyHistory(){
var data = [];
var keys = [];
var devices = getDevices(settings.apiKey, settings.netId);
// Get Devices for each network in the organization
for (var i = 0; i <= devices.length; i++){
try{
var result = getDeviceLossAndLatencyHistory(settings.apiKey, settings.netId, devices[i].serial, settings.timespan);
if(!Array.isArray(result)){continue}
result.forEach(function(obj){
// flatten object and add network info
var flat = flattenObject(obj);
flat['deviceSerial'] = devices[i].serial;
flat['deviceName'] = devices[i].name;
data.push(flat);
// set keys
keys = ['deviceName', 'deviceSerial'];
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
}catch(e){
Logger.log('error'+e);
continue;
}
}
displayJSON(data,keys);
}
function callDevicesStatuses(){
var data = [];
var keys = [];
var result = getDevicesStatuses(settings.apiKey, settings.orgId);
if(!Array.isArray(result)){return}
result.forEach(function(obj){
var flat = flattenObject(obj);
data.push(flat);
// set keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
displayJSON(data,keys);
}
function callOrganizationUplinksLossAndLatency(){
var data = [];
var keys = [];
var nets = getNetworks(settings.apiKey, settings.orgId);
var result = getOrganizationUplinksLossAndLatency(settings.apiKey, settings.orgId, settings.timespan);
var netNames = {};
nets.forEach(function(n){ netNames[n.id]=n.name});
Logger.log("netNames");
Logger.log(JSON.stringify(netNames));
if(!Array.isArray(result)){return}
result.forEach(function(obj, index){
var flat = flattenObject(obj);
// attach network name to report
flat.networkName = netNames[obj.networkId];
data.push(flat);
// set static keys
keys=['networkName'];
// set dynamic keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
displayJSON(data,keys,"Organization Uplinks Loss And Latency");
//displayJSON(data,keys);
}
function callInventory(){
var data = [];
var keys = [];
var result = getInventory(settings.apiKey, settings.orgId);
if(!Array.isArray(result)){return}
result.forEach(function(obj){
var flat = flattenObject(obj);
data.push(flat);
// set keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
displayJSON(data,keys);
}
function callLicenseState(){
var data = [];
var keys = [];
var result = getLicenseState(settings.apiKey, settings.orgId);
var flat = flattenObject(result);
data.push(flat);
keys = ['status','expirationDate'];
displayJSON(data,keys);
}
function callLicenseStateForOrgs(){
var data = [];
var keys = [];
var orgs = getOrgs(settings.apiKey);
// Get License State for each org for API key
for (var i = 0; i <= orgs.length; i++){
try{
var license = getLicenseState(settings.apiKey, orgs[i].id);
// flatten object and add org info
var flat = flattenObject(license);
flat['orgId'] = orgs[i].id;
flat['orgName'] = orgs[i].name;
data.push(flat);
// set keys
keys = ['orgName', 'orgId', 'status','expirationDate'];
// device count details
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
}catch(e){
Logger.log('error'+e);
continue;
}
}
displayJSON(data,keys);
}
function callLicenseStateDetails(){
var data = [];
var keys = [];
var result = getLicenseState(settings.apiKey, settings.orgId);
var flat = flattenObject(result);
data.push(flat);
// set keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
displayJSON(data,keys);
}
function callConfigTemplates(){
var data = [];
var keys = [];
var result = getConfigTemplates(settings.apiKey, settings.orgId);
if(!Array.isArray(result)){return}
result.forEach(function(obj){
var flat = flattenObject(obj);
data.push(flat);
// set keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
displayJSON(data,keys);
}
function callVlansOfOrg(){
var data = [];
var keys = [];
var nets = getNetworks(settings.apiKey, settings.orgId);
// Get VLANs for each network in the organization
for (var i = 0; i <= nets.length; i++){
try{
var result = getVlans(settings.apiKey, nets[i].id);
if(!Array.isArray(result)){continue}
result.forEach(function(obj){
// flatten object and add network info
var flat = flattenObject(obj);
flat['networkId'] = nets[i].id;
flat['networkName'] = nets[i].name;
data.push(flat);
// set keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
}catch(e){
Logger.log('error'+e);
continue;
}
}
displayJSON(data,keys);
}
function callTrafficOfOrg(){
var data = [];
var keys = [];
var nets = getNetworks(settings.apiKey, settings.orgId);
// Get traffic analysis for each network in the organization
for (var i = 0; i < nets.length; i++){
try{
var traffic = getTraffic(settings.apiKey, nets[i].id);
// flatten object and add network info
var flat = flattenObject(traffic);
flat.networkId = nets[i].id;
flat.networkName = nets[i].name;
// set data
data.push(flat);
// set keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
}catch(e){
Logger.log('error'+e);
continue;
}
}
displayJSON(data, keys);
}
function callSiteToSiteVpn(){
var data = [];
var keys = [];
var nets = getNetworks(settings.apiKey, settings.orgId);
// Get vpn info for each network in the organization
for (var i = 0; i < nets.length; i++){
try{
var vpn = getSiteToSiteVpn(settings.apiKey, nets[i].id);
// flatten object and add network info
var flat = flattenObject(vpn);
flat.networkId = nets[i].id;
flat.networkName = nets[i].name;
// set data
data.push(flat);
// set keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
}catch(e){
Logger.log('error'+e);
continue;
}
}
displayJSON(data, keys);
}
function callSsidsOfOrg(){
var data = [];
var keys = [];
var nets = getNetworks(settings.apiKey, settings.orgId);
// Get SSIDs for each network in the organization
for (var i = 0; i <= nets.length; i++){
try{
var ssids = getSsids(settings.apiKey, nets[i].id);
if(!Array.isArray(ssids)){continue}
ssids.forEach(function(obj){
// flatten object and add network info
var flat = flattenObject(obj);
flat['networkId'] = nets[i].id;
flat['networkName'] = nets[i].name;
data.push(flat);
// set keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
}catch(e){
Logger.log('error'+e);
continue;
}
}
displayJSON(data,keys);
}
function callGroupPoliciesOfOrg(){
var data = [];
var keys = [];
var nets = getNetworks(settings.apiKey, settings.orgId);
// Get Policies for each network in the organization
for (var i = 0; i < nets.length; i++){
try{
var policies = getGroupPolicies(settings.apiKey, nets[i].id);
if(!Array.isArray(policies)){continue}
policies.forEach(function(obj){
// flatten object and add network info
var flat = flattenObject(obj);
flat['networkId'] = nets[i].id;
flat['networkName'] = nets[i].name;
data.push(flat);
// set keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
}catch(e){
Logger.log('error'+e);
continue;
}
}
displayJSON(data,keys);
}
function callClientsOfOrg(){
var data = [];
var keys = [];
const devices = getDevicesStatuses(settings.apiKey, settings.orgId);
const nets = getNetworks(settings.apiKey, settings.orgId);
// Get clients for each device in the organization
for (var i = 0; i < devices.length; i++){
try{
var clients = getClients(settings.apiKey, devices[i].serial);
if(!Array.isArray(clients)){continue}
clients.forEach(function(obj){
// flatten object and add network info
var flat = flattenObject(obj);
flat.deviceName = devices[i].name;
flat.deviceLanIp = devices[i].lanIp;
flat.deviceWan1IP = devices[i].wan1Ip;
flat.deviceWan2IP = devices[i].wan2Ip;
flat.deviceMac = devices[i].mac;
flat.deviceName = devices[i].name;
flat.networkId = devices[i].networkId;
flat.networkName = nets.filter(function(obj){
return devices[i].networkId == obj['id'];
})[0]['name'];
data.push(flat);
// set keys
keys = ['description','dhcpHostname','mac','ip','usage.sent','usage.recv','id','networkId','networkName']
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
} catch(e){
Logger.log('error'+e);
continue;
}
}
displayJSON(data,keys);
}
function callClientsOfOrgDetails(){
var data = [];
var keys = [];
const devices = getDevicesStatuses(settings.apiKey, settings.orgId);
const nets = getNetworks(settings.apiKey, settings.orgId);
// Get clients for each device in the organization
for (var i = 0; i < devices.length; i++){
try{
var clients = getClients(settings.apiKey, devices[i].serial);
if(!Array.isArray(clients)){continue}
clients.forEach(function(obj){
// flatten object
var flat = flattenObject(obj);
// add network info
flat.deviceName = devices[i].name;
flat.deviceLanIp = devices[i].lanIp;
flat.deviceWan1IP = devices[i].wan1Ip;
flat.deviceWan2IP = devices[i].wan2Ip;
flat.deviceMac = devices[i].mac;
flat.deviceName = devices[i].name;
flat.networkId = devices[i].networkId;
flat.networkName = nets.filter(function(obj){
return devices[i].networkId == obj['id'];
})[0]['name'];
// add client info
var client = getClient(settings.apiKey, devices[i].networkId, obj.mac);
for (var attrname in client) { flat[attrname] = client[attrname]; }
data.push(flat);
// set keys
keys = ['description','dhcpHostname','mac','ip','usage.sent','usage.recv','id','networkId','networkName']
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
} catch(e){
Logger.log('error'+e);
continue;
}
}
displayJSON(data,keys);
}
function callClientsOfNet(){
var data = [];
var keys = [];
var deviceStatuses = getDevicesStatuses(settings.apiKey, settings.orgId);
var devices = deviceStatuses.filter(function(d){
return d.networkId == settings.netId;
});
// Get clients for each device in the organization
for (var i = 0; i < devices.length; i++){
try{
var clients = getClients(settings.apiKey, devices[i].serial);
if(!Array.isArray(clients)){continue}
clients.forEach(function(obj){
// flatten object and add network info
var flat = flattenObject(obj);
flat.deviceName = devices[i].name;
flat.deviceLanIp = devices[i].lanIp;
flat.deviceWan1IP = devices[i].wan1Ip;
flat.deviceWan2IP = devices[i].wan2Ip;
flat.deviceMac = devices[i].mac;
flat.deviceName = devices[i].name;
flat.networkId = devices[i].networkId;
data.push(flat);
// set keys
keys = ['description','dhcpHostname','mac','ip','usage.sent','usage.recv','id']
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
} catch(e){
Logger.log('error'+e);
continue;
}
}
displayJSON(data,keys);
}
function callClientsOfNetDetails(){
var data = [];
var keys = [];
var deviceStatuses = getDevicesStatuses(settings.apiKey, settings.orgId);
var devices = deviceStatuses.filter(function(d){
return d.networkId == settings.netId;
});
// Get clients for each device in the organization
for (var i = 0; i < devices.length; i++){
try{
var clients = getClients(settings.apiKey, devices[i].serial);
// Logger.log(JSON.parse(clients));
if(!Array.isArray(clients)){continue}
clients.forEach(function(obj){
var client = getClient(settings.apiKey, devices[i].networkId, obj.mac);
Logger.log(client);
// flatten object
var flat = flattenObject(obj);
// Copy device info
flat.deviceName = devices[i].name;
flat.deviceLanIp = devices[i].lanIp;
flat.deviceWan1IP = devices[i].wan1Ip;
flat.deviceWan2IP = devices[i].wan2Ip;
flat.deviceMac = devices[i].mac;
flat.deviceName = devices[i].name;
flat.networkId = devices[i].networkId;
// Copy over all client details
for (var attrname in client) { flat[attrname] = client[attrname]; }
Logger.log("flat"+JSON.stringify(flat));
data.push(flat);
// set keys
keys = ['description','dhcpHostname','mac','ip','usage.sent','usage.recv','id']
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
} catch(e){
Logger.log('error'+e);
continue;
}
}
displayJSON(data,keys);
}
function callStaticRoutes(){
var data = [];
var keys = [];
var nets = getNetworks(settings.apiKey, settings.orgId);
// Get routes for each network in the organization
for (var i = 0; i <= nets.length; i++){
try{
var routes = getStaticRoutes(settings.apiKey, nets[i].id);
if(!Array.isArray(routes)){continue}
routes.forEach(function(obj){
// flatten object and add network info
var flat = flattenObject(obj);
flat['networkId'] = nets[i].id;
flat['networkName'] = nets[i].name;
data.push(flat);
// set keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
}catch(e){
Logger.log('error'+e);
continue;
}
}
displayJSON(data,keys);
}
function callConnectionStatsOfOrg(){
var data = [];
var keys = [];
var nets = getNetworks(settings.apiKey, settings.orgId);
/*
var nets = [
{
"name":"test",
"id":"L_643451796760561218"
}
];
*/
var t1 = Math.floor((new Date).getTime() / 1000);
var t0 = t1 - settings.timespan;
// Get routes for each network in the organization
for (var i = 0; i <= nets.length; i++){
try{
var stats = getConnectionStats(settings.apiKey, nets[i].id, t0, t1);
Logger.log('stats ' + JSON.stringify(stats));
typeof val === 'object'
if(!isObject(stats)){
stats = {};
//continue;
}
// flatten object and add network info
var flat = flattenObject(stats);
flat['networkId'] = nets[i].id;
flat['networkName'] = nets[i].name;
Logger.log('stats parsed ' + JSON.stringify(flat));
data.push(flat);
// set keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
}catch(e){
Logger.log('error'+e);
continue;
}
}
displayJSON(data,keys);
}
function callLatencyStatsOfOrg(){
var data = [];
var keys = [];
var nets = getNetworks(settings.apiKey, settings.orgId);
/*
var nets = [
{
"name":"test",
"id":"L_643451796760561218"
}
];
*/
var t1 = Math.floor((new Date).getTime() / 1000);
var t0 = t1 - settings.timespan;
// Get routes for each network in the organization
for (var i = 0; i <= nets.length; i++){
try{
var stats = getLatencyStats(settings.apiKey, nets[i].id, t0, t1);
Logger.log('stats ' + JSON.stringify(stats));
typeof val === 'object'
if(!isObject(stats)){
stats = {};
//continue;
}
// flatten object and add network info
var flat = flattenObject(stats);
flat['networkId'] = nets[i].id;
flat['networkName'] = nets[i].name;
Logger.log('stats parsed ' + JSON.stringify(flat));
data.push(flat);
// set keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
}catch(e){
Logger.log('error'+e);
continue;
}
}
displayJSON(data,keys);
}
function callConnectionStatsByNode(){
var data = [];
var keys = [];
var t1 = Math.floor((new Date).getTime() / 1000);
var t0 = t1 - settings.timespan;
var stats = getConnectionStatsByNode(settings.apiKey, settings.netId, t0, t1);
stats.forEach(function(s) {
// flatten object and add network info
var flat = flattenObject(s);
flat['networkId'] = settings.netId;
data.push(flat);
// set keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
displayJSON(data,keys);
}
function callConnectionStatsByClient(){
var data = [];
var keys = [];
var t1 = Math.floor((new Date).getTime() / 1000);
var t0 = t1 - settings.timespan;
var stats = getConnectionStatsByClient(settings.apiKey, settings.netId, t0, t1);
stats.forEach(function(s) {
// flatten object and add network info
var flat = flattenObject(s);
flat['networkId'] = settings.netId;
data.push(flat);
// set keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
displayJSON(data,keys);
}
function callLatencyStatsByNode(){
var data = [];
var keys = [];
var t1 = Math.floor((new Date).getTime() / 1000);
var t0 = t1 - settings.timespan;
var stats = getLatencyStatsByNode(settings.apiKey, settings.netId, t0, t1);
stats.forEach(function(s) {
// flatten object and add network info
var flat = flattenObject(s);
flat['networkId'] = settings.netId;
data.push(flat);
// set keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
displayJSON(data,keys);
}
function callLatencyStatsByClient(){
var data = [];
var keys = [];
var t1 = Math.floor((new Date).getTime() / 1000);
var t0 = t1 - settings.timespan;
var stats = getLatencyStatsByClient(settings.apiKey, settings.netId, t0, t1);
stats.forEach(function(s) {
// flatten object and add network info
var flat = flattenObject(s);
flat['networkId'] = settings.netId;
data.push(flat);
// set keys
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
displayJSON(data,keys);
}
function callFailedConnections(){
var data = [];
var keys = [];
var t1 = Math.floor((new Date).getTime() / 1000);
var t0 = t1 - settings.timespan;
var stats = getFailedConnections(settings.apiKey, settings.netId, t0, t1);
stats.forEach(function(s) {
// flatten object and add network info
var flat = flattenObject(s);
flat['networkId'] = settings.netId;
data.push(flat);
// set keys
keys = ['clientMac'];
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
});
displayJSON(data,keys);
}
function callUplinkInfos(){
var data = [];
var keys = [];
var devices = getDevicesStatuses(settings.apiKey, settings.orgId);
// Get uplink info for each device in the organization
for (var i = 0; i < devices.length; i++){
try{
var uplink = getUplinkInfo(settings.apiKey, devices[i].networkId, devices[i].serial);
// flatten object and add network info
var flat = flattenObject(uplink);
flat.networkId = devices[i].networkId;
flat.serial = devices[i].serial;
flat.mac = devices[i].mac;
flat.deviceName = devices[i].name;
flat.status = devices[i].status;
// set data
data.push(flat);
// set keys
keys = ['networkId','serial','mac','deviceName','status']
Object.keys(flat).forEach(function(value){
if (keys.indexOf(value)==-1) keys.push(value);
});
}catch(e){
Logger.log('error'+e);
continue;
}
}
displayJSON(data, keys);
}
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2019 Cory Guynn
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
@victorsamsara

This comment has been minimized.

Copy link

victorsamsara commented Apr 3, 2019

Hi Cory, thanks for this! Quick question, I'm trying to create something similar but can't get past the testing phase. Disclaimer: I'm new to JS.

When I try to run some sample code like below, I always get the error of "undefined" or "null" variables:

var apiKey = 12345
var orgId = 12345

function getAdmins(apiKey, orgId) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/organizations/"+orgId+"/admins", {headers:{'X-Cisco-Meraki-API-Key': apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}

The only way to fix it is by referencing the parameters with "this." inside the fetch method. For example:

function getAdmins(apiKey, orgId) {
var response = UrlFetchApp.fetch("https://api.meraki.com/api/v0/organizations/"+**this.orgId**+"/admins", {headers:{'X-Cisco-Meraki-API-Key': this.apiKey}});
var data = response.getContentText();
var json = JSON.parse(data);
return json;
}

I have not been able to find a reasonable answer, it seems that when the code is run (even without explicitly calling the function) the fetch method tries to resolve DNS. Something seems to be odd with the variable scope.

Thanks in advance!

Victor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.