Create & publish a label

This page describes how to create and publish a label.

Create a label

To create a label, use thecreate method on thelabels collection. Labels canoptionally contain one or moreFields.

You also must specify:

  • ALabelType.

  • A labeltitle through theproperty method.

  • useAdminAccess istrue to use the user's administrator credentials. Theserver verifies that the user is an admin with the "Manage Labels" privilegebefore allowing access.

This example creates a standard, admin label with a specified title and oneSelectionOptionsField with 2Choices.

Python

label_body={'label_type':'ADMIN','properties':{'title':'TITLE'},'fields':[{'properties':{'display_name':'DISPLAY_NAME'},'selection_options':{'list_options':{},'choices':[{'properties':{'display_name':'CHOICE_1'}},{'properties':{'display_name':'CHOICE_2'}}]}}]}response=service.labels().create(body=label_body,useAdminAccess=True).execute()

Node.js

varlabel={'label_type':'ADMIN','properties':{'title':'TITLE'},'fields':[{'properties':{'display_name':'DISPLAY_NAME'},'selection_options':{'list_options':{},'choices':[{'properties':{'display_name':'CHOICE_1'}},{'properties':{'display_name':'CHOICE_2'}}]}}]};service.labels.create({'resource':label,'use_admin_access':true},(err,res)=>{if(err)returnconsole.error('The API returned an error: '+err);console.log(res);});

The label is created in theUNPUBLISHED_DRAFTState. It must bePUBLISHEDfor use on files and to be visible to users. For more information, seeLabellifecycle.

Label limits

The following limits apply when creating and applying labels:

  • Standard labels—150
  • Fields per label—10
  • User-applied labels per file—5

Working with fields in labels

Field TypeWhat users can doFormat considerations and limits
SelectionOptionsSelect one or more options from a listMaximum number of options supported is 200
Maximum number of selections for a file is 10 as configured inListOptions
IntegerOptionsEnter a numerical valueOnly whole numbers are supported
DateOptionsSelect a calendar date(Optional)Date format can be set to “Long: Month DD, YYYY”, or “Short: MM/DD/YY“
TextOptionsEnter text in a text boxMaximum character count supported is 100
UserOptionsSelect one or more users from Google Workspace contacts.Maximum number of user entries for a file is 10 as configured inListOptions

Publish a label

The Labels API lets you publish a draft label once it's complete.

To publish a label, use thepublish method and specify:

  • ALabel resourcethat represents every label. It contains a resourceName andID, whichis a globally unique identifier for the label.

  • useAdminAccess istrue to use the user's administrator credentials. Theserver verifies that the user is an admin with the "Manage Labels" privilegebefore allowing access.

This example uses theID to identify and publish the correct label.

Python

service.labels().publish(name='labels/ID',body={'use_admin_access':True}).execute()

Node.js

service.labels.publish({'resource':{'use_admin_access':true},'name':'labels/ID'},(err,res)=>{if(err)returnconsole.error('The API returned an error: '+err);console.log(res);});

Once the label is published, the label moves to thePUBLISHEDState and the label's revisionID is incremented. The label is then visible to users and can be applied tofiles. For more information, seeLabellifecycle.

Constraints when publishing labels

  • Once published, a label cannot return to its original draft state. For moreinformation, seeLabel lifecycle.

  • Publishing a label creates a newly published revision. All previous draftrevisions are deleted. Previously published revisions are kept but aresubject to automated deletion as needed.

  • Once published, some changes are no longer permitted. Generally, this meansany change that invalidates or triggers new restrictions on existingmetadata related to the label is rejected. For example, the followingchanges to a label aren't permitted after the label is published:

    • The label is directly deleted. (It must be disabled first, thendeleted.)
    • TheField.FieldType is changed.
    • Updates to the Field validation options reject something previouslyaccepted.
    • A reduction in maximum entries.

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.