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

Anything concerning integration via the REST API
Post Reply
jnl29
Posts: 2
Joined: Wed Sep 18, 2019 7:07 pm

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

Post by jnl29 » Wed Sep 18, 2019 8:39 pm

Hello! :D

My team and I are testing Mayan Version 3.2.7 to use as our core document repository. Our goal is to upload, convert, and maintain versions for several million documents, specifically pdf. Most of the controls will be driven by Mayans Workflow and APIs. I have successfully been able to upload a new document, download a document, list all versions, and add a comment using the API calls from Python Request 2.21.0. My problem is when I try uploading a new version of a specific document. I am using the POST API call from Python Request to add a new version of the document in Mayan.

Code:

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'})
Error Message:

Code: Select all

requests.exceptions.HTTPError: 400 Client Error: Bad Request for url 
Is there something missing from my API call?

Thanks,
Jess

User avatar
rosarior
Posts: 387
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: 387
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: 387
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

jnl29
Posts: 2
Joined: Wed Sep 18, 2019 7:07 pm

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

Post by jnl29 » Mon Sep 23, 2019 8:40 pm

Thank you ! Changing json= to data= allowed me to upload a new version. :mrgreen:

Post Reply