Change task's section - task belongs to multiple projects

Hi all,

I am having a bit of an issue and I hope someone can help me. I have tasks that belong to multiple projects, and I am running an API that allocates them to a specific section in one project, leaving the other projects’ membership unchanged.

I am running the API using:

{‘data’: {‘memberships’: [{‘section’: {‘gid’: ‘<gid>’, ‘name’: ‘<name>’}}, {‘section’: {‘gid’: ‘<gid>’, ‘name’: ‘<name>’}}]}}

….where gid and name refer to the sections’ GID and name in two projects in this example. I am passing this data as body to update_task

I am getting the following errors:

“message":“memberships: [0]: project: Missing required field” […] “message”:“memberships: [0]: section: Not a valid GID type: object”

(the same for [0] and [1] in this example.

What am I doing wrong?!? All the best.

Hi @Crescenzo_D_Alessand ,

To do that, do not “edit” the task, but add it to the desired section.

example:

POST /sections/(section gid)/addTask

{“data”:{“task”:“(task gid)”}}

Only the section of the specific project will change, the other section of another project will be kept unchanged in your task.

2 Likes

Awesome, thank you! That worked - based on your answer I also found: Add task to section

1 Like

Hi @Crescenzo_D_Alessand !

While @Frederic_Malenfant ‘s approach is the way to go, one nuance to keep in mind: the memberships property on a task isn’t writable via PUT. You can set memberships only at creation time (POST) to place the task into multiple project/section pairs, but not after the task is created.

If you were to include this property in a POST, you should just reference project/sections GIDs directly, no need to wrap them in objects:

POST https://app.asana.com/api/1.0/tasks
{
  "data": {
    "name": "My Task Name",
    "memberships": [
      {
        "section": "<section_gid_A>",
        "project": "<project_gid_A>"
      },
      {
        "section": "<section_gid_B>",
        "project": "<project_gid_B>"
      }
    ],
    "workspace": "<workspace_gid>",
    "notes": "Task notes"
  }
}
1 Like

Thank you @Mikhail_Melikhov - this explains something I observed. I came across this payload in another thread, I tried it and the command actually “succeeded” (no errors), but it didn’t actually update the task. Thank you!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.