Page 1 of 1

REST API Upload document to a cabinet

Posted: Mon Jan 27, 2020 12:35 pm
by EdVonSchleck
Sorry to ask again, this time as a new thread.
Maybe this time this question gets some attention.

I am trying to migrate a few thousend documents from another DMS to Mayan using the API.
All documents have tags and are organized in folders and sub-folders. The requirement ist to resemble the fodler structure in Mayan.
Luckily, there are cabinets. I can add cabinets to form a hierarchy.
However, I on my part had no luck so far getting documents in any of the cabinets.

I tried python:

Code: Select all"/cabinets/"+str(parentId)+"/documents/",data={"documents_pk_list":str(docId)}).json()
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,

Re: REST API Upload document to a cabinet

Posted: Thu Feb 13, 2020 2:55 am
by rosarior
I just tried it our and works as expected with version 3.3.12.

The result code should be 201.

it could be a permission issue, try it out on the UI with the same API user to validate it is correctly setup. The "Add documents to cabinets" permission must be granted for the cabinet and the document/document type.
2020-02-12_22-52.png (44.66 KiB) Viewed 2890 times
2020-02-12_22-52_1.png (87.98 KiB) Viewed 2890 times

Re: REST API Upload document to a cabinet

Posted: Fri Mar 06, 2020 1:38 pm
by EdVonSchleck
Thank you for your post. Sorry for the late reply. I have not had time to check your comments.

I checked the permissions of the import user. Just to recap what I did:
I created a role "importer" and added permission to add, see, and manipulate cabinets, to add/remove documents to cabinets.
I created a group "gImporter" and added the role "Importer" to it.
I created a user "import" and added the group "gImporter" to it.
I can login with user and manually create cabinet and add also add a document to it.
What exactly do you mean by permission for the docuemnt/document type? The type I am using is 'Default'.

Using the API I do in python:'/api/documents/',auth=(self.user,self.passwd),files={'file':f},data={'document_type':1})
The document id is valid and the document exists in Mayan.

Then I do:'/api/cabinets/'+str(cabId)+'/documents/',auth=(self.user,self.passwd),data={'documents_pk_list':str(docId)})
I get the HTTP result 201 and the doc id in the response, so all seems to be fine on the API side.
However, the doc is not added to the cabinet.
Did you check on your side with uploading a real document and checking in the UI that the document is there?

Re: REST API Upload document to a cabinet

Posted: Mon Mar 23, 2020 9:43 am
by EdVonSchleck
Is there a way to have a detailed debug log for API calls?
I have no idea how to fix my issue.