Create task under section in a project

Hi there.

I have a form that when submitting it will create a task in a project in Asana.
I want this to be able to create the task under the section “billing” in the project called “work”.

Right now I create a task doing it like this:

curl_setopt_array($curl, array(
CURLOPT_URL => ‘https://app.asana.com/api/1.0/tasks’,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => ‘’,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => ‘POST’,
CURLOPT_POSTFIELDS => array(‘name’ => $orderNumber . ’ - ’ . $clientName . ’ - ’ . $clientId, ‘projects’ => ‘1202451678035938’, ‘notes’ => ‘’ . $manus . ‘’, ‘assignee’ => ‘1198834232038500’,),
CURLOPT_HTTPHEADER => array(
',
'

),

    ));

How do I get this task to be created in that project, but under a specific section ?
I have different options in my form that should make this be put under the correct section in the project.

@Joakim_Paulsen1,

I think you need to look at https://developers.asana.com/docs/sections and consider using Get sections in a project and Add task to section.

Larry

3 Likes

Thanks Larry.
That works like a charm

1 Like

As @lpb said, you can add your task to a section after creating it, using 2 separate calls.

You can also add it directly to the section in 1 single POST, by using the “memberships” property.

POST https://app.asana.com/api/1.1/tasks
{"data":{
"name":"création tâche dans section",
 "projects":["269451171754166"],
 "memberships":[
  {"project":"269451171754166","section":"1143617431313814"}
 ]
}}

I think you need to repeat the project in “memberships” AND in projects array.

Note that you can’t update a task using the memberships property, but you can create it with it.

2 Likes