Download and publish file revisions

Google Drive API provides the Revisions resource so that you can download and publish file revisions. For more details about revision terminology, see Changes and revisions overview.

Specify revisions to save from auto delete

Google Drive automatically deletes older revisions that are no longer of interest to the user. To prevent this from happening, you can set the boolean flag keepRevisionForever to true to mark revisions that you don't want Drive to purge.

Download a revision

You can use the value of the headRevisionId field from the Files resource to download the latest revision. This fetches the revision that corresponds to the metadata of the file you previously retrieved. To download the data for all previous revisions of the file that are still stored in cloud, you can call revisions.list, which gets all the revisionIds.

To download the revision content, you need to call revisions.get method with the parameter alt=media. Revisions for Google Docs, Sheets, and Slides can't be downloaded.

Google Docs, Google Drawings, and Slides revisions auto-increment the revision numbers. However, series of numbers may have gaps if revisions are deleted, so you should not rely on sequential numbers when you retrieve revisions.

Publish a revision

To publish a Google Docs, Sheets, and Slides revision, you set the published property for that file in the Revisions property. This property can't be set for Google Sites revisions via the Drive API.

If the file is created in a Google Workspace domain, the publishedOutsideDomain property indicates whether the revision is accessible by anyone or if it is restricted to users of the domain. For Google Sites files, this property indicates whether a type=anyone permission exists.

Published revisions do not reflect changes made to a file unless the publishAuto property is set. If that property is set to true, newer revisions of a file will be automatically published, overwriting the previous ones. This behavior is also controlled by the "Automatically re-publish when changes are made" checkbox in the Drive UI. For Google Sites files, publishAuto is always false.