Workflow that triggers a script/API call when a document is uploaded

Hi everyone,

I’d like to configure mayan so that documents, when uploaded, are automatically added to cabinets based on their OCR content. I was able to achieve this using workflows thanks to Roberto’s solution posted on this community site (thanks a lot!!).

Now, I’ve seen that due to the size of the folder structure I need to migrate, it will take too many workflows to get each document added to the right cabinet.

My question is whether it’s possible to set up a workflow that triggers an API/script call, in which I code the logic with which documents are added to each cabinet.

Thank you!

You will need to create a special user and set all it’s permissions …
https://docs.mayan-edms.com/chapters/permissions.html

… then you’ll need to get it’s api token. Now with both name and token you can interact with mayan via the rest api.
https://docs.mayan-edms.com/chapters/rest_api.html?highlight=api#sessions

I have for instance an api written in flask that receives a document id via a workflow for new files.
In a workflow state html action: in the URL box: http://127.0.0.1:5000/mayan_detect_language/{{document.id}}
Once my api receives the ID I can do some api calls to mayan to get to the real document, download it, detects its language and finally I change the document language and start the ocr process.

3 Likes