Created
November 19, 2016 02:10
-
-
Save superstrong/b8d7413724ce311d11e672ad5d2c57c7 to your computer and use it in GitHub Desktop.
Retrieve JSON data from the Asana API and add it to a Google Sheet. This example retrieves all the users in a workspace. Stands on the shoulders of https://gist.github.com/varun-raj/5350595a730a62ca1954
This file contains 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 getAsanaUsers() { | |
var options = { | |
"headers" : { | |
"Authorization": "Bearer <TOKEN>" | |
} | |
} | |
var response = UrlFetchApp.fetch("https://app.asana.com/api/1.0/workspaces/<workspace-id>/users", options); | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheets = ss.getSheets(); | |
var sheet = ss.getSheetByName("asanaUsers"); // specific sheet name; alternatively use ss.getActiveSheet() | |
var dataAll = JSON.parse(response.getContentText()); // | |
var dataSet = dataAll.data; // "data" is the key containing the relevant objects | |
var rows = [], | |
data; | |
for (i = 0; i < dataSet.length; i++) { | |
data = dataSet[i]; | |
rows.push([data.id, data.name]); //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, 2); | |
dataRange.setValues(rows); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is awesome for use with Zapier! thank you