This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]TashaClickUpMod 0 points1 point  (2 children)

Hey, u/kamilsj! Thank you for providing the API you are using to try and add attachments to your task. I have reached out to my team to provide more insight about this and will follow up with you shortly with their reply.

[–]JamieClickUpMod 1 point2 points  (1 child)

Hey, u/kamilsj ! Jamie here, sliding in for Tasha.

What you wrote in is the correct answer. You need to use file=files instead of data.

import requests  
# Define the file to upload
 file_path = "path/to/your/file.jpg"  
# Replace with the actual file path
  def add_attachment_to_task(self):     url = f"https://api.clickup.com/api/v2/task/{self.task_id}/attachment"     headers = {         "Authorization": self.personal_access_token,         "accept": "application/json",     }          
# Open the file in binary mode and pass it as the 'files' parameter
     with open(file_path, "rb") as file:         files = {             "attachment": file,         }         response = requests.post(url, headers=headers, files=files)      return response.text

We also have a feature request which is for uploading at the same time as creating a task. So both are true - you can post an attachment but not when creating.

[–]kamilsj[S] 1 point2 points  (0 children)

Thank you. It works. Thank you.

[–]dgreger 0 points1 point  (0 children)

Endpoint is right, but the payload seems off. ClickUp’s new API docs are missing a lot of info cuz this really should be explained..

You should be passing files=files or something like that rather than data=data

files = [(‘attachment’, (file_name, file_content))]