Search code examples
phptaskdashboardasana

Getting a ratio of completed tasks to total tasks in Asana


I'm creating a panel for Panic's StatusBoard to show projects from my workspace, with the ratio of completed tasks to total tasks.

I can do this currently, based on what I'm seeing in the API Docs, the problem is I need to make about 40 requests to get all the info I need and this number will only get larger as more tasks are added to my selected projects.

I'm looping through each selected project and getting each individual task, but all I'm taking from that task object in the 'completed' property.

Is there a way to get each project with completed counts and total counts as properties?

Or, is there another approach that I could take so that I don't get timeout errors when making so many requests..


Solution

  • You should be able to do this by getting all of the tasks for a project and selecting the completed field using the ?opt_fields=completed option on your request.

    E.g., http://app.asana.com/api/1.0/projects/[project]/tasks?opt_fields=completed

    where [project] is the project ID you're querying. This will return the completed status of all tasks within a given project. You would then iterate over the returned tasks and count the completed/uncompleted statuses.

    Note that with the opt_fields option, only the identified fields will be returned.