gas-types-detailed
Version:
Enhanced Google Apps Script Type Definitions with detailed documentation. Includes type definitions plus code snippets, return values, required authorization scopes, and other details not found in @types/google-apps-script.
1,156 lines (1,099 loc) • 131 kB
TypeScript
// Type definitions for Google Apps Script 2025-11-10
// Project: https://developers.google.com/apps-script/
// Definitions by: motemen <https://github.com/motemen/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="google-apps-script.types.d.ts" />
/// <reference path="google-apps-script.base.d.ts" />
declare namespace GoogleAppsScript {
namespace Drive {
/**
* An enum representing classes of users who can access a file or folder, besides any individual
* users who have been explicitly given access. These properties can be accessed from DriveApp.Access.
*
* To call an enum, you call its parent class, name, and property. For example,
* DriveApp.Access.ANYONE.
*
* // Creates a folder that anyone on the Internet can read from and write to.
* // (Domain administrators can prohibit this setting for users of a Google
* // Workspace domain.)
* const folder = DriveApp.createFolder('Shared Folder');
* folder.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.EDIT);
*/
enum Access { ANYONE, ANYONE_WITH_LINK, DOMAIN, DOMAIN_WITH_LINK, PRIVATE }
/**
* Allows scripts to create, find, and modify files and folders in Google Drive. Although the
* built-in Drive service is easier to use, it has some limitations. For the most up-to-date
* features and support, and to access files or folders in shared drives, use the advanced Drive service.
*
* // Logs the name of every file in the user's Drive.
* const files = DriveApp.getFiles();
* while (files.hasNext()) {
* const file = files.next();
* console.log(file.getName());
* }
*/
interface DriveApp {
Access: typeof Access;
Permission: typeof Permission;
/**
* Resumes a file iteration using a continuation token from a previous iterator. This method is useful if processing an iterator in one execution exceeds the maximum execution time. Continuation tokens are generally valid for one week.
*
* // Continues getting a list of all 'Untitled document' files in the user's
* // Drive. Creates a file iterator named 'previousIterator'.
* const previousIterator = DriveApp.getFilesByName('Untitled document');
*
* // Gets continuation token from the previous file iterator.
* const continuationToken = previousIterator.getContinuationToken();
*
* // Creates a new iterator using the continuation token from the previous file
* // iterator.
* const newIterator = DriveApp.continueFileIterator(continuationToken);
*
* // Resumes the file iteration using a continuation token from 'firstIterator'
* // and logs the file name.
* if (newIterator.hasNext()) {
* const file = newIterator.next();
* console.log(file.getName());
* }
*
* Return:
* - FileIterator — A collection of files that remained in a previous iterator when the continuation token was generated.
*
* https://developers.google.com/apps-script/reference/drive/drive-app#continueFileIterator(String)
* @param continuationToken A continuation token from a previous file iterator.
*/
continueFileIterator(continuationToken: string): FileIterator;
/**
* Resumes a folder iteration using a continuation token from a previous iterator. This method is useful if processing an iterator in one execution exceeds the maximum execution time. Continuation tokens are generally valid for one week.
*
* // Continues getting a list of all folders in user's Drive.
* // Creates a folder iterator named 'previousIterator'.
* const previousIterator = DriveApp.getFolders();
*
* // Gets continuation token from the previous folder iterator.
* const continuationToken = previousIterator.getContinuationToken();
*
* // Creates a new iterator using the continuation token from the previous folder
* // iterator.
* const newIterator = DriveApp.continueFolderIterator(continuationToken);
*
* // Resumes the folder iteration using a continuation token from the previous
* // iterator and logs the folder name.
* if (newIterator.hasNext()) {
* const folder = newIterator.next();
* console.log(folder.getName());
* }
*
* Return:
* - FolderIterator — A collection of folders that remained in a previous iterator when the continuation token was generated.
*
* https://developers.google.com/apps-script/reference/drive/drive-app#continueFolderIterator(String)
* @param continuationToken A continuation token from a previous folder iterator.
*/
continueFolderIterator(continuationToken: string): FolderIterator;
/**
* Creates a file in the root of the user's Drive from a given Blob of arbitrary data.
*
* Return:
* - File — The new file.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#createFile(BlobSource)
* @param blob The data for the new file.
*/
createFile(blob: Base.BlobSource): File;
/**
* Creates a text file in the root of the user's Drive with the given name and contents. Throws an exception if content is larger than 50 MB.
*
* // Create a text file with the content "Hello, world!"
* DriveApp.createFile('New Text File', 'Hello, world!');
*
* Return:
* - File — The new file.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#createFile(String,String)
* @param name The name of the new file.
* @param content The content for the new file.
*/
createFile(name: string, content: string): File;
/**
* Creates a file in the root of the user's Drive with the given name, contents, and MIME type. Throws an exception if content is larger than 10MB.
*
* // Create an HTML file with the content "Hello, world!"
* DriveApp.createFile('New HTML File', '<b>Hello, world!</b>', MimeType.HTML);
*
* Return:
* - File — The new file.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#createFile(String,String,String)
* @param name The name of the new file.
* @param content The content for the new file.
* @param mimeType The MIME type of the new file.
*/
createFile(name: string, content: string, mimeType: string): File;
/**
* Creates a folder in the root of the user's Drive with the given name.
*
* Return:
* - Folder — The new folder.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#createFolder(String)
* @param name The name of the new folder.
*/
createFolder(name: string): Folder;
/**
* Creates a shortcut to the provided Drive item ID, and returns it.
*
* Return:
* - File — The new shortcut.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#createShortcut(String)
* @param targetId The file ID of the target file or folder.
*/
createShortcut(targetId: string): File;
/**
* Creates a shortcut to the provided Drive item ID and resource key, and returns it. A resource key is an additional parameter that needs to be passed to access the target file or folder that has been shared using a link.
*
* // Creates shortcuts for all folders in the user's drive that have a specific
* // name.
* // TODO(developer): Replace 'Test-Folder' with a valid folder name in your
* // drive.
* const folders = DriveApp.getFoldersByName('Test-Folder');
*
* // Iterates through all folders named 'Test-Folder'.
* while (folders.hasNext()) {
* const folder = folders.next();
*
* // Creates a shortcut to the provided Drive item ID and resource key, and
* // returns it.
* DriveApp.createShortcutForTargetIdAndResourceKey(
* folder.getId(),
* folder.getResourceKey(),
* );
* }
*
* Return:
* - File — The new shortcut.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#createShortcutForTargetIdAndResourceKey(String,String)
* @param targetId The ID of the target file or folder.
* @param targetResourceKey The resource key of the target file or folder.
*/
createShortcutForTargetIdAndResourceKey(targetId: string, targetResourceKey: string): File;
/**
* Enables or disables enforceSingleParent behavior for all calls affecting item parents.
* See the Simplifying Google Drive’s folder structure and sharing models blog for more details.
*
* // Enables enforceSingleParent behavior for all calls affecting item parents.
* DriveApp.enforceSingleParent(true);
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#enforceSingleParent(Boolean)
* @param value The new state of the enforceSingleParent flag.
*/
enforceSingleParent(value: boolean): void;
/**
* Gets the file with the given ID. Throws a scripting exception if the file does not exist or the user does not have permission to access it.
*
* // Gets a list of all files in Google Drive with the given name.
* // TODO(developer): Replace 'Test' with your file name.
* const files = DriveApp.getFilesByName('Test');
*
* if (files.hasNext()) {
* // Gets the ID of each file in the list.
* const fileId = files.next().getId();
*
* // Gets the file name using its ID and logs it to the console.
* console.log(DriveApp.getFileById(fileId).getName());
* }
*
* Return:
* - File — The file with the given ID.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#getFileById(String)
* @param id The ID of the file.
*/
getFileById(id: string): File;
/**
* Gets the file with the given ID and resource key. Resource keys are an additional parameter which need to be passed to access files that have been shared using a link.
* Throws a scripting exception if the file doesn't exist or the user doesn't have permission to access it.
*
* // Gets a list of all files in Drive with the given name.
* // TODO(developer): Replace 'Test' with your file name.
* const files = DriveApp.getFilesByName('Test');
* if (files.hasNext()) {
* // Gets the first file in the list.
* const file = files.next();
*
* // Gets the ID and resource key.
* const key = file.getResourceKey();
* const id = file.getId();
*
* // Logs the file name to the console using its ID and resource key.
* console.log(DriveApp.getFileByIdAndResourceKey(id, key).getName());
* }
*
* Return:
* - File — The file with the given ID.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#getFileByIdAndResourceKey(String,String)
* @param id The ID of the file.
* @param resourceKey The resource key of the folder.
*/
getFileByIdAndResourceKey(id: string, resourceKey: string): File;
/**
* Gets a collection of all files in the user's Drive.
*
* Return:
* - FileIterator — A collection of all files in the user's Drive.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#getFiles()
*/
getFiles(): FileIterator;
/**
* Gets a collection of all files in the user's Drive that have the given name.
*
* Return:
* - FileIterator — A collection of all files in the user's Drive that have the given name.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#getFilesByName(String)
* @param name The name of the files to find.
*/
getFilesByName(name: string): FileIterator;
/**
* Gets a collection of all files in the user's Drive that have the given MIME type.
*
* Return:
* - FileIterator — A collection of all files in the user's Drive that have the given MIME type.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#getFilesByType(String)
* @param mimeType The MIME type of the files to find.
*/
getFilesByType(mimeType: string): FileIterator;
/**
* Gets the folder with the given ID. Throws a scripting exception if the folder does not exist or the user does not have permission to access it.
*
* Return:
* - Folder — The folder with the given ID.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#getFolderById(String)
* @param id The ID of the folder.
*/
getFolderById(id: string): Folder;
/**
* Gets the folder with the given ID and resource key. Resource keys are an additional parameter which need to be passed to access folders that have been shared using a link.
* Throws a scripting exception if the folder doesn't exist or the user doesn't have permission to access it.
*
* Return:
* - Folder — The folder with the given ID.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#getFolderByIdAndResourceKey(String,String)
* @param id The ID of the folder.
* @param resourceKey The resource key of the folder.
*/
getFolderByIdAndResourceKey(id: string, resourceKey: string): Folder;
/**
* Gets a collection of all folders in the user's Drive.
*
* Return:
* - FolderIterator — A collection of all folders in the user's Drive.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#getFolders()
*/
getFolders(): FolderIterator;
/**
* Gets a collection of all folders in the user's Drive that have the given name.
*
* Return:
* - FolderIterator — A collection of all folders in the user's Drive that have the given name.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#getFoldersByName(String)
* @param name The name of the folders to find.
*/
getFoldersByName(name: string): FolderIterator;
/**
* Gets the folder at the root of the user's Drive.
*
* // Gets the user's My Drive folder and logs its name to the console.
* console.log(DriveApp.getRootFolder().getName());
*
* // Logs the Drive owner's name to the console.
* console.log(DriveApp.getRootFolder().getOwner().getName());
*
* Return:
* - Folder — The root folder of the user's Drive.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#getRootFolder()
*/
getRootFolder(): Folder;
/**
* Gets the number of bytes the user is allowed to store in Drive.
*
* // Gets the number of bytes the user can store in Drive and logs it to the
* // console.
* console.log(DriveApp.getStorageLimit());
*
* Return:
* - Integer — The number of bytes the user is allowed to store in Drive.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#getStorageLimit()
*/
getStorageLimit(): Integer;
/**
* Gets the number of bytes the user is currently storing in Drive.
*
* // Gets the number of bytes the user is currently storing in Drive and logs it
* // to the console.
* console.log(DriveApp.getStorageUsed());
*
* Return:
* - Integer — The number of bytes the user is currently storing in Drive.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#getStorageUsed()
*/
getStorageUsed(): Integer;
/**
* Gets a collection of all the files in the trash of the user's Drive.
*
* // Gets a list of all the files in the trash of the user's Drive.
* const trashFiles = DriveApp.getTrashedFiles();
*
* // Logs the trash file names to the console.
* while (trashFiles.hasNext()) {
* const file = trashFiles.next();
* console.log(file.getName());
* }
*
* Return:
* - FileIterator — A collection of files in the trash.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#getTrashedFiles()
*/
getTrashedFiles(): FileIterator;
/**
* Gets a collection of all the folders in the trash of the user's Drive.
*
* // Gets a collection of all the folders in the trash of the user's Drive.
* const trashFolders = DriveApp.getTrashedFolders();
*
* // Logs the trash folder names to the console.
* while (trashFolders.hasNext()) {
* const folder = trashFolders.next();
* console.log(folder.getName());
* }
*
* Return:
* - FolderIterator — A collection of folders in the trash.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#getTrashedFolders()
*/
getTrashedFolders(): FolderIterator;
/**
* Gets a collection of all files in the user's Drive that match the given search criteria. The search criteria are detailed in the Google Drive SDK documentation. Note that the Drive service uses v2 of the Drive API and some query fields differ from v3. Review the field differences between v2 and v3.
* The params argument is a query string that can contain string values, so take care to escape quotation marks correctly (for example "title contains 'Gulliver\\'s Travels'" or 'title contains "Gulliver\'s Travels"').
*
* // Logs the name of every file in the user's Drive that modified after February 28,
* // 2022 whose name contains "untitled.""
* const files = DriveApp.searchFiles(
* 'modifiedDate > "2022-02-28" and title contains "untitled"');
* while (files.hasNext()) {
* const file = files.next();
* console.log(file.getName());
* }
*
* Return:
* - FileIterator — A collection of all files in the user's Drive that match the search criteria.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#searchFiles(String)
* @param params The search criteria, as detailed in the Google Drive SDK documentation.
*/
searchFiles(params: string): FileIterator;
/**
* Gets a collection of all folders in the user's Drive that match the given search criteria. The search criteria are detailed in the Google Drive SDK documentation. Note that the Drive service uses v2 of the Drive API and some query fields differ from v3. Review the field differences between v2 and v3.
* The params argument is a query string that can contain string values, so take care to escape quotation marks correctly (for example "title contains 'Gulliver\\'s Travels'" or 'title contains "Gulliver\'s Travels"').
*
* // Logs the name of every folder in the user's Drive that you own and is starred.
* const folders = DriveApp.searchFolders('starred = true and "me" in owners');
* while (folders.hasNext()) {
* const folder = folders.next();
* console.log(folder.getName());
* }
*
* Return:
* - FolderIterator — A collection of all folders in the user's Drive that match the search criteria.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/drive-app#searchFolders(String)
* @param params The search criteria, as detailed in the Google Drive SDK documentation.
*/
searchFolders(params: string): FolderIterator;
/** @deprecated DO NOT USE */ addFile(child: File): Folder;
/** @deprecated DO NOT USE */ addFolder(child: Folder): Folder;
/** @deprecated DO NOT USE */ removeFile(child: File): Folder;
/** @deprecated DO NOT USE */ removeFolder(child: Folder): Folder;
}
/**
* A file in Google Drive. Files can be accessed or created from DriveApp.
*
* // Trash every untitled spreadsheet that hasn't been updated in a week.
* const files = DriveApp.getFilesByName('Untitled spreadsheet');
* while (files.hasNext()) {
* const file = files.next();
* if (new Date() - file.getLastUpdated() > 7 * 24 * 60 * 60 * 1000) {
* file.setTrashed(true);
* }
* }
*/
interface File {
/**
* Add the given user to the list of commenters for the File. If the user was already on the list of viewers, this method promotes the user out of the list of viewers.
*
* const files = DriveApp.getFilesByName('Test');
*
* // Loops through the files
* while (files.hasNext()) {
* const file = files.next();
* file.addCommenter('hello@example.com');
* }
*
* Return:
* - File — This File, for chaining.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#addCommenter(String)
* @param emailAddress The email address of the user to add.
*/
addCommenter(emailAddress: string): File;
/**
* Add the given user to the list of commenters for the File. If the user was already on the list of viewers, this method promotes the user out of the list of viewers.
*
* // Gets a list of all files in Google Drive with the given name.
* // TODO(developer): Replace the file name with your own.
* const files = DriveApp.getFilesByName('Test');
*
* // Adds the active user as a commenter.
* while (files.hasNext()) {
* const file = files.next();
* file.addCommenter(Session.getActiveUser());
* }
*
* Return:
* - File — This File, for chaining.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#addCommenter(User)
* @param user A representation of the user to add.
*/
addCommenter(user: Base.User): File;
/**
* Add the given array of users to the list of commenters for the File. If any of the users were already on the list of viewers, this method promotes them out of the list of viewers.
*
* // Gets a list of all files in Google Drive with the given name.
* // TODO(developer): Replace the file name with your own.
* const files = DriveApp.getFilesByName('Test');
*
* while (files.hasNext()) {
* const file = files.next();
* // TODO(developer): Replace 'cloudysanfrancisco@gmail.com' and
* // 'baklavainthebalkans@gmail.com' with the email addresses to add as
* // commenters.
* const emails = [
* 'cloudysanfrancisco@gmail.com',
* 'baklavainthebalkans@gmail.com',
* ];
* console.log(file.addCommenters(emails));
* }
*
* Return:
* - File — This File, for chaining.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#addCommenters(String)
* @param emailAddresses An array of email addresses of the users to add.
*/
addCommenters(emailAddresses: string[]): File;
/**
* Adds the given user to the list of editors for the File. If the user was already on the list of viewers, this method promotes the user out of the list of viewers.
*
* Return:
* - File — This File, for chaining.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#addEditor(String)
* @param emailAddress The email address of the user to add.
*/
addEditor(emailAddress: string): File;
/**
* Adds the given user to the list of editors for the File. If the user was already on the list of viewers, this method promotes the user out of the list of viewers.
*
* Return:
* - File — This File, for chaining.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#addEditor(User)
* @param user A representation of the user to add.
*/
addEditor(user: Base.User): File;
/**
* Adds the given array of users to the list of editors for the File. If any of the users were already on the list of viewers, this method promotes them out of the list of viewers.
*
* Return:
* - File — This File, for chaining.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#addEditors(String)
* @param emailAddresses An array of email addresses of the users to add.
*/
addEditors(emailAddresses: string[]): File;
/**
* Adds the given user to the list of viewers for the File. If the user was already on the list of editors, this method has no effect.
*
* Return:
* - File — This File, for chaining.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#addViewer(String)
* @param emailAddress The email address of the user to add.
*/
addViewer(emailAddress: string): File;
/**
* Adds the given user to the list of viewers for the File. If the user was already on the list of editors, this method has no effect.
*
* Return:
* - File — This File, for chaining.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#addViewer(User)
* @param user A representation of the user to add.
*/
addViewer(user: Base.User): File;
/**
* Adds the given array of users to the list of viewers for the File. If any of the users were already on the list of editors, this method has no effect for them.
*
* Return:
* - File — This File, for chaining.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#addViewers(String)
* @param emailAddresses An array of email addresses of the users to add.
*/
addViewers(emailAddresses: string[]): File;
/**
* Gets the permission granted to a specific user. The method doesn't support returning permissions for a Google Group or permissions inherited through Google Groups.
*
* Return:
* - Permission — The permissions granted to the user.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#getAccess(String)
* @param email The email address of the user whose permissions should be checked. Google Groups aren't supported.
*/
getAccess(email: string): Permission;
/**
* Gets the permission granted to a specific user. The method doesn't support returning permissions for a Google Group or permissions inherited through Google Groups.
*
* Return:
* - Permission — The permissions granted to the user.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#getAccess(User)
* @param user A representation of the user whose permissions should be checked.
*/
getAccess(user: Base.User): Permission;
/**
* Return the data inside this object as a blob converted to the specified content type. This method adds the appropriate extension to the filename—for example, "myfile.pdf". However, it assumes that the part of the filename that follows the last period (if any) is an existing extension that should be replaced. Consequently, "ShoppingList.12.25.2014" becomes "ShoppingList.12.25.pdf".
* To view the daily quotas for conversions, see Quotas for Google Services. Newly created Google Workspace domains might be temporarily subject to stricter quotas.
*
* Return:
* - Blob — The data as a blob.
*
* https://developers.google.com/apps-script/reference/drive/file#getAs(String)
* @param contentType The MIME type to convert to. For most blobs, 'application/pdf' is the only valid option. For images in BMP, GIF, JPEG, or PNG format, any of 'image/bmp', 'image/gif', 'image/jpeg', or 'image/png' are also valid. For a Google Docs document, 'text/markdown' is also valid.
*/
getAs(contentType: string): Base.Blob;
/**
* Return the data inside this object as a blob.
*
* Return:
* - Blob — The data as a blob.
*
* https://developers.google.com/apps-script/reference/drive/file#getBlob()
*/
getBlob(): Base.Blob;
/**
* Gets the date the File was created.
*
* Return:
* - Date — the date the File was created
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#getDateCreated()
*/
getDateCreated(): Date;
/**
* Gets the description for the File.
*
* Return:
* - String — the description for the File
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#getDescription()
*/
getDescription(): string;
/**
* Gets the URL that can be used to download the file. Only users with permission to open the file in Google Drive can access the URL. You can use this URL in a browser to download the file, but you can't use to fetch the file with UrlFetchApp. If you want the contents of the file in the script, use getBlob().
*
* // Gets a list of all files in Google Drive with the given name.
* // TODO(developer): Replace the file name with your own.
* const files = DriveApp.getFilesByName('Test');
*
* // Loops through the files and logs the download URLs to the console.
* while (files.hasNext()) {
* const file = files.next();
* console.log(file.getDownloadUrl());
* }
*
* Return:
* - String — The URL that can be used to download the file.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#getDownloadUrl()
*/
getDownloadUrl(): string;
/**
* Gets the list of editors for this File. If the user who executes the script does not have edit access to the File, this method returns an empty array.
*
* // Gets a list of all files in Google Drive with the given name.
* // TODO(developer): Replace the file name with your own.
* const files = DriveApp.getFilesByName('Test');
*
* // Loops through the files.
* while (files.hasNext()) {
* const file = files.next();
*
* // Adds the email addresses in the array as editors of each file.
* // TODO(developer): Replace 'cloudysanfrancisco@gmail.com'
* // and 'baklavainthebalkans@gmail.com' with valid email addresses.
* file.addEditors([
* 'cloudysanfrancisco@gmail.com',
* 'baklavainthebalkans@gmail.com',
* ]);
*
* // Gets a list of the file editors.
* const editors = file.getEditors();
*
* // For each file, logs the editors' email addresses to the console.
* for (const editor of editors) {
* console.log(editor.getEmail());
* }
* }
*
* Return:
* - User[] — If the user has edit access for this File, returns the list of editors. If the user doesn't have edit access, returns an empty array.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#getEditors()
*/
getEditors(): User[];
/**
* Gets the ID of the File.
*
* Return:
* - String — the ID of the File
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#getId()
*/
getId(): string;
/**
* Gets the date the File was last updated.
*
* Return:
* - Date — the date the File was last updated
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#getLastUpdated()
*/
getLastUpdated(): Date;
/**
* Gets the MIME type of the file.
*
* // Gets a list of all files in Google Drive with the given name.
* // TODO(developer): Replace the file name with your own.
* const files = DriveApp.getFilesByName('Test');
*
* // Loops through the files and logs the MIME type to the console.
* while (files.hasNext()) {
* const file = files.next();
* console.log(file.getMimeType());
* }
*
* Return:
* - String — The MIME type of the file.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#getMimeType()
*/
getMimeType(): string;
/**
* Gets the name of the File.
*
* Return:
* - String — the name of the File
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#getName()
*/
getName(): string;
/**
* Gets the file owner.
*
* // Gets a list of all files in Google Drive with the given name.
* // TODO(developer): Replace the file name with your own.
* const files = DriveApp.getFilesByName('Test');
*
* // Loops through the files and logs the names of the file owners to the console.
* while (files.hasNext()) {
* const file = files.next();
* console.log(file.getOwner().getName());
* }
*
* Return:
* - User — The file owner.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#getOwner()
*/
getOwner(): User;
/**
* Gets a collection of folders that are immediate parents of the File.
*
* Return:
* - FolderIterator — a collection of folders that are immediate parents of the File
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#getParents()
*/
getParents(): FolderIterator;
/**
* Gets the resource key of the File that is required to access items that have been shared using a link.
*
* Return:
* - String — The resource key of the File.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#getResourceKey()
*/
getResourceKey(): string;
/**
* Gets whether this File is eligible to apply the security update that requires a resource key for access when it's shared using a link.
* Drive requires a resource key to access some files or folders that have been shared using a link. This change is part of a security update. The update is turned on by default for eligible files and folders. To turn the resource key requirement on or off for eligible files, use setSecurityUpdateEnabled.
* Learn more about the Security update for Google Drive.
*
* Return:
* - Boolean — Whether the resource key requirement can be applied for the File.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#getSecurityUpdateEligible()
*/
getSecurityUpdateEligible(): boolean;
/**
* Gets whether this File requires a resource key for access when it's shared using a link. This requirement is turned on by default for eligible files and folders. To turn the resource key requirement on or off for eligible files, use setSecurityUpdateEnabled.
* Learn more about the Security update for Google Drive.
*
* Return:
* - Boolean — Whether the resource key requirement is enabled for this File.
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#getSecurityUpdateEnabled()
*/
getSecurityUpdateEnabled(): boolean;
/**
* Gets which class of users can access the File, besides any individual users who have been explicitly given access.
*
* Return:
* - Access — which class of users can access the File
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#getSharingAccess()
*/
getSharingAccess(): Access;
/**
* Gets the permission granted to those users who can access the File, besides any individual users who have been explicitly given access.
*
* Return:
* - Permission — the permissions granted to users who can access the File
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#getSharingPermission()
*/
getSharingPermission(): Permission;
/**
* Gets the number of bytes used to store the File in Drive. Note that Google Workspace application files do not count toward Drive storage limits and thus return 0 bytes.
*
* Return:
* - Integer — the number of bytes used to store the File in Drive
*
* Authorization:
*
* Scripts that use this method require authorization with one or more of the following scopes:
* - https://www.googleapis.com/auth/drive.readonly
* - https://www.googleapis.com/auth/drive
*
* https://developers.google.com/apps-script/reference/drive/file#getSize()
*/
getSize(): Integer;
/**
* If this is a Shortcut, returns the ID of the item it points to.
* Otherwise it returns null.
*
* // The ID of the fil