REST api for multiple cabinets creation

Anything concerning integration via the REST API
Post Reply
bkader
Posts: 1
Joined: Thu Jul 18, 2019 7:51 am

REST api for multiple cabinets creation

Post by bkader »

Hi,
Thank you for this great tool.
I'm testing mayan-edms and would like to use it to manage our document system which contains hundreds of cabinets/documents.
So, when I tried to create multiple cabinets with one script, using the following json REST api:

Code: Select all

   [
        {
            "id": 1,
            "label": "CABINET1",
            "parent": null
        },
        {
            "id": 2,
            "label": "CABINET21",
            "parent": 1
        }
    ]
I encountered this system error reported below. Is to possible possible to create multiple (tree) cabinets with REST api "batch" script? Could you please show the right syntaxe.
Many thanks.
Ben
Create
Server error
There's been an error. It's been reported to the site administrators via e-mail and should be fixed shortly. Thanks for your patience.


mayan.apps.common.middleware.error_logging <1423> [ERROR] "process_exception() line 18 Exception caught by request middleware; <WSGIRequest: POST '/api/cabinets/'>, 'list' object has no attribute 'copy'"
Traceback (most recent call last):
File "/opt/mayan-edms/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/mayan-edms/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/opt/mayan-edms/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/opt/mayan-edms/lib/python2.7/site-packages/rest_framework/views.py", line 494, in dispatch
response = self.handle_exception(exc)
File "/opt/mayan-edms/lib/python2.7/site-packages/rest_framework/views.py", line 454, in handle_exception
self.raise_uncaught_exception(exc)
File "/opt/mayan-edms/lib/python2.7/site-packages/rest_framework/views.py", line 491, in dispatch
response = handler(request, *args, **kwargs)
File "/opt/mayan-edms/lib/python2.7/site-packages/rest_framework/generics.py", line 244, in post
return self.create(request, *args, **kwargs)
File "/opt/mayan-edms/lib/python2.7/site-packages/rest_framework/mixins.py", line 20, in create
serializer.is_valid(raise_exception=True)
File "/opt/mayan-edms/lib/python2.7/site-packages/rest_framework/serializers.py", line 236, in is_valid
self._validated_data = self.run_validation(self.initial_data)
File "/opt/mayan-edms/lib/python2.7/site-packages/mayan/apps/cabinets/serializers.py", line 117, in run_validation
result = data.copy()
AttributeError: 'list' object has no attribute 'copy'

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

Re: REST api for multiple cabinets creation

Post by rosarior »

The error is caused by passing a list to a code that expects a JSON object. That API endpoint is only able to create a single cabinet per request. Also don't assign an ID to the object to be created, the database will assign an ID and return it to you in a 200 response. To create multiple cabinets, loop your code to create a single cabinet per iteration and it should be fine.

Post Reply