REST API Upload document to a cabinet

Anything concerning integration via the REST API
Post Reply
EdVonSchleck
Posts: 6
Joined: Tue Sep 17, 2019 7:33 am

REST API Upload document to a cabinet

Post 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

res=this.Session.post(this.Url+"/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 "http://127.0.0.1:8000/api/cabinets/11/documents/" -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,
Ed

User avatar
rosarior
Developer
Developer
Posts: 505
Joined: Tue Aug 21, 2018 3:28 am
Location: Puerto Rico
Contact:

Re: REST API Upload document to a cabinet

Post 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
2020-02-12_22-52.png (44.66 KiB) Viewed 350 times
2020-02-12_22-52_1.png
2020-02-12_22-52_1.png (87.98 KiB) Viewed 350 times

EdVonSchleck
Posts: 6
Joined: Tue Sep 17, 2019 7:33 am

Re: REST API Upload document to a cabinet

Post 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:
res=requests.post(self.baseUrl+'/api/documents/',auth=(self.user,self.passwd),files={'file':f},data={'document_type':1})
docId=res.json()['id']
The document id is valid and the document exists in Mayan.

Then I do:
res=requests.post(self.baseUrl+'/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?

EdVonSchleck
Posts: 6
Joined: Tue Sep 17, 2019 7:33 am

Re: REST API Upload document to a cabinet

Post by EdVonSchleck »

Is there a way to have a detailed debug log for API calls?
I have no idea how to fix my issue.

Post Reply