Issue
I'm trying to create a python script to interact with an API for a system called Xibo. My problem is that I don't know python very well and the documentation for this system is what could generously be described as poor. Parts of their documentation use the format of the requests but their official API manual suggested the following curl command to update a media file on the system. I understand that requests are the best format to interact with APIs over and above curl so obviously I'd rather do it in requests if the general idea is that it's better.
curl -X POST "http://129.12.19.62/api/library" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "[email protected]" -F "name=47" -F "oldMediaId=47" -F "updateInLayouts=1" -F "deleteOldRevisions=1"
That is the command. Could anyone give me assistance by helping me translate it to the format of a request? I have tried using curl.trillworks but for some reason, it says that there was an "Error parsing curl command."
. I understand if this is not possible or if you need some more information, I'll do my best to provide what anyone needs to help me.
Thank you.
Solution
Try something like this:
import requests
entry_point = 'http://129.12.19.62/api/library'
headers = {
'Accept': 'application/json',
'Content-Type': 'multipart/form-data'
}
data = {
'files': '@47.htz',
'name': '47',
'oldMediaId': '47',
'updateInLayouts': '1',
'deleteOldRevisions': '1'
}
r = requests.post(entry_point, headers=headers, data=data)
Answered By - accdias Answer Checked By - Timothy Miller (WPSolving Admin)