Liam Clifford
Liam Clifford

Reputation: 11

Renaming Google Slides Presentation (google slides API)

I'm trying to figure out how to rename a google slides presentation (ie. the document, not an individual slide). I've gone through a good amount of the Google Slide API Request documentation, but am still struggling to find the correct request. In my example, the objective is to rename the google presentation to "hello-world".

Being that I can't locate the right fields, when i go to execute the code below I keep receiving the following error:

<HttpError 400 when requesting https://slides.googleapis.com/v1/presentations/[PRESENTATION ID]:batchUpdate?alt=json returned "Invalid JSON payload received. Unknown name "Presentation" at 'requests[0]': Cannot find field.". Details: "[{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'requests[0]', 'description': 'Invalid JSON payload received. Unknown name "Presentation" at \'requests[0]\': Cannot find field.'}]}]">

I've tried playing around with the request as much as possible, but still can't seem to figure it out. Provided below is the code. Any help is greatly appreciated.

slides_service = build('slides', 'v1', credentials=credentials)
presentationId = '####'   

body = {
  "requests": [{    
    "Presentation": {
      "properties": {
        "title": {
          "description": "hello-world",
          "type": "string"
        }
      }
    }
  }]
}

response = slides_service.presentations().batchUpdate(presentationId=presentationId,body=body).execute()

Upvotes: 1

Views: 322

Answers (1)

NightEye
NightEye

Reputation: 11214

As per Yuri mentioned, Drive API would be much more reasonable instead.

Code:

new_title = 'hello-world'
file = {'title': new_title}
response = service.files().patch(fileId=file_id,
                                 body=file,
                                 fields='title').execute()

Reference:

Upvotes: 1

Related Questions