Skip to Content
1
Jan 28, 2020 at 04:24 PM

Issue in inserting Multiple Records in a single API request using CAP

1139 Views

I have been using using CAP for exposing my HANA tables to ODATA. I can perform CRUD operations from the following documentation https://cap.cloud.sap/docs/guides/generic-providers#crud. With the documentation I can insert single record. For example inserting a book we can use the below API request,

POST serviceName/Books
data: {
  ID: 121,
  title: 'Jane Eyre',
  author_ID: 12
}

with the schema.cds

entity Books {
  key ID : Integer;
      title : string(20);
}

and service.cds

using {sap.capire.bookshop as my} from '../db/schema';

service ServiceName @(requires : 'admin') {
  entity Books   as projection on my.Books;
}

But to insert multiple books in the form of array in a single request as below,

POST serviceName/Books
data: [{
  ID: 121,
  title: 'Book A'
},{
  ID: 122,
  title: 'Book B'
}]

How can we achieve the multiple record insertion in a single request as above