February 23, 2017
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
batchUpdate()
method. Here's the JavaScript for inserting text in
some object (objectID
) on a slide:
{ "insertText": { "objectId": objectID, "text": "Hello World!\n" }Adding shapes is a bit more challenging, as you can see from its sample JSON structure:
{ "createShape": { "shapeType": "SMILEY_FACE", "elementProperties": { "pageObjectId": slideID, "size": { "height": { "magnitude": 3000000, "unit": "EMU" }, "width": { "magnitude": 3000000, "unit": "EMU" } }, "transform": { "unit": "EMU", "scaleX": 1.3449, "scaleY": 1.3031, "translateX": 4671925, "translateY": 450150 } } } }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.
requests
, you'd make an API call with
the aforementioned batchUpdate()
method, which in Python looks like
this (assuming SLIDES
is the service endpoint and a
presentation ID of deckID)
:SLIDES.presentations().batchUpdate(presentationId=deckID, body=requests).execute()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 guide.