Element Operations

The Slides API allows you to create and edit a variety of page elements, including text boxes, images, tables, basic shapes, lines, and embedded videos. The examples on this page show some common page element operations that can be achieved with the API.

These examples use the following variables:

  • presentationId — indicates where you provide the presentation ID. You can discover the value for this ID from the presentation URL.
  • pageId — indicates where you provide the page object ID. You can retrieve the value for this from the URL or by using an API read request.
  • pageElementId — indicates where you provide the page element object ID for an element you are working with. You can specify this ID for elements you create (with some restrictions) or allow the API to automatically create one; element IDs can be retrieved through an API read request.

Add a bulleted list to a textbox

The following presentations.batchUpdate request inserts text into an empty textbox specified by pageElementId and then converts all the text in that box into a bulleted list. Different items in the list are separated by \n characters, while indention is controlled with \t characters.

The request protocol is shown below. The Style Text guide shows an example that implements a batch update in different languages using the Google API client libraries.

POST https://slides.googleapis.com/v1/presentations/presentationId:batchUpdate
{
  "requests": [
    {
      "insertText": {
        "objectId": pageElementId,
        "text": "My List\n\tItem 1\n\t\tItem 2\n\t\t\tItem 3",
        "insertionIndex": 0
      },
      "createParagraphBullets": {
        "objectId": pageElementId,
        "bulletPreset": "BULLET_ARROW_DIAMOND_DISC",
        "textRange": {
          "type": "ALL"
        }
      }
    }
  ]
}

This request can create a bulleted list that looks like this:

Bulleted list recipe result

Add a shape to a slide

The following presentations.batchUpdate request adds a wave shape to a slide specified by pageId. This request specifies the shape type, scales and positions the shape in the slide. A second request adds text to that shape. The request sets the line's ID to be pageElementId.

The request protocol is shown below. The Add Text and Shapes guide shows an example that implements a batch update in different languages using the Google API client libraries.

POST https://slides.googleapis.com/v1/presentations/presentationId:batchUpdate
{
  "requests": [
    {
      "createShape": {
        "objectId": pageElementId,
        "elementProperties": {
          "pageObjectId": pageId,
          "size": {
            "width": {
              "magnitude": 3000000,
              "unit": "EMU"
            },
            "height": {
              "magnitude": 3000000,
              "unit": "EMU"
            }
          },
          "transform": {
            "scaleX": 0.6807,
            "scaleY": 0.4585,
            "translateX": 6583050,
            "translateY": 1673950,
            "unit": "EMU"
          }
        },
        "shapeType": "WAVE"
      }
    },
    {
      "insertText": {
        "objectId": pageElementId,
        "text": "My Wave Shape",
        "insertionIndex": 0
      }
    }
  ]
}

Add a video to a slide

The following presentations.batchUpdate request embeds a video into a slide specified by pageId. This request scales and positions the video in the slide. The request sets the video's ID to be pageElementId. videoId is the video source's unique identifier; for example, the YouTube video at https://www.youtube.com/watch?v=7U3axjORYZ0 has the ID 7U3axjORYZ0.

The request protocol is shown below. The Add Text and Shapes guide shows an example that implements a batch update in different languages using the Google API client libraries.

POST https://slides.googleapis.com/v1/presentations/presentationId:batchUpdate
{
  "requests": [
    {
      "createVideo": {
        "objectId": pageElementId,
        "elementProperties": {
          "pageObjectId": pageId,
          "size": {
            "width": {
              "magnitude": 12000,
              "unit": "EMU"
            },
            "height": {
              "magnitude": 9000,
              "unit": "EMU"
            }
          },
          "transform": {
            "scaleX": 381,
            "scaleY": 381,
            "translateX": 152400,
            "translateY": 152400,
            "unit": "EMU"
          }
        },
        "source": "YOUTUBE",
        "id": videoId
      }
    }
  ]
}

Copy and edit an element

The following presentations.batchUpdate request takes a shape (specified by pageElementId) and creates a copy (specified by copyElementId). The request then makes the following changes to the copy:

  • Sets the background color to the LIGHT2 theme color.
  • Moves the copy down the page (from the original shape's position).
  • Sets the text font to 18-pt Georgia.
  • Edits the text to read "My Shape Copy".

The update requests used here make use of field masks to preserve shape properties that are not to be changed (such as the outline style).

The request protocol is shown below. The Add Text and Shapes guide shows an example that implements a batch update in different languages using the Google API client libraries.

POST https://slides.googleapis.com/v1/presentations/presentationId:batchUpdate
{
  "requests": [
    {
      "duplicateObject": {
        "objectId": pageElementId,
        "objectIds": {
          pageElementId: copyElementId
        }
      }
    },
    {
      "updateShapeProperties": {
        "objectId": copyElementId,
        "fields": "shapeBackgroundFill.solidFill.color",
        "shapeProperties": {
          "shapeBackgroundFill": {
            "solidFill": {
              "color": {
                "themeColor": "LIGHT2"
              }
            }
          }
        }
      }
    },
    {
      "updatePageElementTransform": {
        "objectId": copyElementId,
        "applyMode": "RELATIVE",
        "transform": {
          "scaleX": 1,
          "scaleY": 1,
          "translateX": 0,
          "translateY": 1250000,
          "unit": "EMU"
        }
      }
    },
    {
      "updateTextStyle": {
        "objectId": copyElementId,
        "fields": "fontFamily,fontSize",
        "textRange": {
          "type": "ALL"
        },
        "style": {
          "fontFamily": "Georgia",
          "fontSize": {
            "magnitude": 18,
            "unit": "PT"
          }
        }
      }
    },
    {
      "deleteText": {
        "objectId": copyElementId,
        "textRange": {
          "type": "ALL"
        }
      }
    },
    {
      "insertText": {
        "objectId": copyElementId,
        "text": "My Shape Copy",
        "insertionIndex": 0
      }
    }
  ]
}

Here is what a shape and its copy might look like after this request:

Copy and update recipe result

Edit an image or video outline

The following presentations.batchUpdate request updates the outline appearance of an image specified by imageElementId and an embedded video specified by videoElementId. The request:

  • Sets the image outline color to the ACCENT5 theme color with partial transparency and the video outline color to the ACCENT1 theme color with no transparency.
  • Sets the outline weights to 3-pt.
  • Sets the image outline style to SOLID and the video outline style to DASH_DOT.

Currently, updateImageProperties and updateVideoProperties requests can only change the appearance of image and video outlines — other properties are read-only. The update requests used here make use of field masks to specify that only the outline should be changed, as a way of protecting the code against future API changes.

The request protocol is shown below. The Add Text and Shapes guide shows an example that implements a batch update in different languages using the Google API client libraries.

POST https://slides.googleapis.com/v1/presentations/presentationId:batchUpdate
{
  "requests": [
    {
      "updateImageProperties": {
        "objectId": imageElementId,
        "fields": "outline",
        "imageProperties": {
          "outline": {
            "dashStyle": "SOLID",
            "outlineFill": {
              "solidFill": {
                "alpha": 0.8,
                "color": {
                  "themeColor": "ACCENT5"
                }
              }
            },
            "weight": {
              "magnitude": 3,
              "unit": "PT"
            }
          }
        }
      }
    },
    {
      "updateVideoProperties": {
        "objectId": videoElementId,
        "fields": "outline",
        "videoProperties": {
          "outline": {
            "dashStyle": "DASH_DOT",
            "outlineFill": {
              "solidFill": {
                "alpha": 0.8,
                "color": {
                  "themeColor": "ACCENT1"
                }
              }
            },
            "weight": {
              "magnitude": 3,
              "unit": "PT"
            }
          }
        }
      }
    }
  ]
}

Here is what an image and embedded video might look like after this request:

Image and video outline recipe result

Edit the outline of a shape

The following presentations.batchUpdate request takes a shape specified by pageElementId and updates the appearance of its outline. The request:

  • Sets the outline color to the ACCENT5 theme color, with partial transparency.
  • Sets the outline weight to 3-pt.
  • Sets the outline style to LONG_DASH.

The update requests used here make use of field masks to preserve shape properties that are not to be changed (such as the shape fill color).

The request protocol is shown below. The Add Text and Shapes guide shows an example that implements a batch update in different languages using the Google API client libraries.

POST https://slides.googleapis.com/v1/presentations/presentationId:batchUpdate
{
  "requests": [
    {
      "updateShapeProperties": {
        "objectId": pageElementId,
        "fields": "outline",
        "shapeProperties": {
          "outline": {
            "dashStyle": "LONG_DASH",
            "outlineFill": {
              "solidFill": {
                "alpha": 0.6,
                "color": {
                  "themeColor": "ACCENT5"
                }
              }
            },
            "weight": {
              "magnitude": 3,
              "unit": "PT"
            }
          }
        }
      }
    }
  ]
}

Here is what a shape might look like after this request:

Edit outline recipe result

Format text in a shape or textbox

The following presentations.batchUpdate request takes a shape specified by pageElementId and updates the appearance of all of its text. The request:

  • Sets the text color to the ACCENT5 theme color.
  • Sets the font to be bold italic 18-pt Corsiva.
  • Underlines the text.

The update requests used here make use of field masks to preserve text style properties that are not to be changed (such as the background color, links, or baseline offsets).

The request protocol is shown below. The Add Text and Shapes guide shows an example that implements a batch update in different languages using the Google API client libraries.

POST https://slides.googleapis.com/v1/presentations/presentationId:batchUpdate
{
  "requests": [
    {
      "updateTextStyle": {
        "objectId": pageElementId,
        "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"
        }
      }
    }
  ]
}

Here is what the shape text might look like after this request:

Edit text format recipe result

Import a chart from Sheets

The following presentations.batchUpdate request imports a chart from a Google Sheet and places it on a slide specified by pageId. This request requires the spreadsheet ID and spreadsheet chart ID. These are specified here as spreadsheetId and spreadsheetChartId. The ID of the chart within Slides is presentationChartId. The request also configures the Slides chart as LINKED so that you can easily update it if the Sheets chart is updated.

The request protocol is shown below. The Add Charts guide shows an example that implements a batch update in different languages using the Google API client libraries.

POST https://slides.googleapis.com/v1/presentations/presentationId:batchUpdate
{
  "requests": [
    {
      "createSheetsChart": {
        "objectId": presentationChartId,
        "spreadsheetId": spreadsheetId,
        "chartId": spreadsheetChartId,
        "linkingMode": "LINKED",
        "elementProperties": {
          "pageObjectId": pageId,
          "size": {
            "width": {
              "magnitude": 4000000,
              "unit": "EMU"
            },
            "height": {
              "magnitude": 4000000,
              "unit": "EMU"
            }
          },
          "transform": {
            "scaleX": 1,
            "scaleY": 1,
            "translateX": 100000,
            "translateY": 100000,
            "unit": "EMU"
          }
      }
    }
  ]
}

Refresh a chart from Sheets

The following presentations.batchUpdate request refreshes a linked chart in a presentation, replacing it with the latest version of that chart from Google Sheets. The request requires that the ID of the chart in the presentation (presentationChartId).

The request protocol is shown below. The Add Charts guide shows an example that implements a batch update in different languages using the Google API client libraries.

POST https://slides.googleapis.com/v1/presentations/presentationId:batchUpdate
{
  "requests": [
    {
      "refreshSheetsChart": {
        "objectId": presentationChartId
      }
    }
  ]
}