Slide Operations

The Slides API allows you to create, move, and delete slides. The examples on this page show some common slide 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 and pageId2 — indicate where you provide page object IDs. You can retrieve the value for this from the URL or by using an API read request.

Copy a slide

The following presentations.batchUpdate request creates a copy of a slide and inserts it after the original in the presentation. The original slide is specified by pageId.

The request lets you specify what some or all of the page element IDs should be in the copy, with some restrictions. In this example, the original slide has a table element (specified by the ID tableElement_01), which is mapped to a new table (with ID copiedTable_001) in the slide copy (which is given the ID copiedSlide_001). All other elements on the copy are given random IDs.

The request protocol is shown below. The Create a Slide 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": pageId,
        "objectIds": {
          "pageId": "copiedSlide_001",
          "tableElement_01": "copiedTable_001"
        }
      }
    }
  ]
}

Create a new slide

The following presentations.batchUpdate request creates a new slide and inserts it as the fourth slide in the presentation. The new slide is set to use the "Title and two columns" predefined layout. You can specify a string to use as the pageId for the slide (with some restrictions), or allow the API to generate the pageId by omitting the field in the request.

The request protocol is shown below. The Create a Slide 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": [
    {
      "createSlide": {
        "objectId": pageId,
        "insertionIndex": 3,
        "slideLayoutReference": {
          "predefinedLayout": "TITLE_AND_TWO_COLUMNS"
        }
      }
    }
  ]
}

Create a new slide and modify placeholders

The following presentations.batchUpdate request creates a new slide using the "Title and two columns" predefined layout and sets the title.

POST https://slides.googleapis.com/v1/presentations/presentationId:batchUpdate
{
  "requests": [
    {
      "createSlide": {
        "objectId": pageId,
        "slideLayoutReference": {
          "predefinedLayout": "TITLE_AND_TWO_COLUMNS"
        },
        "placeholderIdMappings": [
          {
            "layoutPlaceholder": {
              "type": "TITLE",
              "index": 0
            },
            "objectId": titleId,
           },
        ],
      }
    },
    {
      "insertText": {
        "objectId": titleId,
        "text": "This is my slide title",
      }
    },
  ]
}

Move slides to a new position

The following presentations.batchUpdate request takes the two specifed slides and moves them to the beginning of the presentation, maintaining their relative ordering. The specified slide IDs must be provided in the existing presentation order, without duplicates.

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": [
    {
      "updateSlidesPosition": {
        "slideObjectIds": [
          pageId,
          pageId2
        ],
        "insertionIndex": 0
      }
    }
  ]
}

Set a slide background image

The following presentations.batchUpdate request sets the background image of a slide spacified by pageId. A field mask is used to only update the slide background without changing its other properties. The image is specified by providing a URL (imageUrl) that the API fetches from. Alternatively, an updatePageProperties request can be used to set the background of a slide to a solid color.

The request protocol is shown below. The Create a Slide 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": [
    {
      "updatePageProperties": {
        "objectId": pageId,
        "pageProperties": {
          "pageBackgroundFill": {
            "stretchedPictureFill": {
              "contentUrl": imageUrl
            }
          }
        },
        "fields": "pageBackgroundFill"
      }
    }
  ]
}

Send feedback about...

Need help? Visit our support page.