Adding text and shapes with the Google Slides API
Posted by Wesley Chun (@wescpy), Developer Advocate, G Suite
When the Google Slides team launched their very first API last November, it immediately opened up a whole new class of applications. These applications have the ability to interact with the Slides service, so you can perform operations on presentations programmatically. Since its launch, we've published several videos to help you realize some of those possibilities, showing you how to:
insertText requests to tell the API to add text to
slides. This is true whether you're adding text to a textbox, a shape or table
cell. Similar to the Google Sheets
API, all requests are made as JSON payloads sent to the API's
some object (
objectID) on a slide:
"text": "Hello World!\n"
Adding shapes is a bit more challenging, as you can see from its sample JSON structure:
Placing or manipulating shapes or images on slides requires more information so the cloud service can properly render these objects. Be aware that it does involve some math, as you can see from the Page Elements page in the docs as well as the Transforms concept guide. In the video, I drop a few hints and good practices so you don't have to start from scratch.
Regardless of how complex your requests are, if you have at least one, say
in an array named
requests, you'd make an API call with
batchUpdate() method, which in Python looks like
SLIDES is the service endpoint and a
presentation ID of
For a detailed look at the complete code sample featured in the
DevByte, check out the deep dive post. As you
can see, adding text is fairly straightforward. If you want to learn how to
format and style that text, check out the Formatting Text post and video as well as the text concepts
To learn how to perform text search-and-replace, say to replace placeholders in a template deck, check out the Replacing Text & Images post and video as well as the merging data into slides guide. We hope these developer resources help you create that next great app that automates the task of producing presentations for your users!