0

I'm having trouble attempting to read back a Task's Section property. The online API docs info on sections (api-reference/sections) state:

The ‘memberships’ property when getting a task will return the information for the section or the column under ‘section’ in the response.

When trying opt_fields request type, the json returned is empty either memberships:[{}] or memberships:[{},{}]

/projects//tasks?&opt_fields=name,notes,completed,completed_at,assignee,assignee_status,due_on,projects,modified_at,memberships"

When trying opt_expand request type, I don't see any json 'memberships' parts returned

"/projects//tasks?&opt_expand=memberships&opt_fields=name,notes,completed,completed_at,assignee,assignee_status,due_on,projects,modified_at"

Thanks in advance for any suggestions.

Community
  • 1
  • 1
Eduarte78
  • 1
  • 2

2 Answers2

0

If you query a task, the response will include memberships by default (you do not need to add an opt_field).

For example, when you request a task GET /tasks/task-id, the response will look like this:

{ "data": { "id": 123456789, "assignee": null, "assignee_status": "later", "completed": false, "completed_at": null, "created_at": "2017-04-03T19:03:43.840Z", "due_at": null, "due_on": "2017-10-09", "hearted": false, "hearts": [], "memberships": [ { "project": { "id": 123456789, "name": "Test Project" }, "section": { "id": 123456789, "name": "I'm a section:" } } ... } }

You can get the memberships of all tasks in a project by using opt_expand=membership in the request: GET /projects/project-id/tasks?opt_expand=membership.

The membership includes the task's project and section. If the task is not in a section, it will return "section":{null}.

You can also query for sections in a project: GET /projects/project-id/sections.

Note that sections are actually tasks (with a colon at the end of the name) in the Asana data model. Also note that the membership of a section will be itself, which is a little confusing.

Jeff
  • 456
  • 2
  • 5
  • 1
    Are you saying that 'memberships' info only gets returned when performing a **single task** GET? I was trying/hoping to obtain this info in the fetch of the collection of tasks in a project (hence the /projects/tasks? query). The Asana API tool seems to imply you can obtain this field in that case, hence my confusion with the entry returned but empty value. (Thanks for the response). – Eduarte78 Oct 18 '17 at 23:50
  • In addition to getting the membership for a single task, you can also get the memberships for all tasks returned from all tasks in a project: `GET /projects/project-id/tasks?opt_expand=membership`. – Jeff Oct 19 '17 at 19:04
  • I've updated my answer to include getting memberships for all tasks in a project. – Jeff Oct 19 '17 at 19:10
-1

If you want both sections and projects under "membership": /tasks?&opt_fields=memberships.(project|section)"

If you need only section name : /tasks?&opt_fields=memberships.section.name"

Source: https://forum.asana.com/t/get-all-project-tasks-with-their-section/15606