Rest API add attachments to comment

How add attachment to issues's comment wia Rest API?

I try this

encoderrrr =MultipartEncoder(fields={'file':('tets.jpg', open('./project/MAC/MAC-338/screenshot-1.png','rb'))})
auth_login,auth_password ='USER','PASSWORD'
headers = {
'Accept': 'application/json',
'Cache-Control': 'no-cache',
'Content-Type': encoderrrr.content_type}
r ='{}/attachments/{}'.format('MAC-1','4-400'),
data= encoderrrr,

And i get error

{"error":"Not Found","error_description":"Entity with id 4-400 not found"}

How I can send attachment to comment?


1 comment
Official comment

Hello, thank you for your message.

First of all, we have a step-by-step tutorial on how to attach files to issues, please feel free to check it here: The process of attaching files to comments is very similar.

As to your code snippets:

1) You need to use a permanent token instead of Basic Auth. Here you can learn more about token authorization for using our REST API:

2) The URL /issues/{issueID}/attachments/{attachID}  that you're using is for the files attached to an issue and not to a comment. If you need to attach files to comments, use this URL instead: /api/issues/{issueID}/comments/{commentID}/attachments

Note that here you don't need to paste the exact attachment ID at the end, but you do need to enter the comment ID. To get a comment ID, make a call to /api/issues/{issueID}/comments and identify the comment that you need to attach files to.


I hope this is helpful, please let me know if I can answer any further of your questions. 

Please sign in to leave a comment.