API Document upload example

Anything concerning integration via the REST API
Post Reply
Posts: 17
Joined: Tue Dec 04, 2018 6:18 pm

API Document upload example

Post by Bastian »

Hi @all

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

Any help is greatly appreciated


Posts: 17
Joined: Tue Dec 04, 2018 6:18 pm

Re: API Document upload example

Post by Bastian »


I've got the file uploaded.

I used the wrong base url
it needs to be uploaded to /api/documents

than it works.

Now I need to add the uploaded document to a cabinet.

We will see...
Posts: 6
Joined: Tue Sep 17, 2019 7:33 am

Re: API Document upload example

Post by EdVonSchleck »

Hi Bastian,

did you get the last step to work - adding a document to a cabinet?

I on my part had no luck so far. I tried python:

Code: Select all

where parentId is a valid id of a cabinet and docId is the id returned when adding it to mayan.
However, the function returns ok but no document is added

Alternatively, I tried curl:

Code: Select all

curl -u admin:pass -X POST "" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"documents_pk_list\":\"116\"}"
No response but also no document in the cabinet.

Any hints?

Thank you,
Post Reply