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)
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)