I’m working with a Google Docs file and need to programmatically update the name of a specific revision. I want to give it a custom label like “Release v2.0 - 20241215” or something similar.
I’m open to using any programming language (Python, JavaScript, etc.) or direct REST API calls. Even if I can only rename the most recent revision, that would work for my needs.
I already have code that retrieves all document revisions, but I’m stuck on the actual renaming part. Here’s what I’m using to fetch the revision list:
import os
from google.oauth2 import service_account
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
def fetch_document_revisions(document_id):
CREDENTIALS_FILE = 'credentials.json'
STORAGE_PATH = 'files'
target_folder = os.path.join(STORAGE_PATH, document_id)
if not os.path.exists(target_folder):
os.makedirs(target_folder)
# setup authentication using service account
creds = service_account.Credentials.from_service_account_file(
CREDENTIALS_FILE,
scopes=['https://www.googleapis.com/auth/documents',
'https://www.googleapis.com/auth/drive']
)
# create Drive API client (v2 required)
api_client = build('drive', 'v2', credentials=creds)
try:
# retrieve all revisions for the document
revision_list = api_client.revisions().list(fileId=document_id).execute()
print(f"Found {len(revision_list['items'])} revisions for document {document_id}")
except HttpError as err:
print(f"Error occurred: {err}")
raise err
if __name__ == '__main__':
doc_id = "1U_Be02ViQp0UKPYNQo184ks4Vv-ey8mNoawJtTyC1R8"
fetch_document_revisions(doc_id)
I’ve searched through the API documentation but haven’t found a method to actually modify revision names. Has anyone successfully done this before?