Last active
July 13, 2023 17:31
-
-
Save vgrem/8bc73080f42e1e11aa5b to your computer and use it in GitHub Desktop.
Example: how to execute SharePoint REST Batch request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jsonSPHeaders = { | |
"Accept": "application/json;odata=verbose", | |
"Content-Type": "application/json;odata=verbose", | |
"DataServiceVersion": "3.0" | |
}; | |
OData.request( { | |
requestUri: _spPageContextInfo.webAbsoluteUrl + "/_api/$batch", | |
method: "POST", | |
headers: { "X-RequestDigest": $("#__REQUESTDIGEST").val(), | |
"DataServiceVersion": "3.0" }, | |
data: { __batchRequests: [ | |
{ requestUri: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Pages')/items", method: "GET" , headers: jsonSPHeaders }, | |
{ requestUri: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Tasks')/items", method: "GET", headers: jsonSPHeaders } | |
]} | |
}, | |
function (data, response) { | |
console.log('Pages list:'); | |
printListItems(data.__batchResponses[0].data); | |
console.log('Tasks list:'); | |
printListItems(data.__batchResponses[1].data); | |
}, | |
null, | |
OData.batchHandler); | |
function printListItems(data){ | |
data.results.forEach(function(item){ | |
console.log(item.Title); | |
}); | |
} |
Can you please share snippets for master and child data insertion.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this