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);


I am also facing some dire difficulties in configuring the Asana API. While making CURL request it showing a huge list of errors.:frowning_face:

Hi @Kate_Jordan and welcome to the forum!

Are you having trouble specifically with uploading a file? That’s what this thread is about. If you’re having troubles with the API regarding anything other than a file upload, then please start a new thread here in the Developers & API section of the forum.

Also, please post the code of your CURL request and post the errors you’re getting in return. Those details will be needed in order to provide any further guidance. Thanks!

1 Like

I tried to upload a pdf and doc attachments from the postman and the attachment uploaded successfully. I tried to validate the data in the uploaded attachment and it’s empty