Advanced Slides Service Stay organized with collections Save and categorize content based on your preferences.
Page Summary
The Advanced Slides service allows Apps Script to read and edit content in Google Slides by accessing the Slides API.
This is an advanced service that must be enabled before use.
The service uses the same objects, methods, and parameters as the public Slides API.
Sample code is provided for common tasks like creating presentations and slides, reading element IDs, and manipulating text boxes.
It is best practice to use batch updates to combine multiple requests when using the Slides Advanced Service.
The Advanced Slides service lets you access theSlides API usingApps Script. This service allows scripts to read and edit content in Google Slides.
This is an advanced service that must beenabled before use.Reference
For detailed information on this service, see thereference documentation for the Slides API.Like all advanced services in Apps Script, the advanced Slides service uses thesame objects, methods, and parameters as the public API. For more information, seeHow method signatures are determined.
To report issues and find other support, see theSlides support guide.
Sample code
The sample code below usesversion 1 of the API.
Create a new presentation
The following example demonstrates how to create a new presentation using theSlides advanced service. It is equivalent to theCreate a new presentationrecipe sample.
/** * Create a new presentation. * @return {string} presentation Id. * @see https://developers.google.com/slides/api/reference/rest/v1/presentations/create */functioncreatePresentation(){try{constpresentation=Slides.Presentations.create({title:"MyNewPresentation",});console.log(`Created presentation with ID:${presentation.presentationId}`);returnpresentation.presentationId;}catch(e){// TODO (developer) - Handle exceptionconsole.log("Failed with error %s",e.message);}}
Create a new slide
The following example demonstrates how to create a new slide in a presentation,at a specific index and with predefined layout. It is equivalent to theCreate a new sliderecipe sample.
/** * Create a new slide. * @param {string} presentationId The presentation to add the slide to. * @return {Object} slide * @see https://developers.google.com/slides/api/reference/rest/v1/presentations/batchUpdate */functioncreateSlide(presentationId){// You can specify the ID to use for the slide, as long as it's unique.constpageId=Utilities.getUuid();constrequests=[{createSlide:{objectId:pageId,insertionIndex:1,slideLayoutReference:{predefinedLayout:"TITLE_AND_TWO_COLUMNS",},},},];try{constslide=Slides.Presentations.batchUpdate({requests:requests},presentationId,);console.log(`Created Slide with ID:${slide.replies[0].createSlide.objectId}`,);returnslide;}catch(e){// TODO (developer) - Handle Exceptionconsole.log("Failed with error %s",e.message);}}
Read page element object IDs
The following example demonstrates how to retrieve the object IDs for every pageelement on a specific slide using a field mask. It is equivalent to theRead element object IDs from a pagerecipe sample.
/** * Read page element IDs. * @param {string} presentationId The presentation to read from. * @param {string} pageId The page to read from. * @return {Object} response * @see https://developers.google.com/slides/api/reference/rest/v1/presentations.pages/get */functionreadPageElementIds(presentationId,pageId){// You can use a field mask to limit the data the API retrieves// in a get request, or what fields are updated in an batchUpdate.try{constresponse=Slides.Presentations.Pages.get(presentationId,pageId,{fields:"pageElements.objectId",});console.log(response);returnresponse;}catch(e){// TODO (developer) - Handle Exceptionconsole.log("Failed with error %s",e.message);}}
Add a new text box
The following example demonstrates how to add a new text box to a slide and addtext to it. It is equivalent to theAdd a text box to a sliderecipe sample.
/** * Add a new text box with text to a page. * @param {string} presentationId The presentation ID. * @param {string} pageId The page ID. * @return {Object} response * @see https://developers.google.com/slides/api/reference/rest/v1/presentations/batchUpdate */functionaddTextBox(presentationId,pageId){// You can specify the ID to use for elements you create,// as long as the ID is unique.constpageElementId=Utilities.getUuid();constrequests=[{createShape:{objectId:pageElementId,shapeType:"TEXT_BOX",elementProperties:{pageObjectId:pageId,size:{width:{magnitude:150,unit:"PT",},height:{magnitude:50,unit:"PT",},},transform:{scaleX:1,scaleY:1,translateX:200,translateY:100,unit:"PT",},},},},{insertText:{objectId:pageElementId,text:"My Added Text Box",insertionIndex:0,},},];try{constresponse=Slides.Presentations.batchUpdate({requests:requests},presentationId,);console.log(`Created Textbox with ID:${response.replies[0].createShape.objectId}`,);returnresponse;}catch(e){// TODO (developer) - Handle Exceptionconsole.log("Failed with error %s",e.message);}}
Format shape text
The following example demonstrates how to format a shape's text, updating itscolor, font and underlining its text. It is equivalent to theFormat text in a shape or textboxrecipe sample.
/** * Format the text in a shape. * @param {string} presentationId The presentation ID. * @param {string} shapeId The shape ID. * @return {Object} replies * @see https://developers.google.com/slides/api/reference/rest/v1/presentations/batchUpdate */functionformatShapeText(presentationId,shapeId){constrequests=[{updateTextStyle:{objectId:shapeId,fields:"foregroundColor,bold,italic,fontFamily,fontSize,underline",style:{foregroundColor:{opaqueColor:{themeColor:"ACCENT5",},},bold:true,italic:true,underline:true,fontFamily:"Corsiva",fontSize:{magnitude:18,unit:"PT",},},textRange:{type:"ALL",},},},];try{constresponse=Slides.Presentations.batchUpdate({requests:requests},presentationId,);returnresponse.replies;}catch(e){// TODO (developer) - Handle Exceptionconsole.log("Failed with error %s",e.message);}}
Best Practices
Batch Updates
When using the Slides Advanced Service, combine multiple requests in an arrayrather than callingbatchUpdate in a loop.
Don't — CallbatchUpdate in a loop.
vartitles=["slide 1","slide 2"];for(vari=0;i <titles.length;i++){Slides.Presentations.batchUpdate(preso,{requests:[{createSlide:...}]});}Do — CallbatchUpdate with an array ofupdates.
varrequests=[];vartitles=["slide 1","slide 2"];for(vari=0;i <titles.length;i++){requests.push({createSlide:...});}Slides.Presentations.batchUpdate(preso,{requests:requests});Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-11 UTC.