Is it possible to create a new revision using google apps script or google drive api?

Viewed 104

Searched a bunch and found pages regarding list/get/update revisions, but nothing about actually making a new revision. Instructions made it sound like if I set published: true in the requestBody it would create a new revision for the current state of the file. Wrote some quick test code in node:

async function testGlg() {
await setupGoogleAuth()
const fileId = '1mVYwVAjDVcR-0bvxLaHzdToy6gx38B5Oe4CZhnRJuJo'
const r = await drive.revisions.list({
    fileId: fileId,
})
const revisions = r.data.revisions
const latestRevisionId = revisions[revisions.length-1].id
const w = await drive.revisions.update({
    fileId: fileId,
    revisionId: latestRevisionId,
    requestBody: {
        published: true,
    },
})

but that didn't appear to do anything. Also, I couldn't find a way to get the name of a revision as it's displayed in chrome or to set it via the api.

1 Answers

The Revisions API returns you the history of changes performed on a document

  • You cannot create a new revision with the Revisions API, since revisions are being created automatically in the background - as a response to a change in a document.

  • You can edit the document either via UI or - depending on the document type - with an API, like e.g. the Google Sheets API in case of spreadsheets

  • The method Revisions: update allows you to modify how an existing revision shall be handled (e.g. either it shall be kept forever), but it does not change the revision content.
Related