Search code examples
apiasana

How to consolidate API calls for the ASANA API


I'm a freelance web dev and I work with a lot of clients across many different workspaces in Asana. Not being able to get a consolidated view makes this a tedious and difficult thing to manage, so I'm putting together my own little utility to help me get a 'superview' of tasks assigned to me in order of the due date. In order to make this easier for me to scan, I need to have the project name next to the task details.

The easiest way, in my mind, would be a single API call for all tasks assigned to me and request the project name, task name, task id, due date, and workspace name all at once.

The API doesn't seem to allow this consolidated type of request, however, so instead, the workflow goes something like this;

  1. API call to get all my workspaces
  2. Loop through the workspaces, making an API call for each to get all tasks
  3. Use PHP to sort those tasks accordingly
  4. Loop through those tasks making an API call for the first instance of each project in order to get the project name (I cache the data as I go so that I'm only making a call once per project)

The issue I'm getting is a 500 error when I start making API calls to get the project details. I doubt I'm hitting the 100 call per minute limit, but I'm still getting the errors none the less. In light of this, I'm looking for a way to make a consolidated call that contains all the data I need, but I can't seem to figure it out.

Anyone have some guidance on this?


Solution

  • Good news! We actually do support Input/Output options that allow you to specify which fields you want, including nested fields. So, while you still need to make separate calls for each workspace, you can do something like this:

    workspaces = GET /workspaces
    for id in workspaces
      tasks = GET /workspaces/:id/tasks?assignee=me&opt_fields=name,due_on,projects.name
    

    (If you're only interested in incomplete tasks, you can add &completed_since=now - or if you want incomplete and recently completed tasks, &completed_since=... with the timestamp you want to exclude any tasks that were completed before)

    Additionally, 500 is not the code we send for rate limiting - it's likely an issue with the request itself. How are you requesting the project details?