Unable to update task in asana API using PHP

I am trying to update asana tasks through API using PHP curl, but I am unable to do it. Here is my code, could anyone please suggest me what’s wrong in my code?
Thank you!

$data = array(
    "data" => array(
        "workspace" => "XXXXXXXXXXXXXXXXXX",
        "projects" => array('XXXXXXXXXXXXXX'),
        "name" => "XXXX",
        "notes" => "XXXXXXX",
        "assignee" => "abcd@ef.com"
// Data should be passed as json format
$data_json = json_encode($data);
$url = 'https://app.asana.com/api/1.0/tasks/{task-id}';
// curl initiate
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data_json)));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_USERPWD, $api);
//curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute curl and assign returned data
$response  = curl_exec($ch);
// Close curl
// See response if data is posted successfully or any error


Hi @Priya1,

A couple of issues I see offhand:

  1. You can’t set Projects once a task is created; see Api Error "projects: Cannot write this property" for details.
  2. Assignee needs to be a GID of an Asana user, not an email address.

Also, when you post an API call that’s failing here in the forum, it’s always helpful to provide the error message that’s being returned.

@Phil_Seeman, assignee is not a problem here because it is working for creating task

Huh, I’m surprised at that but OK.

But trying to specify projects on an existing task will definitely return an error - per that other linked thread.

1 Like

Yes @Phil_Seeman, without specifying project id it’s working now
Thank you so much !!