Inserting multiple entity records to database through API

Hi,

POST /entities/{entityName}
Create new entity
Entity created. The created entity is returned in the response body.

ModelExample Value
{
“id”: “4d8ef1d4-90b6-c075-8bfd-79181ff889ef”,
“_entityName”: “sec$User”,
“_instanceName”: “Smith [smith]”,
“otherEntityFields”: “There must be a set of entity fields instead of this one here”
}

How do we create multiple records at the same time?
I am trying something like this
API : http://localhost:8080/app/rest/v2/entities/saas$FieldReportDetails
[
{
“taskUserId”: {“id”:“398c93fe-921f-9a26-5dbb-afb4b2fe4093”},
“taskUserName”: “shanur”
},
{
“taskUserId”: {“id”:“398c93fe-921f-9a26-5dbb-afb4b2fe4092”},
“taskUserName”: “sameer”
}
]
and I am getting error as below
{
“error”: “Cannot deserialize an entity from JSON”,
“details”: “”
}

Hi,
multiple entities insert is not supported by the standard API. We have an issue for that but is not scheduled for any release yet.
As a workaround, you may write your custom controller and pass the JSON array into it. In the controller method just deserialize entities using the EntitySerilizationAPI and import them using the EntityImportExportService. As an example, you may look at the EntitiesControllerManager.createEntity() method.

Thanks, I will create the custom controller and get it done

Hi Team

Is this feature implemented from cuba side? In latest release.
@knstvk or @gorbunkov

Regards,
Shanur

Hi,

It was implemented in REST API 7.2

The issue: Support batch entity commit · Issue #27 · cuba-platform/restapi · GitHub

It is not documented yet, but the idea is that you can pass multiple entities as JSON-array.