rubyasanaasana-api

Get a list of all tasks and subtasks from Asana REST API


I am trying to get all the tasks and subtasks for an Asana project by hitting the REST endpoint https://app.asana.com/api/1.0/tasks?project=1234&opt_fields=... but this only gives the tasks, not all subtasks or sub-subtasks etc. I don't see any other end point for accessing all subtasks, it only looks like I can get to this info by including subtasks.name etc as part of the opt_fields or accessing the subtasks via the /tasks/987/subtasks endpoint. This has all the disadvantages of making many remote requests with a rate limited backend though.


Solution

  • There is no current method to get all tasks, subtask, and sub-subtasks. The closest you can come to is to add subtasks.name, subtasks.id etc. In this case I could hit the endpoint https://app.asana.com/api/1.0/tasks?project=1234&opt_fields=id,name,subtasks.name,subtasks.id,etc and I only needed to access a few of the fields in the subtask. Once I got the results from the endpoint I could extract the subtasks like so (in ruby):

    tasks = get_tasks_from_api()
    subtasks = tasks.map { |t| t.subtasks } # this is an array of arrays [[x,y],[z]] etc
    subtasks = subtasks.flatten # make into just an array [x,y,z]
    subtasks = subtasks.compact # make sure there are no nils
    
    tasks = tasks + subtasks # this will be all tasks followed by all subtasks