I'm trying to upload a file with a python script and requests library to a cabinet.
So far I've managed to fetch the correct cabinet id and to create a new cabinet if it doesn't exist already.
But how do I upload a document (pdf) into that cabinet?
Does anyone have a codesnippet?
here's what I did so far - but with no success...
I always get status_code 400 with message
{"documents_pk_list":["This field is required."]}
Code: Select all
import requests
doctype = 2
baseurl = 'http://172.21.0.100:8000/api'
cred = ('admin', 'password')
demo_cabin_id = 5
fnam = 'AN1903-001.pdf'
payload = {'description': 'Test Dokument',
'document_type': doctype, 'label': fnam, 'language': 'Deutsch'}
files = {'file': open(fnam, 'rb')}
# Upload URL
url = f'{baseurl}/cabinets/{demo_cabin_id }/documents/'
r = requests.post(url, files=files, data=payload, auth=cred)
print(r.status_code)
print(r.text)
regards,
Bastian