Skip to content

Instantly share code, notes, and snippets.

@YoRyan
Last active April 8, 2026 02:46
Show Gist options
  • Select an option

  • Save YoRyan/4f9d28531d2b2eb9014dcb2c627aa10b to your computer and use it in GitHub Desktop.

Select an option

Save YoRyan/4f9d28531d2b2eb9014dcb2c627aa10b to your computer and use it in GitHub Desktop.
Discover the API label ID's used by your Gmail account using Google Apps Script.
// This work is marked CC0 1.0 Universal.
// To view a copy of this mark, visit https://creativecommons.org/publicdomain/zero/1.0/
function listLabels() {
const labels = Gmail.Users.Labels
.list("me")
.labels;
console.log(
"System Labels:\n\n" +
labels
.filter(label => label.type === "system")
.map(label => label.id)
.sort()
.join("\n")
);
console.log(
"User Labels:\n\n" +
labels
.filter(label => label.type === "user")
.map(label => `${label.name} => ${label.id}`)
.sort()
.join("\n")
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment