Skip to content

Instantly share code, notes, and snippets.

@superstrong
Created November 19, 2016 02:10
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save superstrong/b8d7413724ce311d11e672ad5d2c57c7 to your computer and use it in GitHub Desktop.
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
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);
}
@Bsweetz
Copy link

Bsweetz commented Oct 11, 2017

this is awesome for use with Zapier! thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment