Files: untrash

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

Restores a file from the trash. The currently authenticated user must own the file or be at least a fileOrganizer on the parent for shared drive files. Only the owner may untrash a file. Try it now or see an example.


HTTP request



Parameter name Value Description
Path parameters
fileId string The ID of the file to untrash.
Optional query parameters
includeLabels string A comma-separated list of IDs of labels to include in the labelInfo part of the response.
includePermissionsForView string Specifies which additional view's permissions to include in the response. Only 'published' is supported.
supportsAllDrives boolean Whether the requesting application supports both My Drives and shared drives. (Default: false)
supportsTeamDrives boolean Deprecated use supportsAllDrives instead. (Default: false)


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


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

Do not supply a request body with this method.


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


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).


Uses the Java client library.


// ...

public class MyClass {

  // ...

   * Restore a file from the trash.
   * @param service Drive API service instance.
   * @param fileId ID of the file to restore.
   * @return The updated file if successful, {@code null} otherwise.
  private static File restoreFile(Drive service, String fileId) {
    try {
      return service.files().untrash(fileId).execute();
    } catch (IOException e) {
      System.out.println("An error occurred: " + e);
    return null;

  // ...



Uses the .NET client library.

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

using System.Net;
// ...

public class MyClass {

  // ...

  /// <summary>
  /// Restore a file from the trash.
  /// </summary>
  /// <param name="service">Drive API service instance.</param>
  /// <param name="fileId">ID of the file to restore.</param>
  /// <returns>The updated file, null is returned if an API error occurred</returns>
  public static File RestoreFile(DriveService service, String fileId) {
    try {
      return service.Files.Untrash(fileId).Execute();
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    return null;

  // ...



Uses the PHP client library.

 * Restore a file from the trash.
 * @param Google_Service_Drive $service Drive API service instance.
 * @param String $fileId ID of the file to restore.
 * @return Google_Servie_Drive_DriveFile The updated file. NULL is returned if
 *     an API error occurred.
function restoreFile($service, $fileId) {
  try {
    return $service->files->untrash($fileId);
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  return NULL;


Uses the Python client library.

from apiclient import errors
# ...

def restore_file(service, file_id):
  """Restore a file from the trash.

    service: Drive API service instance.
    file_id: ID of the file to restore.

    The updated file if successful, None otherwise.
    return service.files().untrash(fileId=file_id).execute()
  except errors.HttpError, error:
    print 'An error occurred: %s' % error
  return None


Uses the JavaScript client library.

 * Restore a file from the trash.
 * @param {String} fileId ID of the file to restore.
function restoreFile(fileId) {
  var request ={
    'fileId': fileId
  request.execute(function(resp) { });


Uses the Go client library.

import (

// RestoreFile restores a file from the trash
func RestoreFile(d *drive.Service, fileId string) (*drive.File, error) {
  r, err := d.Files.Untrash(fileId).Do()
  if err != nil {
    fmt.Printf("An error occurred: %v\n", err)
    return nil, err
  return r, nil


Uses the Objective-C client library.

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

+ (void)restoreFileWithService:(GTLServiceDrive *)service
                        fileId:(NSString *)fileId
               completionBlock:(void (^)(GTLDriveFile*, NSError *))completionBlock {
  GTLQueryDrive *query = [GTLQueryDrive queryForFilesUntrashWithFileId:fileId];
  // queryTicket can be used to track the status of the request.
  GTLServiceTicket *queryTicket =
    [service executeQuery:query
        completionHandler:^(GTLServiceTicket *ticket, GTLDriveFile *file,
                            NSError *error) {
          if (error == nil) {
            completionBlock(file, nil);
          } 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.