简体   繁体   中英

Upload attachments using clickup api

I'm trying to upload the attachments to a task on clickup. Clickup API

Click up does provide example code the below is clickup example code

from urllib2 import Request, urlopen

values = """
attachment: raw_image_file (file)
filename: example.png (string)"""

headers = {
  'Authorization': '\'access_token\'',
  'Content-Type': 'multipart/form-data'
}
request = Request('https://private-anon-f799579c66-clickup20.apiary-mock.com/api/v2/task/{task_id}/attachment?custom_task_ids=&team_id=
', data=values, headers=headers)

response_body = urlopen(request).read()
print response_body

I used it as reference and used requests lib for the project

Here's the code using request lib


import requests

attachment_headers = {'Authorization': self.access_token, 'Content-Type': 'multipart/form-data'}
r = requests.post(f"https://private-anon-df9b125a00-clickup20.apiary-mock.com/api/v2/task/{task_id}/attachment", 
            files={"attachment": ("attachment", open("attachment.png", "rb")), "filename": "example.png"}, 
            headers=attachment_headers)
print(r)
print(r.json())

I do get the status code as 200 and no error message but when I check on clickup task it doesn't show any attachments

Thanks for the help in advance!

You must remove the 'filename' part of your files param.

file = {"attachment": ('choose_your_name.png', open('file.png', 'rb'))}
headers = {'Authorization': config.clickup_access_token}
request = requests.post(f'https://api.clickup.com/api/v2/task/{task_id}/attachment', files=file, headers=headers)
print(request.json())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM