Api Error "projects: Cannot write this property"

Good afternoon. I have a problem with Upgrade Task. When trying to update the task gives an error
{
“errors”: [
{
“message”: “projects: Cannot write this property”,
“help”: “For more information on API status codes and how to handle them, read the docs on errors: https://asana.com/developers/documentation/getting-started/errors
}
]
}

I use postman.

request data
{
“data”: {

"completed": "false",
"projects": [
    "1166631470245641"
],
"name": "Review Task2",
"notes": "Please review this task for where the process failed.",
"workspace": "1166632925114028"

}
}

My curl request

curl --location --request PUT ‘https://app.asana.com/api/1.0/tasks/1166956443113613
–header ‘Content-Type: application/json’
–header ‘Accept: application/json’
–header ‘Authorization: Bearer { token }’
–data-raw '{
“data”: {

"completed": "false",
"projects": [
    "1166631470245641"
],
"name": "Review Task2",
"notes": "Please review this task for where the process failed.",
"workspace": "1166632925114028"

}
}’

Hi @Artush_Ghazaryan and welcome to the forum,

Per the API documentation for the projects field in a task:

Create-only. Array of projects this task is associated with. At task creation time, this array can be used to add the task to many projects at once. After task creation, these associations can be modified using the addProject and removeProject endpoints.

In other words, you can only write to that field when creating a new task. After a task is created, you need to use the addProject endpoint to add a project to a task.

1 Like

@Phil_Seeman is right, but let me add this.

Since task are now always in a section (before, it was possible to be in a project without section), we changed our methods and we only use addSection instead of addProject.

https://developers.asana.com/docs/#add-task-to-section

If the task is already in the project of the section, it move from previous section to the new one.
If your task is not in the project of the section, it is automatically added to the selected project at the same time.
If you use addProject without specifying any section, the task will be added to the first section of the project.

So, if you use addProject, 1 section is added (the first one)
If you use addSection, the project is added.

2 Likes

Excellent point, @Frederic_Malenfant!

1 Like