cancel
Showing results for 
Search instead for 
Did you mean: 

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

premchander
Explorer

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

Accepted Solutions (0)

Answers (1)

Answers (1)

pierre_dominique2
Contributor
0 Kudos

Hi,

You can't just pass an array to create multiple records, you have to use batch requests: http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#sec_BatchRequests

Cheers,

Pierre