Forum Discussion
Michael_Baker
4 years agoNeophyte
9 hours ago, Javier said:Hi again,
I prepared my script to programmatically create the XML file to define new EventSources. I test it successfully from the UI, using "Add" - "From File".
Now I would like to use the API to make such a call. According swagger documentation here, it looks like I need to provide this file as a parameter, but I don't have a clear idea on how to provide that. I tried several methods, but none of them worked so far:
- Adding a parameter named "file" to the URL. Something like: "https://XXXXXX.logicmonitor.com/santaba/rest/setting/eventsources/importxml?file=toimport.xml"
- Adding a JSON payload like: { "file": "toimport.xml" }
- Adding the XML content to the payload: { "file": "<?xml version="1.0" encoding="UTF-8" ?>......" }
Using any of these methods, I always get an error "HTTP 415 Unsupported Media Type".
What am I doing wrong?
Set the content type as multipart/form-data then send a file object as a local file read for python
header = {'Content-Type': 'multipart/form-data', 'Authorization': 'LMv1....'}
files = {'file': ('file.xml', open('file.xml', 'rb'),'text/xml')}
r = requests.post(url, headers=header, files=files, verify=False)
You would be much better using the SDK though
Related Content
- 2 years ago
- 2 years agoAnonymous
- 2 years agoAnonymous