Search code examples
pythonasanaasana-api

How to get a user's oldest task from the Asana API?


So I have a little bit of a dilemma in trying to obtain the oldest task of a user. I’m able to get the oldest task of each user in my team's workspace, but takes 1 hour and 30 minutes to run.

Here's the current workflow that I have currently:

1) Get all users and store in a users var.
2) Iterate through all users.
3) For each user, grab all tasks and store in a tasks var.
4) Iterate through all tasks, compare task.modified_at attribute to oldest_task var, store in oldest_task if task.modified_at is older.

What's taking so long is the loading of and iterating through each user's tasks. Any ideas on how to make this process faster? Would there potentially be a way to query specifically for the oldest task of a user through the API?

I’m building a tool that will track the age of the oldest task for each user for tracking purposes. I would love to find out if there’s something that I’m missing.


Solution

  • For oldest task you should probably use created_at rather than modified_at (the oldest task could have been modified recently, after all).

    We don't have any way in the API to specifically get the older task, or order by creation time or anything like that, so for now your workaround is in fact the only way to do it. You may be able to make it a little faster by using ?opt_fields=created_at in the task query to cut down on how much data you're loading.