Get all project tasks with their section

Hi!

I am struggling with something rather basic. I need to get all the tasks for a project, and for each task I need the section it is in. In the documentation it says the information is inside memberships so I asked for this field in opt_fields which does provide the field, but it keeps coming as an empty array. Am I missing something?
The weirdest part is that I manage to get this information using some functions from the PHP library but not some others…

Thanks a lot
cc @Diakoptis the API big boss :stuck_out_tongue:

2 Likes

Haha. hey bastien.

Try this

https://app.asana.com/api/1.0/projects/{projectID}/tasks?opt_fields=memberships.(project|section).name&opt_pretty

Check also Special operators

5 Likes

@Diakoptis you are definitely the best.

'opt_fields' => 'name,notes,due_on,completed,html_notes,memberships.section.name',

5 Likes

Naaaaaah! :blush::blush::blush:

I would like to have the title of the column in the table view. How can I do that with opt_fields ?
And maybe it is with something else ?

Thanks !

https://app.asana.com/api/1.0/projects/{projectID}/sections?opt_pretty

Do you need something like that? I am not sure that I understood the question.

1 Like

Yes thank you !
But I want the sections and the tasks together ? I have these 2 URLs but I want just one request:

https://app.asana.com/api/1.0/projects/{projectID}/tasks?opt_fields=name,due_on,completed,assignee

https://app.asana.com/api/1.0/projects/{projectID}/sections?opt_pretty

Do you have any idea ?

Thanks

1 Like

Hey @Pauline,

you can use this https://app.asana.com/api/1.0/projects/{projectID}/tasks?opt_fields=name,due_on,completed,assignee,memberships.(section|project).name&opt_pretty

you will need to loop through the tasks, get the memberships, loop in the memberships for the project.id to be equal to the project.id of your request and get the section name. This just in the case that a task is multi-homed in more than one project.

If you are sure that the tasks are not multi-homed you can just use

https://app.asana.com/api/1.0/projects/{projectID}/tasks?opt_fields=name,due_on,completed,assignee,memberships.section.name&opt_pretty

That makes sense?

1 Like

It is exactly what I wanted !

Thank you very much :slight_smile:

1 Like

Glad I helped :slight_smile:

That is awesome!