Updated: GAS Library - BatchRequest

BatchRequest was updated to v1.2.1.

Sample script using exportDataAsBlob

In this sample, the Spreadsheet and Document files are exported as PDF format using the batch requests. The exported PDF data is created as a PDF file to the root folder. When I answered this thread on Stackoverflow, when this option is added to this library, I thought that it might be useful for users.

const fileIds = ["###SpreadsheetID1###", "###DocumentID1###"];
const requests = fileIds.map((id) => ({
  method: "GET",
  endpoint: `https://www.googleapis.com/drive/v3/files/${id}/export?mimeType=application/pdf`,
}));
const reqs = {
  batchPath: "batch/drive/v3",
  requests,
  exportDataAsBlob: true,
};
const blobs = BatchRequestTest.EDo(reqs); // Using this library
blobs.forEach((b) => {
  if (b) {
    console.log({ filename: b.getName(), fileSize: b.getBytes().length });
    DriveApp.createFile(b);
  }
});

You can check this at https://github.com/tanaikech/BatchRequest.

 Share!