Google Apps Script - get tasks from a project

projects
tasks
api

#1

Hi,

I try to request all tasks from a project and to include the field ‘completed’ in the response. The following curl command is working and delivers the expected result:
url -H "Authorization: Bearer " https://app.asana.com/api/1.0/projects/‘project-id’/tasks?opt_expand=completed

Now I try to get the same result via Google Apps Script:

function getTasks(){
  var projectId = "'project-id'"; //Project ID 
  var token = "'token'"; //Asana Personal Access Token
  var bearerToken = "Bearer " + token;
  //Request
  var request = {
    data : { 
      opt_expand : ['completed']
    }
  };
  // Request options
  var options = {
    "method" : "GET",
    "headers" : {"Authorization": bearerToken}, 
    "contentType": 'application/json',
    "payload" : JSON.stringify(request) 
  };
  Logger.log(options);

  try {
    var url = "https://app.asana.com/api/1.0/projects/" + projectId + "/tasks";
    var result = UrlFetchApp.fetch(url, options);
    var reqReturn = result.getContentText();
    Logger.log(reqReturn);
  } 
  catch (e) {
    Logger.log(e);
  }
}

Here I get the error message:
returned code 404. Truncated server response: {"errors":[{"message":"No matching route for request","help":"For more information on API status codes and how to handle them, read the docs on err... (use muteHttpExceptions option to examine full response)

If I do not use the ‘payload’ option I get a valid result, but then without the ‘completed’ field. Any ideas?

Thanks


#2

Out of curiosity, what are you using this part of your process for?


#3

In order to collect some numbers for KPIs on our projects. In the past I did this via the Asana Goole Sheets Interface. The Asana Google Sheets interface has unfortunately a limit of 10 and if more than 10 people are working on your projects you need to collect the numbers in a different way. Now I was looking at the API. Best case this will fit my purpose.


#4

Interesting. I’m only getting started on building our processes, so I’m interested in learning about how others are using Asana. Thanks for answering!


#5

Unfortunately, there is no way to filter for completed tasks in the Asana API. Sorry that the error message wasn’t very helpful. We hope to add more filtering in the future. Here is a post that goes into more detail about this aspect of the API: