1
votes

I have tried Create, batchUpdate, get from https://developers.google.com/docs/api/how-tos/overview.

Even in batchUpdate I don't see option to edit title. I have used this to edit the contents of the document - insert/delete, but not title.

How can I edit a document title given that I have document id? Is there any way to edit document title using API?

1

1 Answers

2
votes

I believe your goal as follows.

  • You want to modify the title of Google Document.
    • Namely, you want to modify the filename of Google Document.

For this, how about this answer?

In order to modify the filename of Google Document, you can achieve this using the method of "Files: update" in Drive API. Unfortunately, Google Docs API cannot be used for modifying the filename of Google Document.

Endpoint:

PATCH https://www.googleapis.com/drive/v3/files/fileId

Sample request body:

{"name":"updated title"}

Sample curl:

curl --request PATCH \
  'https://www.googleapis.com/drive/v3/files/{documentId}' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{"name":"updated title"}' \
  --compressed

Reference:

Added:

When you want to request using the browser, you can use this quickstart for authorization and Files: update for modifying the title. As a sample script, I show you the sample script of the method of Files: update for Javascript as follows. Please use the authorization script from the quickstart.

Sample script:

gapi.client.drive.files.update({
  fileId: fileId,
  resource: {name: "updated title"},
}).then((response) => {
  console.log(response);
});