Properties: patch

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

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

Request

HTTP request

PATCH https://www.googleapis.com/drive/v2/files/fileId/properties/propertyKey

Parameters

Parameter name Value Description
Path parameters
fileId string The ID of the file.
propertyKey string The key of the property.
Optional query parameters
visibility string The visibility of the property. Allowed values are PRIVATE and PUBLIC. (Default: PRIVATE)

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
https://www.googleapis.com/auth/drive.metadata

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 the relevant portions of a Properties resource, according to the rules of patch semantics, with the following properties:

Property name Value Description Notes
Optional Properties
value string The value of this property. writable

Response

If successful, this method returns a Properties 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.Drive.Properties.Patch;
import com.google.api.services.drive.model.Property;

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

public class MyClass {

  // ...

  /**
   * Patch a custom property's value.
   *
   * @param service Drive API service instance.
   * @param fileId ID of the file to patch property for.
   * @param key ID of the property to patch.
   * @param newValue The new value for the property.
   * @param visibility The type of property ('PUBLIC' or 'PRIVATE').
   * @return The patched property's if successful, {@code null} otherwise.
   */
  private static Property patchProperty(
      Drive service, String fileId, String key, String newValue, String visibility) {
    Property patchedProperty = new Property();
    patchedProperty.setValue(newValue);
    try {
      Patch request = service.properties().patch(fileId, key, patchedProperty);
      request.setVisibility(visibility);
      return request.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>
  /// Patch a custom property's value.
  /// </summary>
  /// <param name="service">Drive API service instance.</param>
  /// <param name="fileId">ID of the file to patch property for.</param>
  /// <param name="key">ID of the property to patch.</param>
  /// <param name="newValue">The new value for the property.</param>
  /// <param name="visibility">The type of property ('PUBLIC' or 'PRIVATE').</param>
  /// <returns>The patched property, null is returned if an API error occurred</returns>
  public static Property PatchProperty(DriveService service, String fileId,
      String key, String newValue, PropertiesResource.Visibility visibility) {
    Property patchedProperty = new Property();
    patchedProperty.Value = newValue;
    try {
      PropertiesResource.PatchRequest request =
          service.Properties.Patch(patchedProperty, fileId, key);
      request.Visibility = visibility;
      return request.Execute();
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    }
    return null;
  }

  // ...

}

PHP

Uses the PHP client library.

/**
 * Patch a custom property's value.
 *
 * @param Google_Service_Drive $service Drive API service instance.
 * @param String $fileId ID of the file to patch property for.
 * @param String $key ID of the property to patch.
 * @param String $newValue The new value for the property.
 * @param String $visibility The type of property ('PUBLIC' or 'PRIVATE').
 * @return Google_Servie_Drive_Property The patched property. NULL is returned
 *     if an API error occurred.
 */
function patchProperty($service, $fileId, $key, $newValue, $visibility) {
  $patchedProperty = new Google_Service_Drive_Property();
  $patchedProperty->setValue($newValue);
  try {
    $optParams = array('visibility' => $visibility);
    return $service->properties->patch($fileId, $key, $patchedProperty, $optParams);
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  }
  return NULL;
}

Python

Uses the Python client library.

def patch_property(service, file_id, key, new_value, visibility):
  """Patch a custom property's value.

  Args:
    service: Drive API service instance.
    file_id: ID of the file to patch property for.
    key: ID of the property to patch.
    new_value: The new value for the property.
    visibility: type of property ('PUBLIC' or 'PRIVATE').

  Returns:
    The patched property if successful, None otherwise.
  """
  try:
    patched_property = {'value': new_value}
    return service.properties().patch(
        fileId=file_id,
        propertyKey=key,
        visibility=visibility,
        body=patched_property).execute()
  except errors.HttpError, error:
    print 'An error occurred: %s' % error
  return None

JavaScript

Uses the JavaScript client library.

/**
 * Patch a custom property's value.
 *
 * @param {String} fileId ID of the file to patch property for.
 * @param {String} key ID of the property to patch.
 * @param {String} newValue The new value for the property.
 * @param {String} visibility The type of property ('PUBLIC' or 'PRIVATE').
 */
function patchProperty(fileId, key, newValue, visibility) {
  var body = {'value': newValue};
  var request = gapi.client.drive.properties.patch({
    'fileId': fileId,
    'propertyKey': key,
    'visibility': visibility,
    'resource': body
  });
  request.execute(function(resp) {
    console.log('New Value: ' + resp.value);
  });
}

Try it!

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