How to Retrieve Tasks without Projects API

I was originally pulling what I thought to be all tasks using the task API with a project gid specified. However, I have found several sub-tasks that do not have a project and therefor were not returned by the API.

I then tried to use the get tasks API specifying a workplace gid and assignee.any = null and the API returned the follow error message "“Must specify exactly one of project, tag, section, user task list, or assignee + workspace”

If I specify one assignee, then I will be missing unassigned tasks.

Why would a sub-task not be assigned to the same project as the task?

Is there another way of doing this?

Please read this before posting

  • If you received an error from the API that you’re looking for help with, please include the error in your post and be descriptive of the requests you made that received the errors. To be clear, we need the error in the JSON response from the API, not the error your code raised.
  • Do not share any API credentials. Please check that the code you’re pasting into the post does not contain any real OAuth tokens or personal access tokens. If you have exposed credentials, you should revoke them immediately.

This sub-task is also missing when I connect using the Power Bi Asana connector.

@AndreaM - subtasks are not associated with projects, but rather their parent task (which is, in turn, associated with the project). There are a number of forum topics on that, esp. in non-dev contexts, e.g.:

What specifically are you trying to get? All tasks/subtasks in your workspace, in a specific project, or something else? There are a few approaches depending on what you’re trying to do:

  1. You can use the endpoint you already tried (get multiple tasks) but include assignee=null to also get unassigned tasks.
  2. You could use the search API to return tasks by criteria
  3. You could iterate over one/more projects, call the get tasks for project endpoint and then iterate over the returned tasks to also grab any subtasks
1 Like

Thank you Stephen_Li for your quick reply. This particular sub-task is also not returned by the Power Bi connector but others are.

I tried using getting all the tasks using workspace gid and assignee=null but I got the error message I posted earlier saying I needed to specify an assignee.

@AndreaM - I don’t use PowerBI so can’t speak to that part (although it is odd that some subtasks are captured and others not…have you multi-homed any of your subtasks to specific projects?).

Could you post a code snip and the returned error? I think searching for null assignees should give you all the unassigned tasks (you’ll have to handle pagination if you use the search API, the other solutions handle pagination automatically if you’re using one of the client libraries)

When I do this
https://app.asana.com/api/1.0/tasks?assignee.any=null&workspace=123

I get this error

{
“errors”: [
{
“message”: “Must specify exactly one of project, tag, section, user task list, or assignee + workspace”,
“help”: “For more information on API status codes and how to handle them, read the docs on errors: Errors
}
]
}

When I do this
https://app.asana.com/api/1.0/tasks?assignee=null&workspace=123

I get this

{
“errors”: [
{
“message”: “assignee: Object cannot be null”,
“help”: “For more information on API status codes and how to handle them, read the docs on errors: Errors
}
]
}

I thought the workspace method might work, but now I am not sure I will know how to handle the pagination.

I am not the end-user so I don’t know really what multi-homing means but I think they do share the tasks across projects or at least use a template that is shared across projects to create the tasks

@AndreaM - tested and have the same issues, so that seems like maybe a documentation error? Hopefully someone else (Asana devs and partners monitor this channel and know a ton) can offer insight on that.

Are you using one of the client libraries? If so, it handles pagination for you so option #3 above might be easiest for you. If you choose the search route, I think the recommendation is to sort by created date (or something like that) and then use that for de facto pagination (it’s clarified in the documentation I linked).

Thank you @Stephen_Li while I wish I was just doing something wrong so that solution would work it’s nice to know that it isn’t possible.

I am not sure I know what you mean by client libraries, I am calling the API from within Azure Data Factory.

While I love the idea of using the Get Multiple Tasks workspace search, I think you are right I wouldn’t know how to do the pagination without getting passed the offset like the other calls do. I think you are right, option 3 is probably the easiest.

It would be a lot easier if a sub-task was associated with a project and I could get everything in one step because iterating through each of the tasks to get the sub-tasks will be slow and painful.