# Apply a label to an email

Source: https://docs.maylee.app/api-reference/emails/apply-label-to-email

`POST https://api.maylee.app/api/v1/emails/{emailId}/labels/{labelId}`

Scope: `write`.

Idempotent: applying a label the email already has returns the current labels without firing `label.applied` again.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `emailId` | path | string | yes |  |
| `labelId` | path | string | yes |  |

## Example request

```bash
curl -X POST "https://api.maylee.app/api/v1/emails/<emailId>/labels/<labelId>" \
  -H "Authorization: Bearer $MAYLEE_KEY"
```

## Responses

### 200

Every label now on the email.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `labels` | array of LabelRef | yes |  |
| `labels[].color` | string | yes | Color name. The Maylee app renders `Pink`, `Blue`, `Red`, `Yellow`, `Green`, `Purple` and `Orange`; any other value is stored but shown without color. |
| `labels[].id` | string | yes |  |
| `labels[].isAiLabel` | boolean | yes |  |
| `labels[].name` | string | yes |  |

```json
{
  "labels": [
    {
      "color": "Blue",
      "id": "cmtgai1b2c3d4e5f6g7h8i9j",
      "isAiLabel": true,
      "name": "Sales"
    },
    {
      "color": "Green",
      "id": "cmtg1a2b3c4d5e6f7g8h9i0j",
      "isAiLabel": false,
      "name": "Quotes"
    }
  ]
}
```

### 401

Missing, malformed, revoked or expired API key.

### 403

Key lacks the required scope, or outbound sending is not enabled on it.

### 404

`EMAIL_NOT_FOUND` or `LABEL_NOT_FOUND`: unknown id, or belongs to another workspace.

### 429

Per-minute rate limit (`RATE_LIMIT_EXCEEDED`) or monthly quota (`QUOTA_EXCEEDED`) exhausted.

Errors use the format `{ "code", "error", "details" }`: see [Errors](/errors.md).
