Create a Completed Task via API


#1

I’ve been successfully creating tasks via the API, and I’m following the docs for which parameters are accepted, but for some reason it does not like it when I set “completed” in my request.

The docs do not list it as a read-only parameter, and my request only fails when adding it. Thoughts?

Here is my request body (PHP):
array(
‘projects’ => array( $projectId ),
‘memberships’ => array(
array(
‘project’ => $projectId,
‘section’ => $section->id
)
),
‘name’ => $bcTodo[‘content’],
‘completed’ => true
)


#2

That is very weird, I also looked at the doc and their example, looks like you are doing the same… :thinking:
@Diakoptis any idea?

Bastien
Asana consultant, author and developer


#3

projects is a read-only field. Don’t use it when updating a task.

Pass the following data and I think that will be work fine.

array(
‘memberships’ => array(
array(
‘project’ => $projectId,
‘section’ => $section->id
)
),
‘name’ => $bcTodo[‘content’],
‘completed’ => true
)


#4

Hi @Diakoptis,

I’m not updating a task, I’m creating one. When I take out the ‘projects’ field I get an invalid request error as well, even when not setting the ‘completed’ field.

I did try the request format you suggested, but it still doesn’t like it :confused:


#5

Anyone else have ideas here?


#6

I’m not sure that you can use the create task endpoint and set the task completed without a second update request.

I will check it later today and I will let you know.


#7

Thanks, I would appreciate that!

I’m working on a Basecamp 3 - > Asana migration tool, so I’d like to mark tasks as completed in 1 request if possible.


#8

Hey @Josh_Niemeyer,

the following code worked like a charm. You can create a completed task.

$task = $client->tasks->create(array(‘projects’ => ‘PROJECT_ID’, ‘name’ => ‘test’, ‘completed’ => true));


#9

Hey @Diakoptis,

Thanks! I’ll give that a go as soon as I can. I’m in the process of refactoring a good portion of my code.

Overall, I think my request looks very similar to yours, but mine has the addition of setting the task memberships, as I need to be sure to organize the tasks into sections as they are created. Maybe it doesn’t like doing that at the same time and will require 2 requests?

I’ll update this thread with my results.


#10

Just create the tasks in the right order, and sections are just tasks with “:” at the end :wink:


#11

Ahh of course! I could give that a go, thanks @Bastien_Siebman!

That brings up another point, however. I wish Sections were a more official way to group tasks within a project, rather than being a task in and of itself. I have to say it’s one of those things that cause me frustration when working in Asana.


#12

@Josh_Niemeyer I think you may be getting your wish - this is from the API documentation:

Deprecation warning: At this time, sections in a list-layout project are manipulated as if they were tasks, i.e. reordering a section involves moving the section (and all of its tasks if they are to remain in that section) to a new location in a project. (see Task, Project, and Section Associations for more information). This method of manipulating sections as if they are tasks will soon be deprecated in favor of the methods described in the Sections resource.