Skip to content

Instantly share code, notes, and snippets.

@andrewconnell
Last active May 20, 2019 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewconnell/dcd89e694475b628d0c7 to your computer and use it in GitHub Desktop.
Save andrewconnell/dcd89e694475b628d0c7 to your computer and use it in GitHub Desktop.
Sample SharePoint Online REST Batch Request Deleting Items & Querying List
POST https://aconn-fe6c88f31b8e0b.sharepoint.com/sites/dev/SpRestBatchSample/_api/$batch HTTP/1.1
Host: aconn-fe6c88f31b8e0b.sharepoint.com
Connection: keep-alive
Content-Length: 3616
Accept: */*
Origin: https://aconn-fe6c88f31b8e0b.sharepoint.com
X-Requested-With: XMLHttpRequest
X-RequestDigest: 0x3F168AD947C57DCB851D5EFF0F7A9D8CFBB1DF3D1F574BC7D0AF2C7E38DF5AF28C9F311B1ADB8447D965F037657B4DF572C1F9DD139D9E6AE3A565B659134FA5,30 Nov 2014 12:55:26 -0000
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36
Content-Type: multipart/mixed; boundary="batch_f7ee2f04-d4bb-4501-c8c8-af782b0ceace"
Referer: https://aconn-fe6c88f31b8e0b.sharepoint.com/sites/dev/SpRestBatchSample/Pages/Default.aspx?SPHostUrl=https%3A%2F%2Faconn%2Esharepoint%2Ecom%2Fsites%2Fdev&SPLanguage=en%2DUS&SPClientTag=0&SPProductNumber=16%2E0%2E3431%2E1218&SPAppWebUrl=https%3A%2F%2Faconn%2Dfe6c88f31b8e0b%2Esharepoint%2Ecom%2Fsites%2Fdev%2FSpRestBatchSample
Accept-Encoding: gzip,deflate
Accept-Language: en-US,en;q=0.8
Cookie: WSS_FullScreenMode=false; rtFa=tuVED+yNm9wcX/FhwoP4LWBIKTDdkU57FJQFUXDB1HxxIOrPF9UmWGJK8MVlRWuyRhJtagkeIb0pEXuAse2dC1/5o/af/PZO9gWU4QGu7hkePjAyt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hdWx0LmFzcHg/U1BIb3N0VXJsPWh0dHBzOi8vYWNvbm4uc2hhcmVwb2ludC5jb20vc2l0ZXMvZGV2JmFtcDtTUExhbmd1YWdlPWVuLVVTJmFtcDtTUENsaWVudFRhZz0wJmFtcDtTUFByb2R1Y3ROdW1iZXI9MTYuMC4zNDMxLjEyMTgmYW1wO1NQQXBwV2ViVXJsPWh0dHBzOi8vYWNvbm4tZmU2Yzg4ZjMxYjhlMGIuc2hhcmVwb2ludC5jb20vc2l0ZXMvZGV2L1NwUmVzdEJhdGNoU2FtcGxlPC9TUD4=
--batch_f7ee2f04-d4bb-4501-c8c8-af782b0ceace
Content-Type: multipart/mixed; boundary="changeset_19900e7e-3e1a-4d5b-e669-716e9c3fa731"
Host: aconn-fe6c88f31b8e0b.sharepoint.com
Content-Length: 2984
Content-Transfer-Encoding: binary
--changeset_19900e7e-3e1a-4d5b-e669-716e9c3fa731
Content-Type: application/http
Content-Transfer-Encoding: binary
DELETE https://aconn-fe6c88f31b8e0b.sharepoint.com/sites/dev/SpRestBatchSample/_api/web/lists/getbytitle('Drivers')/items(19) HTTP/1.1
If-Match: *
--changeset_19900e7e-3e1a-4d5b-e669-716e9c3fa731
Content-Type: application/http
Content-Transfer-Encoding: binary
DELETE https://aconn-fe6c88f31b8e0b.sharepoint.com/sites/dev/SpRestBatchSample/_api/web/lists/getbytitle('Drivers')/items(20) HTTP/1.1
If-Match: *
--changeset_19900e7e-3e1a-4d5b-e669-716e9c3fa731
Content-Type: application/http
Content-Transfer-Encoding: binary
DELETE https://aconn-fe6c88f31b8e0b.sharepoint.com/sites/dev/SpRestBatchSample/_api/web/lists/getbytitle('Drivers')/items(22) HTTP/1.1
If-Match: *
--changeset_19900e7e-3e1a-4d5b-e669-716e9c3fa731
Content-Type: application/http
Content-Transfer-Encoding: binary
DELETE https://aconn-fe6c88f31b8e0b.sharepoint.com/sites/dev/SpRestBatchSample/_api/web/lists/getbytitle('Drivers')/items(24) HTTP/1.1
If-Match: *
--changeset_19900e7e-3e1a-4d5b-e669-716e9c3fa731
Content-Type: application/http
Content-Transfer-Encoding: binary
DELETE https://aconn-fe6c88f31b8e0b.sharepoint.com/sites/dev/SpRestBatchSample/_api/web/lists/getbytitle('Drivers')/items(21) HTTP/1.1
If-Match: *
--changeset_19900e7e-3e1a-4d5b-e669-716e9c3fa731
Content-Type: application/http
Content-Transfer-Encoding: binary
DELETE https://aconn-fe6c88f31b8e0b.sharepoint.com/sites/dev/SpRestBatchSample/_api/web/lists/getbytitle('Drivers')/items(23) HTTP/1.1
If-Match: *
--changeset_19900e7e-3e1a-4d5b-e669-716e9c3fa731--
--batch_f7ee2f04-d4bb-4501-c8c8-af782b0ceace
Content-Type: application/http
Content-Transfer-Encoding: binary
GET https://aconn-fe6c88f31b8e0b.sharepoint.com/sites/dev/SpRestBatchSample/_api/web/lists/getbytitle('Drivers')/items?$orderby=Title HTTP/1.1
Host: aconn-fe6c88f31b8e0b.sharepoint.com
Accept: application/json;odata=verbose
--batch_f7ee2f04-d4bb-4501-c8c8-af782b0ceace--
@balmeter
Copy link

Andrew,
Is there a way to loop through list items with a batch request? If I have a list of 5000+ list items that need to be deleted, how can I do this besides items(1), items(2), ..... items(5001)?

Much appreciated!
Brian Almeter

@vikbehal
Copy link

@brian,

We have to loop through items to build it. Generally, we would query for items, loop through ids to build batch-content. I think what you are asking for it if ID >= 1 or ID <= 5001 which is not available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment