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!
<?php
$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}';
$api = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
// 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($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
//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
curl_close($ch);
// See response if data is posted successfully or any error
var_dump($response);
?>