Google Slides Api (Node JS / JavaScript) - is it possible to create a duplicate of a specific slide like for example assuming slide no 5 needs to be duplicated 3 times?
I believe your goal and your current situation as follows.
In this case, I thought that the method of batchUpdate in Slides API can be used.
In this sample script, please use auth
retrieved from your script. If you want to see the script for authorizing for Node.js, you can see Quickstart for Node.js. Ref In this case, please use the scope of https://www.googleapis.com/auth/presentations
.
const presentationId = "###"; // Please set the presentation ID (Google Slides ID).
const pageNumber = 5; // Please set the page number. In your question, it's 5.
const numberOfCopy = 3; // Please set the number of copy. In your question, it's 3.
const slides = google.slides({ version: "v1", auth: auth });
slides.presentations.get(
{
presentationId: presentationId,
fields: "slides(objectId)",
},
(err, res) => {
if (err) {
console.log(err);
return;
}
const pageObjectId = res.data.slides[pageNumber - 1].objectId;
const requests = [];
for (let i = 0; i < numberOfCopy; i++) {
requests.push({ duplicateObject: { objectId: pageObjectId } });
}
slides.presentations.batchUpdate(
{
presentationId: presentationId,
resource: { requests: requests },
},
(err, res) => {
if (err) {
console.log(err);
return;
}
console.log(res.data);
}
);
}
);
auth
retrieved from your authorization script can be used. Please be careful this.