0

Experiencing difficulty trying to successfully add an attachment to a task using cURL/PHP.

$data = array("file" => "@$filename");
$headers = array("Authorization: Basic " . base64_encode($asana_api_key) . ":"));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://app.asana.com/api/1.0/tasks/$task_id/attachments");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_exec($ch);

Assume $filename, $asana_api_key, and $task_id are set properly. Should be fairly straightforward... but for some unknown reason I get the following response:

{"errors":[{"message":"Server Error","phrase":"19 snobby warthogs cheer busily"}]}

Oddly enough, running this request using curl command line works perfectly. I've tinkered with this for hours now to no avail.

Any ideas as to what the issue may be?

René Höhle
  • 26,716
  • 22
  • 73
  • 82
  • It seems this happens in situations where the filename being passed contains slashes, which is pretty annoying. I'm looking into it now, shouldn't be hard to fix. – agnoster Aug 20 '13 at 00:31

1 Answers1

0

This was a bug on our end, and should now be fixed. It had to do with the way curl was sending the filename, namely, as the entire path to the file. Browsers typically send only the basename (without the directory). We now apply the same logic ourselves if we get a full path for our local name, and it seems like it works, but your case may be different.

I'd certainly appreciate knowing if it works for you now.

agnoster
  • 3,744
  • 2
  • 21
  • 29