Add attachment to a task with cURL

Hi there.

curl_setopt_array($curl, array(
                        CURLOPT_URL => 'https://app.asana.com/api/1.0/tasks',
                        CURLOPT_RETURNTRANSFER => true,
                        CURLOPT_ENCODING => '',
                        CURLOPT_MAXREDIRS => 10,
                        CURLOPT_TIMEOUT => 0,
                        CURLOPT_FOLLOWLOCATION => true,
                        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                        CURLOPT_CUSTOMREQUEST => 'POST',
                        CURLOPT_POSTFIELDS => array('name' => '' . $adname . '', 'projects' => '1201177956477737', 'notes' => '' . $main_brief . '', 'assignee' => '1199508896039720', 'custom_fields' => '{"1198721486672892" : "' . $name . '", "1137109783273489" : "' . $orderNumber . '"}'),
                        CURLOPT_HTTPHEADER => array(
                            'Authorization: Bearer 1/************',
                            'Cookie: TooBusyRedirectCount=0; TooBusyRedirectCount=0; logged_out_uuid=54a01a0dd7857620640436eb9ab6e4e0'
                        ),
));

I am trying to add attachments to this Asana task. But I have no idea how to do it.
Tried to read the documentation, but I can’t say that it explained it good enough. I have now tried for over 2 months to get this going, but still I can’t get an attachment to show up in the task.

I am using a upload field in my form where I can upload severeal images / documents and I need this to get into Asana. Right now I am uploading images to an FTP so that people receive them, but getting them into Asana would be much better and lighten the workload.

Anyone that has any suggestion on how I can do this?

$curl = curl_init();
 curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://app.asana.com/api/1.0/tasks/' . $taskGid . '/attachments',
        CURLOPT_RETURNTRANSFER => true,
         CURLOPT_ENCODING => '',
          CURLOPT_MAXREDIRS => 10,
          CURLOPT_TIMEOUT => 0,
          CURLOPT_FOLLOWLOCATION => true,
          CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
          CURLOPT_CUSTOMREQUEST => 'POST',
          CURLOPT_POSTFIELDS => array('file' =>  base64_encode($tmpFilePath), 'name' => $newFilePath),
          CURLOPT_HTTPHEADER => array(
                                        'Authorization: Bearer 1/*****',
                                        'Cookie: TooBusyRedirectCount=0; TooBusyRedirectCount=0; logged_out_uuid=54a01a0dd7857620640436eb9ab6e4e0'
                                    ),

));

This is my call to upload an attachment.
I have tried without base64_encode and with it.

$tmpFilePath fetched $_FILES[‘file’][‘tmp_name’][$j] from a loop and $newFilPath fetches $_FILES[‘file’][‘name’][$j] from the same loop.

Nothing happends.

Hi,

Adding attachment with cURL has been discussed in multiple threads, did you try to have a look?

I have tried several of them. This is the first time I try CURL so I am not vert experienced with it.
What I have from postman is what I posted up here but I do not get any errors or any attachments to the task.

There is a discussion here as well Upload attachment with CURL - #8 by Bastien_Siebman