Forked from superstrong/google-script-basecrm-api.js
Created
August 26, 2018 17:16
-
-
Save schlos/a1e7e29bfd6f5157c89f53c93166b7c4 to your computer and use it in GitHub Desktop.
Retrieve JSON data from the BaseCRM API and add it to a Google Sheet. This example retrieves all users. Stands on the shoulders of https://gist.github.com/varun-raj/5350595a730a62ca1954
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getBaseUsers() { | |
var options = { | |
"contentType" : "application/json", | |
"headers" : { | |
"Accept": "application/json", | |
"Authorization": "Bearer <TOKEN>" | |
} | |
} | |
var response = UrlFetchApp.fetch("https://api.getbase.com/v2/users", options); | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheets = ss.getSheets(); | |
var sheet = ss.getSheetByName("baseUsers"); // specific sheet name; alternatively use ss.getActiveSheet() | |
var dataAll = JSON.parse(response.getContentText()); // | |
var dataSet = dataAll.items; // "items" is the key containing relevant objects | |
var rows = [], | |
data; | |
for (i = 0; i < dataSet.length; i++) { | |
data = dataSet[i]; | |
rows.push([data.data.id, data.data.name, data.data.email]); //your JSON entities here | |
} | |
// [row to start on], [column to start on], [number of rows], [number of entities] | |
dataRange = sheet.getRange(2, 1, rows.length, 3); | |
dataRange.setValues(rows); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment