# Add attachment to a task with cURL

**URL:** <https://forum.asana.com/t/add-attachment-to-a-task-with-curl/148846>\
**Category:** API & Developers\
**Created:** [12 January 2022 07:11 UTC](https://forum.asana.com/t/add-attachment-to-a-task-with-curl/148846 "2022-01-12T07:11:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon61459744](https://luna1.co/8d76cd.png) [@anon61459744](https://forum.asana.com/u/anon61459744)\
**Post date:** [12 January 2022 07:11 UTC](https://forum.asana.com/t/add-attachment-to-a-task-with-curl/148846/1 "2022-01-12T07:11:57Z")

</div>

Hi there.

```auto
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?

---

<div class="post-metadata">

**Author:** ![anon61459744](https://luna1.co/8d76cd.png) [@anon61459744](https://forum.asana.com/u/anon61459744)\
**Post date:** [12 January 2022 09:41 UTC](https://forum.asana.com/t/add-attachment-to-a-task-with-curl/148846/2 "2022-01-12T09:41:24Z")

</div>

```auto
$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.

---

<div class="post-metadata">

**Author:** ![Bastien\_Siebman](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/bastien_siebman/32/172354_2.png) [@Bastien\_Siebman](https://forum.asana.com/u/Bastien_Siebman)\
**Post date:** [12 January 2022 15:29 UTC](https://forum.asana.com/t/add-attachment-to-a-task-with-curl/148846/3 "2022-01-12T15:29:56Z")

</div>

Hi,

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

---

<div class="post-metadata">

**Author:** ![anon61459744](https://luna1.co/8d76cd.png) [@anon61459744](https://forum.asana.com/u/anon61459744)\
**Post date:** [12 January 2022 16:37 UTC](https://forum.asana.com/t/add-attachment-to-a-task-with-curl/148846/4 "2022-01-12T16:37:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Bastien\_Siebman](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/bastien_siebman/32/172354_2.png) [@Bastien\_Siebman](https://forum.asana.com/u/Bastien_Siebman)\
**Post date:** [29 January 2022 09:54 UTC](https://forum.asana.com/t/add-attachment-to-a-task-with-curl/148846/5 "2022-01-29T09:54:09Z")

</div>

There is a discussion here as well [Upload attachment with CURL - #8 by Bastien\_Siebman](https://forum.asana.com/t/upload-attachment-with-curl/143429/8)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/system/32/276370_2.png) [@system](https://forum.asana.com/u/system)\
**Post date:** [30 May 2025 19:04 UTC](https://forum.asana.com/t/add-attachment-to-a-task-with-curl/148846/6 "2025-05-30T19:04:42Z")

</div>

Closed on 30 May 2025 19:04 UTC


