I want get ONLY the task that either have a parent or have a subtask (either way possible). Is there a way that I can get this using Asana API with Python?

I want to get ONLY the task that either has a parent or has a subtask (either way possible). Is there a way that I can get this using Asana API with Python?
Please help. This is a bit urgent

@Shiva_Kalyan,

Welcome to our developer forums. I think the endpoint you are probably looking for is our Search tasks in a workspace endpoint.

I don’t think we have a way to filter for tasks with non-null parent property or tasks that have subtasks. If you want to do either of these, you’ll have to do the filtering on your side after fetching all the tasks.

We do have a way to filter for tasks in a workspace that is a subtask though. I am not sure if it would be helpful but below would be how you would do this.

Using our Python v3.2.2 client library:

import asana
from pprint import pprint

client = asana.Client.access_token("<YOUR_ASANA_PERSONAL_ACCESS_TOKEN>")

workspace_gid = "<YOUR_WORKSPACE_GID>"
params = {
    "is_subtask": True
}
result = client.tasks.search_tasks_for_workspace(workspace_gid, params)
pprint(list(result))

2 Likes