Odata POST multiple entries / JSON array?

6,459 views
Skip to first unread message

Christopher Förster

unread,
May 28, 2015, 7:45:36 AM5/28/15
to odata-di...@googlegroups.com

Hi,
I tried to insert multiple entries with a single POST without success. Do you have any idea how to solve this?

The request body looks similar to:

{
 "data":[
 {"id":"a1","content":"a2"},
 {"id":"b1","content":"b2"},
 {"id":"c1","content":"c2"}
]
}

Vagif Abilov

unread,
May 28, 2015, 7:55:40 AM5/28/15
to odata-di...@googlegroups.com
Hi Christopher,

You should use OData batch to execute multiple operations in a single HTTP request.

Cheers
Vagif

--
You received this message because you are subscribed to the Google Groups "OData Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to odata-discussi...@googlegroups.com.
To post to this group, send email to odata-di...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christopher Förster

unread,
May 28, 2015, 8:28:46 AM5/28/15
to odata-di...@googlegroups.com
How does this work in my scenario? As I understood the batch is just a conatiner for other HTTP requests inside. My target is to use the request above without big changes.

Vagif Abilov

unread,
May 28, 2015, 8:45:44 AM5/28/15
to odata-di...@googlegroups.com
Look at the Advanced OData Tutorial that shows how to deal with batches:

http://www.odata.org/getting-started/advanced-tutorial/

Of course it's cumbersome to manually generate batch request payload, but there are both Microsoft and third party libraries that encapsulate low level details.

Hope this helps

Vagif

Handl, Ralf

unread,
May 29, 2015, 3:21:48 AM5/29/15
to odata-di...@googlegroups.com

Hi Christopher,

 

$batch is the only defined way in OData 4.0 to insert multiple entities in one request. Reason: $batch allows you to insert multiple entities into multiple entity sets in one change set.

 

We are currently discussing a feature similar to your use case in https://issues.oasis-open.org/browse/ODATA-613. Upserting a bunch of entities would then use a payload

 

{

 "value":[

    {"id":"a1","content":"a2"},

    {"id":"b1","content":"b2"},

    {"id":"c1","content":"c2"} 

  ]

}

 

Using the delta response format would also allow deleting entities or changing links between entities, and it would allow to GET a delta from one service and POST that same payload to another service to replicate the changes.

 

How valuable would this alternative syntax be for your use cases?

 

Thanks in advance!
--Ralf

Christopher Förster

unread,
May 29, 2015, 6:56:31 AM5/29/15
to odata-di...@googlegroups.com
Hi Ralf,
that seems to be exacly what I am looking for. As far as I can see you just changed the parent node to "value". Could you provide a complete REST request including the needed header attributes? Is the feature in development or available in odata 4?

Thanks,
  Chris

To post to this group, send email to odata-d...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "OData Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to odata-discussi...@googlegroups.com.

To post to this group, send email to odata-d...@googlegroups.com.

sneha.ful...@gmail.com

unread,
Oct 17, 2019, 6:54:00 AM10/17/19
to OData Discussion

Michael Pizzo

unread,
Oct 17, 2019, 10:25:40 AM10/17/19
to sneha.ful...@gmail.com, OData Discussion

POST is used to add a single item to a collection.

 

You could use a $batch request in order to batch multiple such posts in a single request.

 

The new OData version 4.01 adds support for bulk updates to a collection using a “delta” payload. This feature would allow you to insert multiple entries by doing a PATCH request to the collection with a payload containing the array of items to insert.


The stack that you are using for your OData service may or may not have support for this new OData 4.01 feature. We have added support for creating and parsing batch payloads to the .NET OData Core libraries, and have a work item to add support to our WebAPI OData stack.

 

Hope that helps,

 

-Mike

--

You received this message because you are subscribed to the Google Groups "OData Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to odata-discussi...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages