Creating a New Slide

This page describes how to add slides to an existing Google Slides presentation.

Slides

Each individual page of a Google Slides presentation is a slide.

To add a slide to the presentation, you need the presentation ID to start with. You can find the presentation's ID by opening the presentation in Google Slides and looking at its URL:

https://docs.google.com/presentation/d/presentationID/edit

To add a slide, use the batchUpdate() method with the presentation ID and include a CreateSlideRequest in the request body. The ID of the new slide is returned in the response body.

Example

The following example shows how to add a new slide to a presentation. All the parameters for the createSlide request are optional; this example creates the new slide as the second slide, with TITLE_AND_TWO_COLUMNS layout, and an explicit object ID.

Apps Script

slides/api/Snippets.gs
// See Presentation.insertSlide(...) to learn how to add a slide using SlidesApp.
// http://developers.google.com/apps-script/reference/slides/presentation#appendslidelayout
var requests = [{
  createSlide: {
    objectId: pageId,
    insertionIndex: '1',
    slideLayoutReference: {
      predefinedLayout: 'TITLE_AND_TWO_COLUMNS'
    }
  }
}];

// If you wish to populate the slide with elements, add element create requests here,
// using the pageId.

// Execute the request.
var createSlideResponse = Slides.Presentations.batchUpdate({
  requests: requests
}, presentationId);
console.log('Created slide with ID: %s', createSlideResponse.replies[0].createSlide.objectId);

Go

slides/snippets/presentations.go
// Add a slide at index 1 using the predefined "TITLE_AND_TWO_COLUMNS" layout
// and the ID "MyNewSlide_001".
slideId := "MyNewSlide_001"
requests := []*slides.Request{{
	CreateSlide: &slides.CreateSlideRequest{
		ObjectId:       slideId,
		InsertionIndex: 1,
		SlideLayoutReference: &slides.LayoutReference{
			PredefinedLayout: "TITLE_AND_TWO_COLUMNS",
		},
	},
}}

// If you wish to populate the slide with elements, add create requests here,
// using the slide ID specified above.

// Execute the request.
body := &slides.BatchUpdatePresentationRequest{
	Requests: requests,
}
response, err := slidesService.Presentations.BatchUpdate(presentationId, body).Do()
if err != nil {
	log.Fatalf("Unable to create slide. %v", err)
}
fmt.Printf("Created slide with ID: %s", response.Replies[0].CreateSlide.ObjectId)

Java

slides/snippets/src/main/java/Snippets.java
// Add a slide at index 1 using the predefined "TITLE_AND_TWO_COLUMNS" layout
// and the ID "MyNewSlide_001".
List<Request> requests = new ArrayList<>();
String slideId = "MyNewSlide_001";
requests.add(new Request()
        .setCreateSlide(new CreateSlideRequest()
                .setObjectId(slideId)
                .setInsertionIndex(1)
                .setSlideLayoutReference(new LayoutReference()
                        .setPredefinedLayout("TITLE_AND_TWO_COLUMNS"))));

// If you wish to populate the slide with elements, add create requests here,
// using the slide ID specified above.

// Execute the request.
BatchUpdatePresentationRequest body =
        new BatchUpdatePresentationRequest().setRequests(requests);
BatchUpdatePresentationResponse response =
        slidesService.presentations().batchUpdate(presentationId, body).execute();
CreateSlideResponse createSlideResponse = response.getReplies().get(0).getCreateSlide();
System.out.println("Created slide with ID: " + createSlideResponse.getObjectId());

JavaScript

slides/snippets/snippets.js
var requests = [{
  createSlide: {
    objectId: pageId,
    insertionIndex: '1',
    slideLayoutReference: {
      predefinedLayout: 'TITLE_AND_TWO_COLUMNS'
    }
  }
}];

// If you wish to populate the slide with elements, add element create requests here,
// using the pageId.

// Execute the request.
gapi.client.slides.presentations.batchUpdate({
  presentationId: presentationId,
  requests: requests
}).then((createSlideResponse) => {
  console.log(`Created slide with ID: ${createSlideResponse.result.replies[0].createSlide.objectId}`);
});

Node.js

slides/snippets/snippets.js
let requests = [{
  createSlide: {
    objectId: pageId,
    insertionIndex: '1',
    slideLayoutReference: {
      predefinedLayout: 'TITLE_AND_TWO_COLUMNS',
    },
  },
}];
// If you wish to populate the slide with elements, add element create requests here,
// using the pageId.

// Execute the request.
return this.slidesService.presentations.batchUpdate({
  presentationId,
  resource: {
    requests,
  },
}, (err, res) => {
  console.log(`Created slide with ID: ${res.replies[0].createSlide.objectId}`);
});

PHP

slides/snippets/src/SlidesSnippets.php
<?php
// Add a slide at index 1 using the predefined 'TITLE_AND_TWO_COLUMNS' layout and
// the ID page_id.
$requests = array();
$requests[] = new Google_Service_Slides_Request(array(
    'createSlide' => array(
        'objectId' => $pageId,
        'insertionIndex' => 1,
        'slideLayoutReference' => array(
            'predefinedLayout' => 'TITLE_AND_TWO_COLUMNS'
        )
    )
));

// If you wish to populate the slide with elements, add element create requests here,
// using the page_id.

// Execute the request.
$batchUpdateRequest = new Google_Service_Slides_BatchUpdatePresentationRequest(array(
    'requests' => $requests
));
$response = $slidesService->presentations->batchUpdate($presentationId, $batchUpdateRequest);
$createSlideResponse = $response->getReplies()[0]->getCreateSlide();
printf("Created slide with ID: %s\n", $createSlideResponse->getObjectId());

Python

slides/snippets/slides_snippets.py
# Add a slide at index 1 using the predefined
# 'TITLE_AND_TWO_COLUMNS' layout and the ID page_id.
requests = [
    {
        'createSlide': {
            'objectId': page_id,
            'insertionIndex': '1',
            'slideLayoutReference': {
                'predefinedLayout': 'TITLE_AND_TWO_COLUMNS'
            }
        }
    }
]

# If you wish to populate the slide with elements,
# add element create requests here, using the page_id.

# Execute the request.
body = {
    'requests': requests
}
response = slides_service.presentations() \
    .batchUpdate(presentationId=presentation_id, body=body).execute()
create_slide_response = response.get('replies')[0].get('createSlide')
print('Created slide with ID: {0}'.format(
    create_slide_response.get('objectId')))

Ruby

slides/snippets/lib/file_snippets.rb
body = Google::Apis::SlidesV1::Presentation.new
requests = [{
  create_slide: {
    object_id_prop: page_id,
    insertion_index: '1',
    slide_layout_reference: {
      predefined_layout: 'TITLE_AND_TWO_COLUMNS'
    }
  }
}]

# If you wish to populate the slide with elements, add element create requests here,
# using the page_id.

# Execute the request.
req = Google::Apis::SlidesV1::BatchUpdatePresentationRequest.new(requests: requests)
response = slides_service.batch_update_presentation(presentation_id, req)
create_slide_response = response.replies[0].create_slide
puts "Created slide with ID: #{create_slide_response.object_id}"

After you have created a new slide, you can begin to add text and shapes to it.

Filling in placeholders

Layouts normally have placeholder shapes on them that are copied to the slide when it's created. CreateSlideRequest lets you specify the object IDs used for these copied placeholders using the placeholderIdMappings field. This lets you to modify the copied placeholders in the same batchUpdate request, which improves performance and saves quota. See the CreateSlideRequest sample for an example.

Send feedback about...

Need help? Visit our support page.