Question

I need to do bulk inserts and learned that there is the $batch operation in the REST API. https://msdn.microsoft.com/en-us/library/office/dn903506.aspx

I read through this and following and explored his GitHub http://www.andrewconnell.com/blog/part-1-sharepoint-rest-api-batching-understanding-batching-requests https://github.com/andrewconnell/sp-o365-rest/blob/master/SpRestBatchSample/Scripts/App.js

I ended up creating a POST against my server that looks like this

POST http://portalstst.m.DUMMY.com/sites/DUMMY_digital/_api/web/lists/getbytitle('Logging_DB')/Items HTTP/1.1
Host: portalstst.m.DUMMY.com
Connection: keep-alive
Content-Length: 680
Origin: http://portalstst.m.DUMMY.com
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1
contentType: application/json;odata=verbose
Content-Type: multipart/mixed; boundary="batch_6495a5b4-f360-44d4-9a61-5a9d515456de"
Accept: application/json;odata=verbose
DataServiceVersion: 1.0
X-RequestDigest: 0x428391B9D35610B96821EEF1C768534C38C8CEB9A275EC8A661C3D3DE08A7DB4A342899235931BA589AA153430D484C0D413976B028C77292E2F8A77F27C5039,19 Aug 2016 14:17:46 -0000
DNT: 1
Referer: http://portalstst.m.DUMMY.com/sites/DUMMY_digital/App/index.html
Accept-Encoding: gzip, deflate
Accept-Language: de,en-US;q=0.8,en;q=0.6

--batch_6495a5b4-f360-44d4-9a61-5a9d515456de
Content-Type: multipart/mixed; boundary="changeset_9473c1bb-265d-45df-9ad1-9a0487d043ee"
Content-Length: 436
Content-Transfer-Encoding: binary

--changeset_9473c1bb-265d-45df-9ad1-9a0487d043ee
Content-Type: application/http
Content-Transfer-Encoding: binary

POST http://portalstst.m.DUMMY.com/sites/DUMMY_digital/_api/web/lists/getbytitle('Logging_DB')/Items HTTP/1.1
Content-Type: application/json;odata=verbose

{"__metadata":{"type":"SP.Data.Logging_x005f_DBListItem"},"FromPage":"transformation","ToPage":"capability"}

--changeset_9473c1bb-265d-45df-9ad1-9a0487d043ee--

--batch_6495a5b4-f360-44d4-9a61-5a9d515456de--

The result in short: HTTP/1.1 415 Unsupported Media Type, The HTTP header Content-Type is missing or its value is invalid.

HTTP/1.1 415 Unsupported Media Type
Cache-Control: private, max-age=0
Content-Type: application/json;odata=verbose;charset=utf-8
Expires: Thu, 04 Aug 2016 14:17:53 GMT
Last-Modified: Fri, 19 Aug 2016 14:17:53 GMT
Server: Microsoft-IIS/8.5
X-SharePointHealthScore: 0
SPClientServiceRequestDuration: 140
X-AspNet-Version: 4.0.30319
SPRequestGuid: 72559b9d-7727-4083-b167-b7fd1dca3fb6
request-id: 72559b9d-7727-4083-b167-b7fd1dca3fb6
X-RequestDigest: 0xB102AC2A481F112F017D042DC858F3429233A97163971A795C93E38BDC57FD7B04967CABD190D539844F91C21252BD64BD6589C5D90E114550C1D6FB119C96F1,19 Aug 2016 14:17:53 -0000
X-FRAME-OPTIONS: SAMEORIGIN
X-Powered-By: ASP.NET
MicrosoftSharePointTeamServices: 15.0.0.4763
X-Content-Type-Options: nosniff
X-MS-InvokeApp: 1; RequireReadOnly
Date: Fri, 19 Aug 2016 14:17:52 GMT
Content-Length: 177

{"error":{"code":"-1, Microsoft.SharePoint.Client.ClientServiceException","message":{"lang":"en-US","value":"The HTTP header Content-Type is missing or its value is invalid."}}}

I compared my request to the example at https://gist.github.com/andrewconnell/ad502b73b2cc9504229d and don't see any mistake.

Now I wonder whether this is supported on premise at all? Or what I'm doing wrong?

Was it helpful?

Solution 3

Finally found a solution. Like in other cases where the REST API is missing something, fall back to the List Service and use it in pretty much the same way as is described for the REST variant in newer versions:

/_vti_bin/listdata.svc/$batch

Problem solved

OTHER TIPS

As far as I know REST API batching is only supported in SharePoint Online and SharePoint 2016. Support for REST API batching did not get pushed down to SharePoint 2013.

If I recall correctly you need Service Pack 1 at least for SharePoint 2013 for this to be supported.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top