# Create Label — Gmail

> Create a new user label in the authenticated Gmail mailbox and return its ID. Call this before Modify Labels whenever the label the user wants to apply doesn't yet exist — List Labels will tell you what's already there. Idempotent: if a…

- Key: `gmail-create-label`
- Type: Action (Write)
- Version: 0.1.3
- App: Gmail (`gmail`) — https://pipedream.com/apps/gmail.md
- This page (HTML): https://pipedream.com/apps/gmail/actions/create-label
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/gmail/actions/create-label/create-label.mjs

## Description

Create a new user label in the authenticated Gmail mailbox and return its ID. Call this before **Modify Labels** whenever the label the user wants to apply doesn't yet exist — **List Labels** will tell you what's already there. Idempotent: if a label with the same name already exists, the action swallows the 409, looks it up by name, and returns the existing label with `alreadyExisted: true` so the caller can proceed. Nested labels are expressed with `/` — e.g. `Clients/Acme` creates or targets a sub-label under `Clients`. `color` is optional; when provided, both `textColor` and `backgroundColor` must be supplied together and must come from Gmail's fixed palette. [See the documentation](https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.labels/create).

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `name` | `string` | Yes | The display name of the label. Use / to create a nested label (e.g. Clients/Acme). Must be unique within the mailbox. |
| `labelListVisibility` | `string` | No | Visibility of the label in the sidebar. Defaults to labelShow. |
| `messageListVisibility` | `string` | No | Whether messages with this label show the label chip in the list view. Defaults to show. |
| `textColor` | `string` | No | Optional text color (must come from Gmail's fixed palette). If set, backgroundColor must also be set. |
| `backgroundColor` | `string` | No | Optional background color (must come from Gmail's fixed palette). If set, textColor must also be set. |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "gmail",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "gmail-create-label",
  arguments: {
    name: "Name",
    labelListVisibility: "Label List Visibility",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "gmail-create-label",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    gmail: { authProvisionId: "apn_xxxxxxx" },
    name: "Name",
    labelListVisibility: "Label List Visibility",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "gmail-create-label",
    "configured_props": {
      "gmail": { "authProvisionId": "apn_xxxxxxx" },
      "name": "Name",
      "labelListVisibility": "Label List Visibility"
    }
  }'
```

---

- App: https://pipedream.com/apps/gmail.md · All apps: https://pipedream.com/apps
