Question

Unable to attach pdf to an existing ticket using REST API - Internal Server Error

  • 2 February 2023
  • 2 replies
  • 116 views

Badge

I am trying to attach a pdf to a service request using below Python code:

========================================================

import requests

import urllib.request

 

headers3 = {"Content-Disposition": "multipart/form-data", "Content-Type":"multipart/form-data", "Cookie":"JSESSIONID="+"C1FB8D0318D1F8851495124442C3226F.inst05us-autoscaleapp-001092"}

 

url = “https://company.sysaidit.com/api/v1/sr/attachment"

pdfurl=”https://xx.com/a.pdf”

pdfFile = urllib.request.urlopen(pdfurl, data=None, timeout=60)

file = {"file": pdfFile}

 

attachmentResponse = requests.post(url=attachmentUrl, files=file, headers=headers3)

print(attachmentResponse.text)

=========================================================

I gett below error:

HTTP Status - 500 – Internal Server Error


2 replies

Userlevel 5
Badge

Hi @abhatia

I am not python savvy but from a quick look I think you are missing the SR ID in the string. Nonetheless adding the full flow you need to follow in order to add an attachment via API with postman that you can review and see if you need to improve anything from your end. 

 

1) The URL in the API tool (e.g: Postman) should be for example:

https://accountID.sysaidit.com/api/v1/sr/123456/attachment

 (Replace accountID with the account ID, and 123456 with the SR number. )

2) In the Body, select the form-data radio button.

3) Under KEY, there is an option to select FILE. When you select that option, in the Type column, there is an option to select a file.

4) After the file (attachment) is uploaded from the computer, type file under KEY, and click Send to use the POST method and upload the attachment.

200 OK is displayed as confirmation.


Hope this helps!

 

Badge

Thanks a lot.

Reply