Last active
April 13, 2023 13:47
-
-
Save dougblackjr/2be6c114e80223d0e7398c635b489819 to your computer and use it in GitHub Desktop.
Clickup File Attachment via API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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); |
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 beimage/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
@rajnaviktor
It should not be possible in theory for something to work in postman and not when running from the code, if they are in fact the same, so something has to be up here. It's hard to debug this way, but as a shot in the dark
1/ Enable logging and check if any errors get recorded?
2/ Why is the file name in the path pngwing.com (1).png and then in the filename param it is test.png
3/ Test with a file that does not have a space nor special characters in the name, just to be safe.
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 beimage/png
if I am not mistaken5/ Remove the boundary=12121 from the header in case it is causing issues.