# Set the alert email

Choose the address alerts go to. We send a confirmation link first.

PUT `/api/v1/notifications/email`

**cURL**

```shell
curl -X PUT 'https://www.prufy.dev/api/v1/notifications/email' \
  -b cookies.txt \
  -H 'content-type: application/json' \
  -d '{
  "email": "owner@yourcompany.com"
}'
```

**Node.js**

```javascript
// `cookie` is the session cookie that Create a claim returned.
const response = await fetch("https://www.prufy.dev/api/v1/notifications/email", {
  method: "PUT",
  headers: { "content-type": "application/json", cookie },
  body: JSON.stringify({ email: "owner@yourcompany.com" }),
})
const data = await response.json()
```

**Python**

```python
import requests

# `session` is the requests.Session() that created the claim.
response = session.put(
    "https://www.prufy.dev/api/v1/notifications/email",
    json={"email": "owner@yourcompany.com"},
)
data = response.json()
```

Response 200 OK

```json
{
  "email": {
    "address": "owner@yourcompany.com",
    "verified": false
  },
  "pushDevices": 1,
  "capabilities": {
    "email": true,
    "pushPublicKey": "BEl62iUYgUivxIkv69yViEuiBIa-Ib9-SkvMeAtA3LFgDzkrxZJjSgSnfckjBJuBkr3qBUYIHBQFLXYp5Nksh8U"
  }
}
```

Nothing is sent to the address until its owner presses the button in the confirmation email. That link works for 24 hours. Until then the response shows the address with `verified: false`.

Setting a new address replaces the old one.

## Authentication

Send the session cookie. Without it the answer is `unauthorized`. [How sessions work](https://www.prufy.dev/docs/authentication.md).

## Body

JSON, with `content-type: application/json`.

- `email` email required

  The address alerts should go to.

  - At most 254 characters

## Response

`200 OK`, with every field below present. Times are ISO 8601 strings in UTC.

- `email` object | null

  The alert address. Null when none is set.

  - `address` string

    Where alert emails go.
  - `verified` boolean

    False until the confirmation link has been used.
- `pushDevices` integer

  How many browsers are subscribed to push.
- `capabilities` object

  Which channels this server can use.

  - `email` boolean

    Whether this server can send email at all.
  - `pushPublicKey` string | null

    The key a browser subscribes with. Null when push is off.

## Errors

| Status | Kind | When |
| --- | --- | --- |
| 400 | `bad_request` | The body isn't JSON, or doesn't match the shape below. `message` names the first field to fix, and `fields` lists each one with its path. |
| 401 | `unauthorized` | The request has no session cookie, or one we don't recognise. |
| 413 | `payload_too_large` | The body is over 16 KB. No route takes anything near that. |
| 429 | `rate_limited` | The account has changed its address 5 times in the last hour. |
| 503 | `email_unavailable` | This server has no email set up, or the confirmation couldn't be sent to that address. |

Any route can also answer `500` with `internal_error`. Every error has the same shape, described in [Errors](https://www.prufy.dev/docs/errors.md).

---

Every page of these docs, as a list: https://www.prufy.dev/llms.txt
