Your organization can have multiple labels, with labels having several fields.
The Google Drive Labels API provides the
[`labels`](https://developers.google.com/workspace/drive/labels/reference/rest/v2/labels) resource to enable
the reading of labels.

This document describes how to search for and retrieve labels using the
Drive Labels API.

## Methods

The `labels` resource provides the following methods for reading label values,
each with a specific task in mind:

| Range | Method |
|---|---|
| Single label by resource name | `https://developers.google.com/workspace/drive/labels/reference/rest/v2/labels/get` |
| All labels | `https://developers.google.com/workspace/drive/labels/reference/rest/v2/labels/list` |

## Get label by resource name

To get a single label by its resource name, use the
[`get`](https://developers.google.com/workspace/drive/labels/reference/rest/v2/labels/get) method on the
[`labels`](https://developers.google.com/workspace/drive/labels/reference/rest/v2/labels) resource.

A label resource `name` is required and can be structured as:

- `labels/{id}` or `labels/{id}@latest`: Gets the latest label revision.
- `labels/{id}@published`: Gets the current published label revision.
- `labels/{id}@{revisionId}`: Gets the label at the specified revision ID.

You must specify a
[`LabelView`](https://developers.google.com/workspace/drive/labels/reference/rest/v2/LabelView) object as
`LABEL_VIEW_FULL` to set a resource view that's applied to label responses.
`LABEL_VIEW_FULL` returns all possible fields.

The following code sample shows how to use the label's `name` to get a single
label by its resource name:

### Python

    # Label name, with or without revision:
    #
    # Revision specified:
    # labels/LABEL_ID@published
    # labels/LABEL_ID@latest
    # labels/LABEL_ID@1
    #
    # No revision specified, returns latest revision:
    # labels/LABEL_ID
    name = 'labels/NAME@published'

    # Label view controls level of data in response
    view = 'LABEL_VIEW_FULL'

    label = service.labels().get(
        name=name,
        view=view
    ).execute()

### Node.js

    // Label name, with or without revision:
    //
    // Revision specified:
    // labels/LABEL_ID@published
    // labels/LABEL_ID@latest
    // labels/LABEL_ID@1
    //
    // No revision specified, returns latest revision:
    // labels/LABEL_ID
    const name = 'labels/NAME@published';

    // Label view controls level of data in response
    const view = 'LABEL_VIEW_FULL';

    service.labels.get({
      name: name,
      view: view
    }, (err, res) => {
      if (err) return console.error('The API returned an error: ' + err);
      console.log(res);
    });

Replace <var translate="no">NAME</var> with the name of the label.

## List all labels

To get a list of labels, use the
[`list`](https://developers.google.com/workspace/drive/labels/reference/rest/v2/labels/list) method on the
[`labels`](https://developers.google.com/workspace/drive/labels/reference/rest/v2/labels) resource.

You also must specify:

- A [`customer`](https://developers.google.com/workspace/drive/labels/reference/rest/v2/labels/list#body.QUERY_PARAMETERS.customer)
  query parameter to scope this list request to. If `customer` is unset, all
  labels within the current customer are returned.

- A [`LabelView`](https://developers.google.com/workspace/drive/labels/reference/rest/v2/LabelView) object
  as `LABEL_VIEW_FULL` to set a resource view that's applied to label
  responses. `LABEL_VIEW_FULL` returns all possible fields.

The following code sample shows how to use the `customer` query parameter to get
a list of labels:

### Python

    response = service.labels().list(
        customer='customers/CUSTOMER',
        view='LABEL_VIEW_FULL'
    ).execute()

### Node.js

    const params = {
      customer: 'customers/CUSTOMER',
      view: 'LABEL_VIEW_FULL'
    };

    service.labels.list(params, (err, res) => {
      if (err) return console.error('The API returned an error: ' + err);
      const labels = res.data.labels;
      if (labels) {
        labels.forEach((label) => {
          const name = label.name;
          const title = label.properties.title;
          console.log(`${name}\t${title}`);
        });
      } else {
        console.log('No Labels');
      }
    });

Replace <var translate="no">CUSTOMER</var> with the name of the customer.

> [!NOTE]
> **Note:** If you need to return only the published label revisions, you can also set [`publishedOnly`](https://developers.google.com/workspace/drive/labels/reference/rest/v2/labels/list#body.QUERY_PARAMETERS.published_only) set to `true`. The results also include disabled labels.