I am trying to add a due_on date during task creation with the Asana API and every time it spits out a server 500 error and a random, kinda humorous, message.. Here is an example of the api response when trying to add a task with a due_on or due_at value.
stdClass Object ( [errors] => Array ( [0] => stdClass Object ( [message] => Server Error [phrase] => 22 tough cobras kneel kindly ) ) )
Is there something going on with these date features? Maybe the 'YYYY-MM-DD' format I'm using (from the api docs) is not correct? When I remove this field I have no problems creating the task, that leaves me to believe the problem is only with the due_on and due_at fields. If i remove line 6 completely it will return a success.
Here is an example of the code that spits out the error:
$post_data = array(
'assignee' => $asana_user_id,
'notes' => $task_notes,
'followers[0]' => $asana_user_id,
'name' => 'Test Task',
'due_on' => '2015-09-03',
'workspace' => $workspaceID,
'projects' => $project_id
);
$curl = curl_init('https://app.asana.com/api/1.0/tasks');
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '.$asanaApiToken
));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
$response = curl_exec($curl); // execute post to asana
print_r($response);
Any help is appreciated, thanks in advanced
The random and kind of humorous error message you are getting is standard when server errors occur on the Asana API. It is meant to be a unique string that allows us to track down the exception that caused the 500.
I took a look at what seems to be causing this and I believe it has something to do with parsing the date from the multipart form fields specifically.
If you send the request with a different Content-Type
, either application/json
or application/x-www-form-urlencoded
then it should be fine.
Here is an example using application/json
:
$curl = curl_init('https://app.asana.com/api/1.0/tasks');
$data_string = json_encode(array(
"data" => array(
"workspace" => $workspace,
"name" => $name,
"assignee" => "me",
"due_on" => "2015-09-03")
)
);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '.$access_token,
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$response = curl_exec($curl);
print_r($response);