Add task to a section upon creation via API request

When you create a task currently, if you want to add it to a section, you need a second POST request. Is there a way to add a task to a section on creation, similarly to how you add it to a project? Sections have a globally unique GID, so it seems like it should be doable?

Thanks

Yes! Set the Memberships property on the task.

There are some subtleties involved in terms of the exact syntax and the language you’re using; here’s some info:

1 Like

That’s actually what I’m asking about avoiding. With the new Section implementation, the /sections/<section_gid>/addTask endpoint is exactly the same, however, I’d like to add the section when I post to the /tasks endpoint to create the task. We’re currently able to specify a project to add the task to, but what about a section?

1 Like

The Memberships property includes specifying the section.

From Build an app with Asana

**Create-only.** Array of projects this task is associated with and the section it is in. At task creation time, this array can be used to add the task to specific sections. After task creation, these associations can be modified using the addProject and removeProject endpoints. Note that over time, more types of memberships may be added to this property.

2 Likes

For clarity (and to link to this from another thread I’m about to respond to) this is what a request that both creates the task and sets the section memberships in the same request looks like:

POST /tasks
{
  "data": {
    "name": "My Task",
    "memberships": [
      {
        "project": 123,
        "section": 456,
      },
      {
        "project": 789,
        "section": 1011,
      }
    ]
  }
}
6 Likes

I have successfully created a task with Python and with Postman, however I cannot seem to grasp how to add the task to a Section through memberships in one POST, meaning add new task to project and section at the same time. Can you provide a Python url example? Or a Postman example? Thank you

Hi @Antonio_Felicetta and welcome to the forum!

Using Postman, have you tried the syntax that Joe illustrated just above? If that didn’t work for you, please post the contents of your request and let us know what error message was returned.