Remove a label from a file Stay organized with collections Save and categorize content based on your preferences.
This page describes how to remove a label on a single Google Drive file.
To remove the file label metadata from a file, use thefiles.modifyLabels method. Therequest bodycontains an instance ofModifyLabelsRequestto modify the set of labels on a file. The request might contain severalmodifications that are applied atomically. That is, if any modifications aren'tvalid, then the entire update is unsuccessful and none of the (potentiallydependent) changes are applied.
TheModifyLabelsRequest contains an instance ofLabelModificationwhich is a modification to a label on a file. It might also contain an instanceofFieldModificationwhich is a modification to a label's field. To remove the label from the file,setFieldModification.removeLabel toTrue.
If successful, theresponsebody containsthe labels added or updated by the request. These exist within amodifiedLabels object of typeLabel.
Example
The following code sample shows how to use thelabelId to remove all fieldsassociated with the label using thefileId. For example, if a label containsboth text and user fields, removing a label deletesboth the text and user fields associated with the label. Whereas, unsetting the text field removes it from the label but leaves the user field untouched. For more information, seeUnset a label field on a file.
Java
ModifyLabelsRequestmodifyLabelsRequest=newModifyLabelsRequest().setLabelModifications(ImmutableList.of(newLabelModification().setLabelId("LABEL_ID").setRemoveLabel(true)));ModifyLabelsResponsemodifyLabelsResponse=driveService.files().modifyLabels("FILE_ID",modifyLabelsRequest).execute();Python
label_modification={'labelId':'LABEL_ID','removeLabel':True]}modified_labels=drive_service.files().modifyLabels(fileId="FILE_ID",body={'labelModifications':[label_modification]}).execute();Node.js
/*** Remove a label on a Drive file* @return{obj} updated label data**/asyncfunctionremoveLabel(){// Get credentials and build service// TODO (developer) - Use appropriate auth mechanism for your appconst{GoogleAuth}=require('google-auth-library');const{google}=require('googleapis');constauth=newGoogleAuth({scopes:'https://www.googleapis.com/auth/drive'});constservice=google.drive({version:'v3',auth});constlabelModification={'labelId':'LABEL_ID','removeLabel':True,};constlabelModificationRequest={'labelModifications':[labelModification],};try{constupdateResponse=awaitservice.files.modifyLabels({fileId:'FILE_ID',resource:labelModificationRequest,});returnupdateResponse;}catch(err){// TODO (developer) - Handle errorthrowerr;}Replace the following:
- LABEL_ID: The
labelIdof the label to modify. To locatethe labels on a file, use thefiles.listLabelsmethod. - FILE_ID: The
fileIdof the file for which the labels aremodified.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-11 UTC.