Returning Sections In The Get Tasks Response

Hello!

We have a use case where when getting tasks for a Project we may want to filter out tasks that fall under a specific section. I’m not seeing it in the schema but is there a way to get the section a task falls under via the /API/1.0/projects/{projectId}/tasks endpoint?

I see we can get tasks by section but it would add quite a few calls, and a lot of fragility, to get all the sections, then get all the tasks for every section that isn’t filtered out, then concatenating them all together and de-duping that list. I would be worried about general failures or hitting the API limit if we did it that way.

Thank you!

Hi @Alex_Hofer

There are some possible solutions for your need.

First, your initial guess of querying all sections, choosing the one you want, then getting all tasks for these sections can be good.
But, to avoid limitation issues, set them in queue and query them one by one. Also, you can do that using batch, to get them 5 by 5 for exemple.
https://developers.asana.com/docs/batch-api
You can’t run your query more than 1500 times/minute, and a batch of 5 counts for 5. But, trust me, the api is slow enough that you will not be able to reach that 1500 limit using a queue… :frowning:

Another solution can be to use the Search API
https://developers.asana.com/docs/search-tasks-in-a-workspace

From that endpoint you can query exactly the sections you need, using:
GET /workspaces/xxx/tasks/search??sections.any=aaa,bbb,ccc,…

But, when using the search API, you need to code your pagination differently, sort by date added, and then query the next page based on the last date added of the previous page.

1 Like

Hi @Alex_Hofer,

In addition to @Frederic_Malenfant’s suggestions, you can also make your tasks retrieval call like this:
/API/1.0/projects/{projectId}/tasks?opt_fields=memberships.section
and that will give you the section info for each returned task.

Ah thank you @Phil_Seeman! This is exactly what I was looking for! :slightly_smiling_face:

1 Like