Revisions: update

Stay organized with collections Save and categorize content based on your preferences.

Updates a revision. Try it now or see an example.

Request

HTTP request

PUT https://www.googleapis.com/drive/v2/files/fileId/revisions/revisionId

Parameters

Parameter name Value Description
Path parameters
fileId string The ID for the file.
revisionId string The ID for the revision.

Authorization

This request requires authorization with at least one of the following scopes:

Scope
https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/drive.file
https://www.googleapis.com/auth/drive.appdata

Some scopes are restricted and require a security assessment for your app to use them. For more information, see the authentication and authorization page.

Request body

In the request body, supply a Revisions resource with the following properties:

Property name Value Description Notes
Optional Properties
pinned boolean Whether this revision is pinned to prevent automatic purging. If not set, the revision is automatically purged 30 days after newer content is uploaded. This field can only be modified on files with content stored in Drive, excluding Docs Editors files. Revisions can also be pinned when they are created through the drive.files.insert/update/copy by using the pinned query parameter. Pinned revisions are stored indefinitely using additional storage quota, up to a maximum of 200 revisions. writable
publishAuto boolean Whether subsequent revisions will be automatically republished. This is only populated and can only be modified for Docs Editors files. writable
published boolean Whether this revision is published. This is only populated and can only be modified for Docs Editors files. writable
publishedOutsideDomain boolean Whether this revision is published outside the domain. This is only populated and can only be modified for Docs Editors files. writable

Response

If successful, this method returns a Revisions resource in the response body.

Examples

Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).

Java

Uses the Java client library.

import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.Revision;

import java.io.IOException;
// ...

public class MyClass {

  // ...

  /**
   * Pin a revision.
   *
   * @param service Drive API service instance.
   * @param fileId ID of the file to update revision for.
   * @param revisionId ID of the revision to update.
   * @return The updated revision if successful, {@code null} otherwise.
   */
  private static Revision updateRevision(Drive service, String fileId,
      String revisionId) {
    try {
      // First retrieve the revision from the API.
      Revision revision = service.revisions().get(
          fileId, revisionId).execute();
      revision.setPinned(true);
      return service.revisions().update(
          fileId, revisionId, revision).execute();
    } catch (IOException e) {
      System.out.println("An error occurred: " + e);
    }
    return null;
  }

  // ...

}

.NET

Uses the .NET client library.

using Google.Apis.Drive.v2;
using Google.Apis.Drive.v2.Data;

using System.Net;
// ...

public class MyClass {

  // ...

  /// <summary>
  /// Pin a revision.
  /// </summary>
  /// <param name="service">Drive API service instance.</param>
  /// <param name="fileId">ID of the file to update revision for.</param>
  /// <param name="revisionId">ID of the revision to update.</param>
  /// <returns>The updated revision, null is returned if an API error occurred</returns>
  public static Revision UpdateRevision(DriveService service, String fileId,
      String revisionId) {
    try {
      // First retrieve the revision from the API.
      Revision revision = service.Revisions.Get(fileId, revisionId).Execute();
      revision.Pinned = true;
      return service.Revisions.Update(revision, fileId, revisionId).Execute();
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    }
    return null;
  }

  // ...

}

PHP

Uses the PHP client library.

/**
 * Pin a revision.
 *
 * @param Google_Service_Drive $service Drive API service instance.
 * @param String $fileId ID of the file to update revision for.
 * @param String $revisionId ID of the revision to update.
 * @return Google_Servie_Drive_Revision The updated revision. NULL is returned
 *     if an API error occurred.
 */
function updateRevision($service, $fileId, $revisionId) {
  try {
    // First retrieve the revision from the API.
    $revision = $service->revisions->get($fileId, $revisionId);
    $revision->setPinned(true);
    return $service->revisions->update($fileId, $revisionId, $revision);
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  }
  return NULL;
}

Python

Uses the Python client library.

from apiclient import errors
# ...

def update_revision(service, file_id, revision_id):
  """Pin a revision.

  Args:
    service: Drive API service instance.
    file_id: ID of the file to update revision for.
    revision_id: ID of the revision to update.

  Returns:
    The updated revision if successful, None otherwise.
  """
  try:
    # First retrieve the revision from the API.
    revision = service.revisions().get(
        fileId=file_id, revisionId=revision_id).execute()
    revision['pinned'] = True
    return service.revisions().update(
        fileId=file_id, revisionId=revision_id, body=revision).execute()
  except errors.HttpError, error:
    print 'An error occurred: %s' % error
  return None

JavaScript

Uses the JavaScript client library.

/**
 * Pin a revision.
 *
 * @param {String} fileId ID of the file to update revision for.
 * @param {String} revisionId ID of the revision to update.
 */
function updateRevision(fileId, revisionId) {
  // First retrieve the permission from the API.
  var request = gapi.client.drive.revisions.get({
    'fileId': fileId,
    'revisionId': revisionId
  });
  request.execute(function(resp) {
    resp.pinned = true;
    var updateRequest = gapi.client.drive.revisions.update({
      'fileId': fileId,
      'revisionId': revisionId,
      'resource': resp
    });
    updateRequest.execute(function(resp) { });
  });
}

Go

Uses the Go client library.

import (
  "google.golang.org/drive/v2"
  "fmt"
)

// UpdateRevision fetches and updates a revision to be pinned
func UpdateRevision(d *drive.Service, fileId string, revisionId string,
    role string) error {
  r, err := d.Revisions.Get(fileId, revisionId).Do()
  if err != nil {
    fmt.Printf("An error occurred: %v\n", err)
    return err
  }
  r.Pinned = true
  _, err = d.Revisions.Update(fileId, revisionId, r).Do()
  if err != nil {
    fmt.Printf("An error occurred: %v\n", err)
    return err
  }
  return nil
}

Objective-C

Uses the Objective-C client library.

#import "GTLDrive.h"
// ...

+ (void)updateRevisionWithService:(GTLServiceDrive *)service
                           fileId:(NSString *)fileId
                       revisionId:(NSString *)revisionId
                  completionBlock:(void (^)(GTLDriveRevision*, NSError *))completionBlock {
  GTLQueryDrive *getQuery =
    [GTLQueryDrive queryForRevisionsGetWithFileId:fileId
                                       revisionId:revisionId];
  // queryTicket can be used to track the status of the request.
  GTLServiceTicket *queryTicket =
    [service executeQuery:getQuery
        completionHandler:^(GTLServiceTicket *ticket,
                            GTLDriveRevision *revision, NSError *error) {
          if (error == nil) {
            revision.pinned = @YES;
            GTLQueryDrive *updateQuery =
              [GTLQueryDrive queryForRevisionsUpdateWithObject:revision
                                                      fileId:fileId
                                                  revisionId:revisionId];
            // executeQuery returns a ticket object that can be used to track
            // progress of the request.
            [service executeQuery:updateQuery
                completionHandler:^(GTLServiceTicket *ticket,
                                    GTLDriveRevision *revision, NSError *error) {
                  if (error == nil) {
                    completionBlock(revision, nil);
                  } else {
                    NSLog(@"An error occurred: %@", error);
                    completionBlock(nil, error);
                  }
                }];
          } else {
            NSLog(@"An error occurred: %@", error);
            completionBlock(nil, error);
          }
        }];
}

// ...

Try it!

Use the APIs Explorer below to call this method on live data and see the response.