I've been trying to use curl to send requests but I keep getting an error:
Error: "" - Code: 3 (The URL was not properly formatted.)
Here is my code that I have been using (after successful authentication and using my access token)
$name = 'test' . rand();
$notes = 'hello hello' . rand();
// Curl request to create asana task.
$url = 'https://app.asana.com/api/1.0/tasks';
$header = "Authorization: Bearer $token";
$curl = curl_init();
curl_setopt($curl, array(
CURLOPT_URL => $url,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
'notes' => $notes,
'name' => $name,
'projects' => 'xxxxxxxxxxxxxxx',
),
));
curl_setopt($curl, CURLOPT_HTTPHEADER, array($header));
$result = curl_exec($curl);
if(!curl_exec($curl)){
die('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
}
Where I got the project id from the id in the URL of the project.
Update: the equvilant command line curl command I took from https://asana.com/developers/api-reference/tasks and is below. Running this is in the command line worked.
curl -H "Authorization: Bearer tokenid123" https://app.asana.com/api/1.0/tasks -d "notes=test notes" -d "projects[0]=xxxxxxxxxxxxxxx" -d "name=test"