1

I am trying to add an attachment to the existing incident using BMC rest-api with python 3.6, For some reason it did not work for me, however I was able to add an attachment using Postman without any issues, but not thru this python code. Sometime I get Http 500 error and sometime Http 400 bad requests. Any one is aware what am I doing wrong? much appreciated. I have been stuck at this for few weeks now and no clue to move forward, unable to find any documentation from BMC, any direction much appreciated

Using python 3.6

import requests

url = "https://restapi/api/arsys/v1/entry/HPD:WorkLog"

payload = {
"entry": {
    "values": {
        "Incident Number": "INC000020972030",
        "z1D Action": "CREATE",
        "Work Log Type": "General Information",
        "View Access": "Internal",
        "Secure Work Log": "No",
        "Detailed Description": "Add your description",
        "z2AF Work Log01": "sample.txt"
    }
}}

files=[('attach-z2AF Work Log01'('sample.txt',open('/Users/Downloads/sample.txt','rb'),'text/plain'))]

headers = {
'Authorization': 'AR-JWT authentication token here',
'Content-Type' : 'multipart/form-data'
}

response = requests.request("POST", url, headers=headers, data=payload,files=files,verify=False)
print(response.text)
vas
  • 53
  • 2
  • 8
  • No, still facing the same issue, researching it. – vas Jan 24 '23 at 14:20
  • Postman doesn't send the attachment at all, if you chek the console, it sends undefined elements, check the code provided on my answer – ricardorios Jan 24 '23 at 22:36
  • Refer to https://stackoverflow.com/questions/75203863/php-remedy-api-call-to-create-an-entry-with-attachment-not-working-with-postman/75227562?noredirect=1#comment132748985_75227562 – ricardorios Jan 24 '23 at 23:42

1 Answers1

1

After long struggle I was able to add an attachment to the remedy incident, Thanks to this post: https://stackoverflow.com/a/35946962/8741275

Incase if any one looking for the answer here is the working version:

import requests
import json

url = "https://restapi.onbmc.com/api/arsys/v1/entry/HPD:WorkLog"

payload = {
         'values': { 
         'Incident Number': 'INC000020972030',
         'z1DAction':'CREATE',
         'Work Log Type': 'General Information', 
         'View Access':'Internal', 
         'Secure Work Log': 'No', 
         'Detailed Description': 'Add your description', 
         'z2AF Work Log01': 'sample.txt' 
         }}
 
files = {
          'entry': ('entry', json.dumps(payload), 'application/json'),
          'attach-z2AF Work Log01':('sample.txt',open('/Users/Downloads/sample.txt', 'rb'), 'application/octet-stream')
 }
 
 headers = {'Authorization' : 'AR-JWT authentication token here'}
 
 res = requests.post(url, files=files,headers=headers,verify=False)
 print(res.status_code)
vas
  • 53
  • 2
  • 8