How can i get info about parent task in python code?

I couldn’t find the answer I needed in the documetation. I have in my code opt fields like this opt_fields=[“”,“”,“”,“memberships.project”,“name”,“permalink_url”].
So first of all i get project’s name, section’s name, then i get parent’s name. Can i get parent’s info? I need section and project.
Do I understand correctly or not: In my opt fields I get info about task or sub-task? If I get task’s name then I can get only parent’s name and nothing else?
At actually i want something like that:

  1. project’s name of task
  2. section’s name of task
  3. if i have parent task i want get parent task’s name
  4. project’s name of parent task
  5. finally section’s name of parent task.
    I will be very grateful if you can help me!

Hi @Aaoam , welcome to the forum!

You are very near the information you need.

Because a subtask and its parent are both tasks, you only need to query the same fields for the parent, as you can do for the subtasks when you query the parents.

/tasks/xyz (xyz IS a subtask)
opt_fields: “name, memberships.project, memberships.section,, parent.memberships.project, parent.memberships.section”

Subtasks can be 5 levels deep, so they can have their own memberships, + multi-level parent memberships. And each level can be member of 0, 1 or many projects.

Now, what are you querying? Usually, you request tasks, and their subtasks. And, if you know the parent task, you don’t need to query the parent memberships of subtasks, because you already know them from its parent.

Except, if you assign that subtask to a a user, tag or project directly. Then you can see that subtask in the results of a project or user or tag query, like /projets/xyz/tasks. In that case, I understand that you may need to query more informations about its parent.

p.s. I was curious, so I tried with a 5-level deep subtask I have in my account… and it works, we can query 5 level parent in one call!
using that opt_field config:

But I don’t suggest to use that in a real application.

1 Like