Search code examples
google-apps-scriptgoogle-slides-api

Google Slide API - copy an object from a file to another file


I have just started playing with Google Slide API. I am able to duplicate object within a file. However, I couldn't do it when I tried copying an object from one file to another. The function will return an error that the objectId is not found. Thank you for helping!

Invalid requests[0].duplicateObject: The object (myObjectId) could not be found.

//read a file
function copyPasteObject() {
  //presentationId if the input
  var presentationId = myPresentationId;
  var presentation = Slides.Presentations.get(presentationId);
  var slides = presentation.slides;
  //getting elements objectId
  Logger.log(slides[0].pageElements[0].objectId);

  var request1 = [{
    duplicateObject: {
      objectId: slides[0].pageElements[0].objectId
    }
  }];

  // Execute the request.
  var createBullet = Slides.Presentations.batchUpdate({
    requests: request1
  }, myTargetPresentationId);
}

Solution

  • duplicateObject only works with objects in the same presentation. Copying objects across presentations isn't supported just yet-- the feature request to follow is here.