Add attachments to issue via API

Get help from other users here.

Moderators: Developer, Contributor

Post Reply
Posts: 3
Joined: 23 Jun 2020, 08:07

Add attachments to issue via API

Post by falexandre90650 »

Hi all !

I try to add attachments to an issue via API as explained in that website : ... 259c5706ef

I am using a Python script which follows :

Code: Select all

url_issue = "{{url_Mantis}}/api/rest/issues/{{id_Mantis_issue}}/notes"
payload = "{\n  \"files\": [\n  \t{\n  \t\t\"name\": \"test.pdf\",\n  \t\t\"content\": \"C:/Users/admin/Desktop/Doc7.pdf\"\n  \t}  \t\n  ]\n}"
headers = {
          'Authorization': "{{token}}",
          'Content-Type': 'application/json'
print(requests.request("POST", url_issue, headers=headers, data = payload)))
Positive Point : the attachment appears in my mantis issue. But when I click on it to see the attachment, there is an error. Google Chrome can't open the pdf.

So, I try to find the problem... and i think I found it !
When I go to this website


It is possible to have some data about the issue. And I saw that :

Code: Select all

          "content_type":"application\/octet-stream; charset=binary"}]
I think the problem comes from the content type (last line). It should be like this :

Code: Select all

          "content_type":"application\/pdf; charset=binary"}]
So, I change the payload like this :

Code: Select all

payload = "{\n  \"files\": [\n  \t{\n  \t\t\"name\": \"test.pdf\",\n  \t\t\"content\": \"C:/Users/afournel/Desktop/Doc7.pdf\",
                                    \n  \t\t\"content_type\":\"application\/pdf; charset=binary\"\n  \t}  \t\n  ]\n}"
With this kind of payload, the content type is still the same, and my file can't be opened. MantisBT can't understand my file is a pdf.

i would be very grateful for your help,

Post Reply