Problem with /api/documents/{id}/versions/

Anything concerning integration via the REST API
Post Reply
User avatar
rosarior
Posts: 440
Joined: Tue Aug 21, 2018 3:28 am

Re: Problem with /api/documents/{id}/versions/

Post by rosarior » Sat Sep 21, 2019 5:15 pm

Thanks for the report. The issue has been added to the queue to diagnose and fix.

User avatar
rosarior
Posts: 440
Joined: Tue Aug 21, 2018 3:28 am

Re: Problem with /api/documents/{id}/versions/

Post by rosarior » Mon Sep 23, 2019 1:04 am

I was unable to replicate the error. The API worked as expected.

Here are some issues with your code sample:

Code: Select all

with open(pdf, mode='rb') as file_object: 
    requests.post('*/api/documents/{id}/versions/',auth=('admin','password'),files={'file':file_object},json={'comment':'new-upload'})
the URL must be in the form: "http://<your IP address>/api/documents/<actual ID of the document>/versions/"

Example:

If you have a Mayan install at 192.168.1.1 that contains a document with an ID of 5 the URL would be:

"http://192.168.1.1/api/documents/5/versions/"

The other issue is that the json argument is for requests that return data, to send data use the 'data' argument like so:

Code: Select all

with open(pdf, mode='rb') as file_object: 
    requests.post('http://192.168.1.1/api/documents/5/versions/', auth=('admin', 'password'), files={'file': file_object}, data={'comment': 'new upload'})
Give this a try and let us know it works or there are other issues. Thanks!

User avatar
rosarior
Posts: 440
Joined: Tue Aug 21, 2018 3:28 am

Re: Problem with /api/documents/{id}/versions/

Post by rosarior » Mon Sep 23, 2019 1:05 am

Here is the documentation chapter covering API usage with additional examples: https://docs.mayan-edms.com/topics/integration.html

lcerliani
Posts: 1
Joined: Thu Nov 14, 2019 7:55 pm

Re: Problem with /api/documents/{id}/versions/

Post by lcerliani » Thu Nov 14, 2019 8:03 pm

Hi! I'm trying to do the same thing and I'm having problems with the

Code: Select all

files={'file': file_object}
part. Can you bring me an example of the file_object value?

Thanks!
Lucas.

Post Reply