oData version
I'm facing a lot of '500 Internal Server Error' issues, while attempting to batch delete items in SharePoint list. My SharePoint tenant loads fine so I looked up on the Internet for other possible issues. I see a similar bug was submitted for spfx, which was fixed by overriding oData version to 3, since spfx defaults oData version as 4.
I am wondering if there is such issue with REST batching too. If not, can there be direction or documentations from Microsoft to handle such failures?
Here is the discuss and oData for for spfx: https://github.com/SharePoint/sp-dev-docs/issues/44
//Since the SP Search REST API works with ODataVersion 3, we have to create a new ISPHttpClientConfiguration object with defaultODataVersion = ODataVersion.v3 const spSearchConfig: ISPHttpClientConfiguration = { defaultODataVersion: ODataVersion.v3 };
//Override the default ODataVersion.v4 flag with the ODataVersion.v3 const clientConfigODataV3: SPHttpClientConfiguration = SPHttpClient.configurations.v1.overrideWith(spSearchConfig);
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: e3f963c2-441f-8f40-9c2a-3d31f4a79b1f
- Version Independent ID: d4a6f050-b632-a5a0-1814-33699760fccb
- Content: Make batch requests with the REST APIs
- Content Source: docs/sp-add-ins/make-batch-requests-with-the-rest-apis.md
- Product: sharepoint
- GitHub Login: @spdevdocs
- Microsoft Alias: spdevdocs
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
So your reference is a different issue - the Search REST API doesn't accept OData v4, so you have to change it.
What are the actual failures you are seeing? What's the error if you look at the response in the network tab?
I verified and found that those 500s are request request timeout for some of the requests in a batch. I wonder if there is way to disable or increase timeout. Or, is the internally Microsoft's way of declining some of the requests? i.e. throttling. My batch size is 50.
Throttling should return a 429, not a 500. What happens if you make individual requests? What is the total time spent across them?
Individual requests worked without any issue but then 500 error is intermittent too. The total runtime was 13 minutes which deleted 80 records, actual runtime would be 7.5 minutes since I have a 5 second pause after each batch so 80 items * 5 = 400 seconds.
Does Microsoft have any recommendation on batch number? I ask this because number of 500s are directly proportional to batch size. e.g. batch-size of 100 yields more 500s.
Also, this is my request. In case i'm missing any other information, please let me know. Properties like connection, host etc are not part of my header var batchRequestHeader = { 'X-RequestDigest': $("#_REQUESTDIGEST").val(), 'Content-Type': 'multipart/mixed; boundary="batch' + batchGuid + '"', };
//2. Update Digest if required, let Microsoft handle it
UpdateFormDigest(_spPageContextInfo.webServerRelativeUrl, _spFormDigestRefreshInterval);
//3. Make call
$.ajax({
url: batchEndpoint,
type: 'POST',
headers: batchRequestHeader,
data: batchBody,
async: !isValidate, //Attempt for Sync calls for validation attempts
success: function (response) {
onDeleteRESTSucceeded(response, Param_ListName, Param_SplitArrayResult, SplitItems, isValidate);
},
error: onDeleteRESTQueryFailed
});
So that's a lot of processing time. I don't know what you will save with batching requests that take 30+seconds to execute. One off would be better. A more interesting question would be "what does your query/command look like"? Spending 13 minutes to delete 70 things sounds really bad.
Well, I do not disagree but after every batch I query again to find if any items had failed to delete. if so, reattempt, I try maximum 5 times. Secondly, I assume during working hours, CRUD operations are slow?
Here is the code to build the Batch. Am I doing anything wrong here?
SplitItems.forEach(function (obj) { var itemID = obj.ID;
var endpoint = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + Param_ListName + "')/items(" + itemID + ")";
changeSetContents.push('--changeset_' + changeSetId);
changeSetContents.push('Content-Type: application/http');
changeSetContents.push('Content-Transfer-Encoding: binary');
changeSetContents.push('');
changeSetContents.push('DELETE ' + endpoint + ' HTTP/1.1');
changeSetContents.push('IF-Match: *');
changeSetContents.push('');
});
// 2. Close ChangeSet
changeSetContents.push('--changeset_' + changeSetId + '--');
// 3. Join ChangeSet
changeSetContents = changeSetContents.join('\r\n');
// Build ChangeSet: End
// Build batch content: Start
// 1. Build batch
batchContents.push('--batch_' + batchGuid);
batchContents.push('Content-Type: multipart/mixed; boundary="changeset_' + changeSetId + '"');
batchContents.push('Content-Length: ' + changeSetContents.length);
batchContents.push('Content-Transfer-Encoding: binary');
batchContents.push('');
batchContents.push(changeSetContents);
batchContents.push('');
// 2. Close Batch
batchContents.push('--batch_' + batchGuid + '--');
// 3. Join ChangeSet into batchBody
var batchBody = batchContents.join('\r\n');
//*****************************************//
//Step 3: Call REST
// 1. Build REST endpoint & headers
var batchEndpoint = _spPageContextInfo.webAbsoluteUrl + '/_api/$batch';
var batchRequestHeader = {
'X-RequestDigest': $("#__REQUESTDIGEST").val(),
'Content-Type': 'multipart/mixed; boundary="batch_' + batchGuid + '"',
};
//2. Update Digest if required, let Microsoft handle it
UpdateFormDigest(_spPageContextInfo.webServerRelativeUrl, _spFormDigestRefreshInterval);
//3. Make call
$.ajax({
url: batchEndpoint,
type: 'POST',
headers: batchRequestHeader,
data: batchBody,
async: !isValidate, //Attempt for Sync calls for validation attempts
success: function (response) {
onDeleteRESTSucceeded(response, Param_ListName, Param_SplitArrayResult, SplitItems, isValidate);
},
error: onDeleteRESTQueryFailed
});
Irrespective of slowness, why would individual requests timeout?
Closing issue as "answered". If you encounter similar issue(s), please open up a NEW issue. Thank you.
So the issue is closed even though There was no comment on why individual requests were timing out? Great Support and eagerness to close reported issue.
Just FYI for those reading this - the issue remains open.
There was an incorrect 'answered' status applied, and the bot closed it because of this. I've reopened it. There is no malicious intent. If you run each command individually, what does the URL/body of the request look like, and how long does the operation take?
It looks same as mentioned by Andrew here: https://gist.github.com/andrewconnell/dcd89e694475b628d0c7. The run-time is shared previous response.
Here is a something I noticed: I did receive operation timeout, if I select large number of items manually, say around 50 items, and attempt to delete. I have a screenshot of it but I can not paste it here.
I believe REST timeouts and one seen when manually deleting using UI are related.
Hey @vikbehal - in order to get more info in order to help, can you try and answer this? "If you run each command individually, what does the URL/body of the request look like, and how long does the operation take?"
Closing issue as "answered". If you encounter similar issue(s), please open up a NEW issue. Thank you.
Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues