API php attachment



Hi there,

I tried to upload a file using Asana API in two ways:

  • php-asana library (example file)
  • making CURL request

and in both cases have received an error message: “file: File is not an object”.

Can you help me identify the problem?

Many Thanks!


Hey @Artem,

Thanks for reaching out. In order for us to reproduce and troubleshoot the issue, can you please share your code and the response you’re getting.


Hi Jeff,

here it is:

It throws “file: File is not an object” on $client->attachments->createOnTask(…)

BTW I found the reason: this example doesn’t work with PHP 7.0+ because of CURL ( CURLOPT_POSTFIELDS should not contain @ - see https://binfalse.de/2016/06/21/forget-the-at-use-curl-file-create/)

So, the next code works:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.asana.com/api/1.0/tasks/' . $taskId . '/attachments');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer ' . $apiToken]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, ['file' => new \CURLFile($pathToFile, $fileType, $fileName)]);
$data = curl_exec($ch);