New endpoint: project task counts

Hello all! With the growing set of high-level reporting and planning features Asana has been adding to our web app (timeline, portfolios, workload) we’ve decided to bring some additional high-level reporting functionality to the API: project task counts. When you view a list of projects in a portfolio or view a project’s “Progress” tab, you can see a count of complete and incomplete tasks and milestones in that project, and those counts are now in the API!

Specifically, by hitting GET /projects/<project-gid>/task_counts you can get six different counts for that project:

{
  "num_tasks": 150,
  "num_incomplete_tasks": 100,
  "num_completed_tasks": 50,
  "num_milestones": 10,
  "num_incomplete_milestones": 7,
  "num_completed_milestones": 3
}

A few things to note about this endpoint:

  • All fields are opt-in. You’ll need to use the opt_fields parameter to select which counts you want. Like the rest of our API, we encourage you to select only the fields you need.
  • This endpoint has a separate rate limit. You will be limited to 60 requests per minute, similar to the search API. These fields also count fairly high against our cost limits, so you should only opt-in to the fields you truly need.
  • Milestones are included in task counts. Milestones are a subtype of tasks, and so num_tasks and other task counts also include counts of milestones. In the above example, there are 150 tasks in the project, of which 140 have resource_subtype: "default_task" and 10 have resource_subtype: "milestone".

Take a look at our docs for more information. Happy reporting!

2 Likes

That’s great news, will be useful to show our customers why the app seems slow fetching data, when we know that a project have 25000 tasks.
Can these new fields be returned by you while paging, on the first page?
I mean, if I query for /projects/xyz/tasks, when I receive the first page with the “paging offset”, can we also receive the “total count” to have an idea of how many page we’ll need to query?
If not, I’ll certainly add a query to these new task_counts when I detect a huge project that needs paging.

Unfortunately, we cannot make these counts part of our pagination systems. They only apply to these few specific categories (completed/incomplete/total tasks/milestones in a project) and would not work when, for example, using modified_since to filter the tasks, or when making queries for other kinds of objects in the API.

For some reason I’ve not been able to get this to work no matter what I include in the opt_fields as part of the GET request. Does anyone have a working example? Thanks!

1 Like

Realised I hadn’t posted an update after solving this issue, it was super simple and just down to me not reading properly…
The following GET request works fine!
https://app.asana.com/api/1.0/projects/<project_gid>/task_counts?opt_fields=num_tasks

1 Like

Reposted as it’s own thread in the API forum How to use the Task Count Endpoint for Projects in the java client library

I struggle creating this request with the java client-lib "com.asana:asana:0.10.1" - I would assume that I just need to do the following:

client.projects.getTaskCountsForProject(projectId).option("fields", "num_tasks").execute()

But this always returns me an empty JSON object {} -what am I missing here?

Debugging the client I see the following:

  • The LowLevelHttpRequest uses the wrong url https://app.asana.com/api/1.0/projects//task_counts?opt_pretty=false&limit=50
    at [1]
  • This should be because in [2] the url doesn’t contain the opt_fields see [3]

But I’m still not sure what I might have configured wrong - any help would be very much appreciated.

References
  • [1] com.google.http-client/google-http-client/1.20.0/5140e4d6fc293ede7dee965e8f3426d3e9e3d0c0/google-http-client-1.20.0-sources.jar!/com/google/api/client/http/HttpRequest.java:862
  • [2] com.asana/asana/0.10.1/fea2bd16f4426fad8ae4aef42bfde7c7b03692ea/asana-0.10.1-sources.jar!/com/asana/Client.java:201
  • [3] url = { "opt_pretty" -> {Boolean@3443} false, "limit" -> {Integer@3444} 50

Nice!
Do we have this method for users?