Bas
Bas

Reputation: 2038

Efficiently getting all completed tasks

For an application I need all the user's recently completed tasks (recent meaning the last 7 days in this case). I've got it working now, but it's extremely inefficient and in the API reference I can't see a better way to do it.

What I currently need to do is get the current user (https://app.asana.com/api/1.0/users/me), iterate through the user's workspaces and call https://app.asana.com/api/1.0/tasks?workspace=workspaceId&assignee=me&completed_since=sevenDaysAgo for each workspace. This gives me the compact task data for all completed tasks for all projects in that workspace, and also all uncompleted tasks for all projects in that workspace. Since I only need the completed tasks, I need to filter the uncompleted tasks out of that list. However, the compact task data doesn't include the "completed" property. To figure out if a task is completed or uncompleted, I need to get the full task data, which means a call to https://app.asana.com/api/1.0/tasks/taskId per task.

Say I have two workspaces that each have three projects, and each project has on average 100 completed tasks and 200 uncompleted tasks. That means 1 + 2 + (2 * 3) + (2 * 3 * 300) = a whopping 1809 API requests. Apart from this being very slow, it's also a large hit on the Asana servers.

Is there a way to do this more efficiently? Only getting compact task data for completed tasks would go a long way. Getting it in one call would be even better: how does Asana itself do this in My Tasks > View: Recently Completed Tasks, for instance?

Upvotes: 1

Views: 513

Answers (1)

agnoster
agnoster

Reputation: 3784

(Asana dev here) Have you considered using ?opt_fields=completed in your initial GET /tasks request? You can specifically request any fields you want, see the Input/Output option docs, and of course see Task docs for a reference on available fields. So if you really just want the name (for instance) you could request ?opt_fields=completed,name.

Sadly, you will need to do the filtering out of incomplete tasks on your side.

Upvotes: 3

Related Questions