Skip to content

Instantly share code, notes, and snippets.

@dougblackjr
Last active April 13, 2023 13:47
Show Gist options
  • Save dougblackjr/2be6c114e80223d0e7398c635b489819 to your computer and use it in GitHub Desktop.
Save dougblackjr/2be6c114e80223d0e7398c635b489819 to your computer and use it in GitHub Desktop.
Clickup File Attachment via API
$yourApiToken = 'your-api-token';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.clickup.com/api/v2/task/{task_id}/attachment?custom_task_ids=&team_id=");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
$filepath = '/path/to/file';
$file = curl_file_create($filepath, 'image/png', 'filename');
curl_setopt(
$ch,
CURLOPT_POSTFIELDS,
[
'attachment' => $file,
]
);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: {$yourApiToken}",
"Content-Type: multipart/form-data"
));
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
@DmitrySidorenkoShim
Copy link

4/ Test with this line $file = curl_file_create($file_path, $file_type, $file_name ); instead of your version, and note that this one includes the file type which in your case should be image/png if I am not mistaken

thank you
at least I have it working with curl right now

but maybe someone made it working with GuzzleHttp?
I am using:

        $data['multipart'] = [
            [
                'name'     => 'attachment',
                'contents' => Utils::tryFopen(storage_path('app/public/image.png'), 'r'),
            ]
        ];

and i tried fopen() and file_get_content() for 'contents'

but it always:
'{"err":"No attachment supplied","ECODE":"ATTCH_039"}'

I am using Guzzle for all other requests
so, please, let me know with an example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment