Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schlos/b77cd6162cf0e88c2bd60c7c2eda7f83 to your computer and use it in GitHub Desktop.
Save schlos/b77cd6162cf0e88c2bd60c7c2eda7f83 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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment