@mikezimm/fps-core-v7
Version:
Library of reusable core interfaces, types and constants migrated from fps-library-v2
47 lines (43 loc) • 1.59 kB
JavaScript
/**
* 2024-11-23: This is for EXPERIMENTAL Purposes to test out batch calls
*/
function sampleBatchCall() {
const siteUrl = "https://fuzzypawstech.sharepoint.com/sites/WorldMaps";
const batchEndpoint = `${siteUrl}/_api/$batch`;
async function executeBatch() {
const headers = {
"Accept": "application/json;odata=verbose",
"Content-Type": "multipart/mixed; boundary=batch_boundary",
"Authorization": "Bearer YOUR_ACCESS_TOKEN" // Use an access token if required
};
// Construct batch request body
const body = `
--batch_boundary
Content-Type: application/http
Content-Transfer-Encoding: binary
GET ${siteUrl}/_api/web/lists/getbytitle('WorldCoords888')/items?$top=5 HTTP/1.1
Accept: application/json;odata=verbose
--batch_boundary
Content-Type: application/http
Content-Transfer-Encoding: binary
GET ${siteUrl}/_api/web/lists/getbytitle('WorldCoords999')/items?$top=5 HTTP/1.1
Accept: application/json;odata=verbose
--batch_boundary--
`;
// Send batch request
const response = await fetch(batchEndpoint, {
method: "POST",
headers,
body
});
if (response.ok) {
const text = await response.text();
console.log(text); // Contains the raw batch response
}
else {
console.error(`Batch request failed with status: ${response.status}`);
}
}
executeBatch();
}
//# sourceMappingURL=getSourceItemsBatchAPI.js.map