---
title: "nextmail.account"
description: "Every method in this namespace: its signature, its parameters, what it returns and an example."
url: "https://nextmail.sh/docs/python/reference/account"
area: "Python"
category: "Reference"
---

# nextmail.account

Every method in this namespace: its signature, its parameters, what it returns and an example.

## Methods

The account of the person behind the key or the app: the email notifications they get and the workspaces muted on their phone, their profile photo and username, the apps they connected, the invitations waiting for them, the devices they are signed in on, their passkeys and their security log. An API key acts for the workspace owner, and an app for the person who connected it.

### `account.get_notifications()`

Read your notification settings

```python
def get_notifications(
    *,
    api_key: str | None = None,
    timeout: float | None = None,
) -> NotificationSettingsResource
```

Returns which kinds of email Nextmail sends the person, as Account, Notifications shows them, and the workspaces whose notifications are muted on their phone. An API key answers for the workspace owner, and an app for the person who connected it.

Scopes: `account:read`.

**Parameters**

- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`NotificationSettingsResource` with `email`, a list holding one `EmailNotificationSetting` for each kind of email, and `mutedWorkspaces`, a list of workspace ids.

**Example**

```python
from nextmail import nextmail

settings = nextmail.account.get_notifications()

for kind in settings['email']:
    print(kind['label'], 'on' if kind['enabled'] else 'off')

print('Muted on the phone:', settings['mutedWorkspaces'])
```

**Notes**

- `account` and `billing` email are always on, and `required` says so.

Also available in: API [`GET /account/notifications`](https://nextmail.sh/docs/api/reference/your-account#get-account-notifications); TypeScript [`nextmail.account.getNotifications()`](https://nextmail.sh/docs/sdk/reference/account#getNotifications); Ruby [`account.get_notifications`](https://nextmail.sh/docs/ruby/reference/account#getNotifications); PHP [`account->getNotifications`](https://nextmail.sh/docs/php/reference/account#getNotifications); Go [`Account.GetNotifications`](https://nextmail.sh/docs/go/reference/account#getNotifications); Java [`account().getNotifications`](https://nextmail.sh/docs/java/reference/account#getNotifications); C# [`Account.GetNotificationsAsync`](https://nextmail.sh/docs/csharp/reference/account#getNotifications); CLI [`nextmail account get-notifications`](https://nextmail.sh/docs/cli/reference/account#account-get-notifications).

### `account.set_email_notification()`

Turn a kind of email on or off

```python
def set_email_notification(
    category: EmailNotificationCategory,
    body: EmailNotificationSet,
    *,
    api_key: str | None = None,
    timeout: float | None = None,
) -> NotificationSettingsResource
```

`{'enabled': False}` stops Nextmail sending the person that kind of email, and `{'enabled': True}` starts it again. `activity` and `product` can be turned off. `account` and `billing` cannot, and asking to is a 422 `invalid_parameter` on `category`.

Scopes: `account:write`.

**Parameters**

- `category` (`EmailNotificationCategory`, required): `account`, `billing`, `activity` or `product`.
- `body['enabled']` (`bool`, required): `True` to receive that email, `False` to stop it.
- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`NotificationSettingsResource` as it is after the change.

**Example**

```python
from nextmail import nextmail

settings = nextmail.account.set_email_notification('product', {'enabled': False})

for kind in settings['email']:
    print(kind['category'], kind['enabled'])
```

**Notes**

- Retried automatically on network failure, since the same setting sent twice changes nothing.

Also available in: API [`PUT /account/notifications/email/{category}`](https://nextmail.sh/docs/api/reference/your-account#put-account-notifications-email-category); TypeScript [`nextmail.account.setEmailNotification()`](https://nextmail.sh/docs/sdk/reference/account#setEmailNotification); Ruby [`account.set_email_notification`](https://nextmail.sh/docs/ruby/reference/account#setEmailNotification); PHP [`account->setEmailNotification`](https://nextmail.sh/docs/php/reference/account#setEmailNotification); Go [`Account.SetEmailNotification`](https://nextmail.sh/docs/go/reference/account#setEmailNotification); Java [`account().setEmailNotification`](https://nextmail.sh/docs/java/reference/account#setEmailNotification); C# [`Account.SetEmailNotificationAsync`](https://nextmail.sh/docs/csharp/reference/account#setEmailNotification); CLI [`nextmail account set-email-notification`](https://nextmail.sh/docs/cli/reference/account#account-set-email-notification).

### `account.set_push_muted()`

Mute a workspace on your phone

```python
def set_push_muted(
    workspace_id: str,
    body: PushNotificationSet,
    *,
    api_key: str | None = None,
    timeout: float | None = None,
) -> NotificationSettingsResource
```

`{'muted': True}` stops the phone app notifying the person about the mail of one workspace, on every phone they signed in on, and `{'muted': False}` lets it notify them again.

Scopes: `account:write`.

**Parameters**

- `workspace_id` (`str`, required): A workspace id from `workspaces.list`.
- `body['muted']` (`bool`, required): `True` to mute it, `False` to let it notify again.
- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`NotificationSettingsResource` with the new `mutedWorkspaces`.

**Example**

```python
from nextmail import nextmail

settings = nextmail.account.set_push_muted(
    '10417196-e324-4283-af98-66ec62167c47', {'muted': True}
)

print(settings['mutedWorkspaces'])
```

**Notes**

- A workspace the person cannot open is a 404 `resource_not_found`.
- Retried automatically on network failure, since the same setting sent twice changes nothing.

Also available in: API [`PUT /account/notifications/push/{workspaceId}`](https://nextmail.sh/docs/api/reference/your-account#put-account-notifications-push-workspaceid); TypeScript [`nextmail.account.setPushMuted()`](https://nextmail.sh/docs/sdk/reference/account#setPushMuted); Ruby [`account.set_push_muted`](https://nextmail.sh/docs/ruby/reference/account#setPushMuted); PHP [`account->setPushMuted`](https://nextmail.sh/docs/php/reference/account#setPushMuted); Go [`Account.SetPushMuted`](https://nextmail.sh/docs/go/reference/account#setPushMuted); Java [`account().setPushMuted`](https://nextmail.sh/docs/java/reference/account#setPushMuted); C# [`Account.SetPushMutedAsync`](https://nextmail.sh/docs/csharp/reference/account#setPushMuted); CLI [`nextmail account set-push-muted`](https://nextmail.sh/docs/cli/reference/account#account-set-push-muted).

### `account.set_photo()`

Set your profile photo

```python
def set_photo(
    data: RawBody,
    *,
    content_type: ContactPhotoType | None = None,
    api_key: str | None = None,
    timeout: float | None = None,
) -> AccountPhotoResource
```

Sends the image bytes as the request body, replacing the person's profile photo, as Account, Profile does. PNG, JPEG, WebP and GIF are accepted, up to 5 MB. The server fits the image into a 512 pixel square, stores it as WebP and keeps the first frame of an animation.

`data` is `bytes`, a `bytearray` or a `memoryview`, such as what `Path('photo.jpg').read_bytes()` returns. Bytes carry no type of their own, so the type is read from `content_type=` alone. Without it the bytes go as `application/octet-stream` and the server refuses them with 422 `invalid_image`.

Scopes: `account:write`.

**Parameters**

- `data` (`RawBody`, required): The image as `bytes`, a `bytearray` or a `memoryview`.
- `content_type` (`ContactPhotoType`): `image/png`, `image/jpeg`, `image/webp` or `image/gif`, matching the bytes. Left out, the upload is refused with 422 `invalid_image`.
- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`AccountPhotoResource` with the new `url`.

**Example**

```python
from pathlib import Path

from nextmail import nextmail

photo = nextmail.account.set_photo(Path('photo.jpg').read_bytes(), content_type='image/jpeg')

print(photo['url'])
```

**Notes**

- A busy image service answers 503 `image_busy`, which the SDK retries like any other 503.
- Every upload gets a new URL, so a cached old photo never shows under the new one.

Also available in: API [`PUT /account/photo`](https://nextmail.sh/docs/api/reference/your-account#put-account-photo); TypeScript [`nextmail.account.setPhoto()`](https://nextmail.sh/docs/sdk/reference/account#setPhoto); Ruby [`account.set_photo`](https://nextmail.sh/docs/ruby/reference/account#setPhoto); PHP [`account->setPhoto`](https://nextmail.sh/docs/php/reference/account#setPhoto); Go [`Account.SetPhoto`](https://nextmail.sh/docs/go/reference/account#setPhoto); Java [`account().setPhoto`](https://nextmail.sh/docs/java/reference/account#setPhoto); C# [`Account.SetPhotoAsync`](https://nextmail.sh/docs/csharp/reference/account#setPhoto); CLI [`nextmail account set-photo`](https://nextmail.sh/docs/cli/reference/account#account-set-photo).

### `account.remove_photo()`

Remove your profile photo

```python
def remove_photo(
    *,
    api_key: str | None = None,
    timeout: float | None = None,
) -> AccountPhotoResource
```

Removes the profile photo and deletes the stored image, so the app shows the person's initials again. Removing it when there is none changes nothing.

Scopes: `account:write`.

**Parameters**

- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`AccountPhotoResource` with `url` set to `None`.

**Example**

```python
from nextmail import nextmail

photo = nextmail.account.remove_photo()

print(photo['url'])
```

**Notes**

- Safe to replay, so the SDK retries it after a network failure.

Also available in: API [`DELETE /account/photo`](https://nextmail.sh/docs/api/reference/your-account#delete-account-photo); TypeScript [`nextmail.account.removePhoto()`](https://nextmail.sh/docs/sdk/reference/account#removePhoto); Ruby [`account.remove_photo`](https://nextmail.sh/docs/ruby/reference/account#removePhoto); PHP [`account->removePhoto`](https://nextmail.sh/docs/php/reference/account#removePhoto); Go [`Account.RemovePhoto`](https://nextmail.sh/docs/go/reference/account#removePhoto); Java [`account().removePhoto`](https://nextmail.sh/docs/java/reference/account#removePhoto); C# [`Account.RemovePhotoAsync`](https://nextmail.sh/docs/csharp/reference/account#removePhoto); CLI [`nextmail account remove-photo`](https://nextmail.sh/docs/cli/reference/account#account-remove-photo).

### `account.get_username()`

Read your username

```python
def get_username(
    *,
    api_key: str | None = None,
    timeout: float | None = None,
) -> UsernameResource
```

Returns the person's username, whether they chose it or it was made for them from their name, and the free address that comes with it, when there is one. A username the person chose never changes.

Scopes: `account:read`.

**Parameters**

- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`UsernameResource` with `username`, `chosen` and `address`.

**Example**

```python
from nextmail import nextmail

account = nextmail.account.get_username()

print(account['username'], 'chosen' if account['chosen'] else 'made for you')
print(account['address'])
```

**Notes**

- The first read makes a username for an account that has none.

Also available in: API [`GET /account/username`](https://nextmail.sh/docs/api/reference/your-account#get-account-username); TypeScript [`nextmail.account.getUsername()`](https://nextmail.sh/docs/sdk/reference/account#getUsername); Ruby [`account.get_username`](https://nextmail.sh/docs/ruby/reference/account#getUsername); PHP [`account->getUsername`](https://nextmail.sh/docs/php/reference/account#getUsername); Go [`Account.GetUsername`](https://nextmail.sh/docs/go/reference/account#getUsername); Java [`account().getUsername`](https://nextmail.sh/docs/java/reference/account#getUsername); C# [`Account.GetUsernameAsync`](https://nextmail.sh/docs/csharp/reference/account#getUsername); CLI [`nextmail account get-username`](https://nextmail.sh/docs/cli/reference/account#account-get-username).

### `account.check_username()`

Check a username

```python
def check_username(
    username: str,
    *,
    api_key: str | None = None,
    timeout: float | None = None,
) -> UsernameAvailabilityResource
```

Says whether the person could choose a username, without choosing it, and why not when they could not. The username is lowercased and its spaces become dots before it is checked, as the app does, and `username` in the answer is the form that was checked.

Scopes: `account:read`.

**Parameters**

- `username` (`str`, required): Up to 60 characters before it is tidied.
- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`UsernameAvailabilityResource` with `status`, `available` and a `message` that says why.

**Example**

```python
from nextmail import nextmail

check = nextmail.account.check_username('Ada Lovelace')

if check['available']:
    print(check['username'], 'is free')
else:
    print(check['status'], check['message'])
```

**Notes**

- `status` is `current` for the username the person already has, and `available` is `False` for it.

Also available in: API [`GET /account/username/availability`](https://nextmail.sh/docs/api/reference/your-account#get-account-username-availability); TypeScript [`nextmail.account.checkUsername()`](https://nextmail.sh/docs/sdk/reference/account#checkUsername); Ruby [`account.check_username`](https://nextmail.sh/docs/ruby/reference/account#checkUsername); PHP [`account->checkUsername`](https://nextmail.sh/docs/php/reference/account#checkUsername); Go [`Account.CheckUsername`](https://nextmail.sh/docs/go/reference/account#checkUsername); Java [`account().checkUsername`](https://nextmail.sh/docs/java/reference/account#checkUsername); C# [`Account.CheckUsernameAsync`](https://nextmail.sh/docs/csharp/reference/account#checkUsername); CLI [`nextmail account check-username`](https://nextmail.sh/docs/cli/reference/account#account-check-username).

### `account.set_username()`

Choose your username

```python
def set_username(
    username: str,
    *,
    api_key: str | None = None,
    timeout: float | None = None,
) -> UsernameResource
```

Sets the person's username for good, and with it their free address. Once chosen it never changes: a second choice is refused with 409 `username_locked`. A username another account has is a 409 `username_taken`, and one that is too short, too long, reserved or not lowercase letters, numbers and single dots is a 422 `invalid_parameter` on `username`. Check one first with `check_username`.

Scopes: `account:write`.

**Parameters**

- `username` (`str`, required): 3 to 30 lowercase letters, numbers and single dots once it is tidied.
- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`UsernameResource` with `chosen` set to `True`.

**Example**

```python
from nextmail import NextmailApiError, nextmail

try:
    account = nextmail.account.set_username('ada.lovelace')
except NextmailApiError as error:
    if error.code == 'username_taken':
        print('Someone else has that one, try another')
    elif error.code == 'username_locked':
        print('Your username is already chosen for good')
    else:
        raise
else:
    print(account['username'], account['address'])
```

**Notes**

- Not retried automatically: a retry after a lost response would be refused with `username_locked`, because the first call already chose it.

Also available in: API [`PUT /account/username`](https://nextmail.sh/docs/api/reference/your-account#put-account-username); TypeScript [`nextmail.account.setUsername()`](https://nextmail.sh/docs/sdk/reference/account#setUsername); Ruby [`account.set_username`](https://nextmail.sh/docs/ruby/reference/account#setUsername); PHP [`account->setUsername`](https://nextmail.sh/docs/php/reference/account#setUsername); Go [`Account.SetUsername`](https://nextmail.sh/docs/go/reference/account#setUsername); Java [`account().setUsername`](https://nextmail.sh/docs/java/reference/account#setUsername); C# [`Account.SetUsernameAsync`](https://nextmail.sh/docs/csharp/reference/account#setUsername); CLI [`nextmail account set-username`](https://nextmail.sh/docs/cli/reference/account#account-set-username).

### `account.list_connected_apps()`

List your connected apps

```python
def list_connected_apps(
    *,
    api_key: str | None = None,
    timeout: float | None = None,
) -> builtins.list[ConnectedAppResource]
```

Returns every app the person connected with OAuth, as Account, Connected apps lists them: the workspace and the permissions each may reach, until when, how many tokens it holds, and until when it may make changes that ask for a verification code without one. `current` marks the app making the call.

What an app may reach is changed in the app, never through an app.

Scopes: `account:read`.

**Parameters**

- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`list[ConnectedAppResource]`, each with `clientId`, `name`, `kind`, `status`, `grant` and `tokenCount`.

**Example**

```python
from nextmail import nextmail

apps = nextmail.account.list_connected_apps()

for app in apps:
    print(app['name'], app['kind'], app['status'], '(this app)' if app['current'] else '')
```

**Notes**

- A sign-in of the command line tool shows with `kind` set to `cli`, and its device in `cliDevice`.

Also available in: API [`GET /account/connected-apps`](https://nextmail.sh/docs/api/reference/your-account#get-account-connected-apps); TypeScript [`nextmail.account.listConnectedApps()`](https://nextmail.sh/docs/sdk/reference/account#listConnectedApps); Ruby [`account.list_connected_apps`](https://nextmail.sh/docs/ruby/reference/account#listConnectedApps); PHP [`account->listConnectedApps`](https://nextmail.sh/docs/php/reference/account#listConnectedApps); Go [`Account.ListConnectedApps`](https://nextmail.sh/docs/go/reference/account#listConnectedApps); Java [`account().listConnectedApps`](https://nextmail.sh/docs/java/reference/account#listConnectedApps); C# [`Account.ListConnectedAppsAsync`](https://nextmail.sh/docs/csharp/reference/account#listConnectedApps); CLI [`nextmail account list-connected-apps`](https://nextmail.sh/docs/cli/reference/account#account-list-connected-apps).

### `account.list_connected_app_requests()`

Read the request log of a connected app

```python
def list_connected_app_requests(
    client_id: str,
    *,
    limit: int | None = None,
    cursor: str | None = None,
    since: datetime | str | None = None,
    until: datetime | str | None = None,
    failed_only: bool | None = None,
    statuses: Sequence[int] | None = None,
    api_key: str | None = None,
    timeout: float | None = None,
) -> Page[ConnectedAppRequestResource]
```

Returns one page of the REST calls an app the person connected made with the access they gave it, newest first, as Request log in the menu of the app under Account, Connected apps shows them. Each call has its method, path, status, how long it took and the error code of a refusal, and never a body, a query string or the address it came from. The command line tool signed in from a browser is in it too. Calls made under an earlier connection of the same app are not: connecting it again starts a new log. `failed_only=`, `statuses=`, `since=` and `until=` narrow it, and they combine.

Scopes: `account:read`.

**Parameters**

- `client_id` (`str`, required): The app's `clientId` from `list_connected_apps`.
- `limit` (`int`): Calls per page, a whole number from 1 to 100. The server defaults to 25.
- `cursor` (`str`): The `nextCursor` of the previous page, passed back unchanged. Leave it out for the first page.
- `since` (`datetime | str`): Only calls at or after this instant. A `datetime` is sent as ISO 8601 in UTC, and a string must already be one.
- `until` (`datetime | str`): Only calls before this instant. It has to be later than `since`, or the server answers 400 `invalid_parameter`.
- `failed_only` (`bool`): Only calls answered with a status of 400 or more.
- `statuses` (`Sequence[int]`): Only calls answered with one of these HTTP status codes, such as `[401, 403]`. At most 20, each from 100 to 599, sent comma-separated as `status`.
- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`Page[ConnectedAppRequestResource]`, a dict with `items`, `hasMore` and `nextCursor`. Each item has `id`, `clientId`, `workspaceId`, `requestId`, `method`, `path`, `status`, `errorCode`, `durationMs`, `userAgent` and `createdAt`.

**Example**

```python
from nextmail import nextmail

page = nextmail.account.list_connected_app_requests(
    'kZ3mQ9vT2xR7pL4wN8bY1cF6hJ5sD0aE', failed_only=True, limit=50
)

for call in page['items']:
    print(call['createdAt'], call['method'], call['path'], call['status'], call['errorCode'])
```

**Notes**

- An app the person never connected is a 404 `resource_not_found`, and a cursor this log did not hand out is a 400 `invalid_cursor`.
- Calls made with an API key are in the request log of that key, `nextmail.keys.list_requests()`, not here.

Also available in: API [`GET /account/connected-apps/{clientId}/requests`](https://nextmail.sh/docs/api/reference/your-account#get-account-connected-apps-clientid-requests); TypeScript [`nextmail.account.listConnectedAppRequests()`](https://nextmail.sh/docs/sdk/reference/account#listConnectedAppRequests); Ruby [`account.list_connected_app_requests`](https://nextmail.sh/docs/ruby/reference/account#listConnectedAppRequests); PHP [`account->listConnectedAppRequests`](https://nextmail.sh/docs/php/reference/account#listConnectedAppRequests); Go [`Account.ListConnectedAppRequests`](https://nextmail.sh/docs/go/reference/account#listConnectedAppRequests); Java [`account().listConnectedAppRequests`](https://nextmail.sh/docs/java/reference/account#listConnectedAppRequests); C# [`Account.ListConnectedAppRequestsAsync`](https://nextmail.sh/docs/csharp/reference/account#listConnectedAppRequests); CLI [`nextmail account list-connected-app-requests`](https://nextmail.sh/docs/cli/reference/account#account-list-connected-app-requests).

### `account.list_all_connected_app_requests()`

Collect the whole request log of a connected app into one list

```python
def list_all_connected_app_requests(
    client_id: str,
    *,
    limit: int | None = None,
    cursor: str | None = None,
    since: datetime | str | None = None,
    until: datetime | str | None = None,
    failed_only: bool | None = None,
    statuses: Sequence[int] | None = None,
    api_key: str | None = None,
    timeout: float | None = None,
) -> builtins.list[ConnectedAppRequestResource]
```

Walks every page of `list_connected_app_requests` under the same filters and returns every call in one list. The log is never pruned, so give it a window unless you mean to read a busy app's whole history, or use `iterate_connected_app_requests` to stop early.

Scopes: `account:read`.

**Parameters**

- `client_id` (`str`, required): The app's `clientId` from `list_connected_apps`.
- `limit` (`int`): Page size for each request, 1 to 100. The server defaults to 25.
- `cursor` (`str`): Starts the walk from this cursor instead of the newest call.
- `since` (`datetime | str`): Only calls at or after this instant. A `datetime` is sent as ISO 8601 in UTC, and a string must already be one.
- `until` (`datetime | str`): Only calls before this instant. It has to be later than `since`, or the server answers 400 `invalid_parameter`.
- `failed_only` (`bool`): Only calls answered with a status of 400 or more.
- `statuses` (`Sequence[int]`): Only calls answered with one of these HTTP status codes, such as `[401, 403]`. At most 20, each from 100 to 599, sent comma-separated as `status`.
- `api_key` (`str`): Overrides the client API key for every page of this walk.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`list[ConnectedAppRequestResource]`, newest first.

**Example**

```python
from datetime import datetime, timedelta, timezone

from nextmail import nextmail

today = nextmail.account.list_all_connected_app_requests(
    'kZ3mQ9vT2xR7pL4wN8bY1cF6hJ5sD0aE',
    since=datetime.now(timezone.utc) - timedelta(days=1),
    limit=100,
)

print(len(today), 'calls in the last 24 hours')
```

**Notes**

- If any page fails, the call raises and the calls already fetched are discarded.

Also available in: API [`GET /account/connected-apps/{clientId}/requests`](https://nextmail.sh/docs/api/reference/your-account#get-account-connected-apps-clientid-requests); TypeScript [`nextmail.account.listAllConnectedAppRequests()`](https://nextmail.sh/docs/sdk/reference/account#listAllConnectedAppRequests); Ruby [`account.list_all_connected_app_requests`](https://nextmail.sh/docs/ruby/reference/account#listAllConnectedAppRequests); PHP [`account->listAllConnectedAppRequests`](https://nextmail.sh/docs/php/reference/account#listAllConnectedAppRequests); Go [`Account.ListAllConnectedAppRequests`](https://nextmail.sh/docs/go/reference/account#listAllConnectedAppRequests); Java [`account().listAllConnectedAppRequests`](https://nextmail.sh/docs/java/reference/account#listAllConnectedAppRequests); C# [`Account.ListAllConnectedAppRequestsAsync`](https://nextmail.sh/docs/csharp/reference/account#listAllConnectedAppRequests).

### `account.iterate_connected_app_requests()`

Stream the request log of a connected app one call at a time

```python
def iterate_connected_app_requests(
    client_id: str,
    *,
    limit: int | None = None,
    cursor: str | None = None,
    since: datetime | str | None = None,
    until: datetime | str | None = None,
    failed_only: bool | None = None,
    statuses: Sequence[int] | None = None,
    api_key: str | None = None,
    timeout: float | None = None,
) -> Iterator[ConnectedAppRequestResource]
```

A generator over `list_connected_app_requests` under the same filters, fetching a page only when the one before is drained. Nothing is requested until you start iterating.

Scopes: `account:read`.

**Parameters**

- `client_id` (`str`, required): The app's `clientId` from `list_connected_apps`.
- `limit` (`int`): Page size for each request, 1 to 100. The server defaults to 25.
- `cursor` (`str`): Starts the walk from this cursor instead of the newest call.
- `since` (`datetime | str`): Only calls at or after this instant. A `datetime` is sent as ISO 8601 in UTC, and a string must already be one.
- `until` (`datetime | str`): Only calls before this instant. It has to be later than `since`, or the server answers 400 `invalid_parameter`.
- `failed_only` (`bool`): Only calls answered with a status of 400 or more.
- `statuses` (`Sequence[int]`): Only calls answered with one of these HTTP status codes, such as `[401, 403]`. At most 20, each from 100 to 599, sent comma-separated as `status`.
- `api_key` (`str`): Overrides the client API key for every page of this walk.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`Iterator[ConnectedAppRequestResource]`, a generator yielding one call per step, newest first.

**Example**

```python
from nextmail import nextmail

for call in nextmail.account.iterate_connected_app_requests(
    'kZ3mQ9vT2xR7pL4wN8bY1cF6hJ5sD0aE', failed_only=True
):
    print('Last refused call', call['createdAt'], call['path'], call['errorCode'])
    break
```

**Notes**

- Breaking out of the loop stops the walk, and no further page is fetched.

Also available in: API [`GET /account/connected-apps/{clientId}/requests`](https://nextmail.sh/docs/api/reference/your-account#get-account-connected-apps-clientid-requests); TypeScript [`nextmail.account.iterateConnectedAppRequests()`](https://nextmail.sh/docs/sdk/reference/account#iterateConnectedAppRequests); Ruby [`account.iterate_connected_app_requests`](https://nextmail.sh/docs/ruby/reference/account#iterateConnectedAppRequests); PHP [`account->iterateConnectedAppRequests`](https://nextmail.sh/docs/php/reference/account#iterateConnectedAppRequests); Go [`Account.IterateConnectedAppRequests`](https://nextmail.sh/docs/go/reference/account#iterateConnectedAppRequests); Java [`account().iterateConnectedAppRequests`](https://nextmail.sh/docs/java/reference/account#iterateConnectedAppRequests); C# [`Account.IterateConnectedAppRequestsAsync`](https://nextmail.sh/docs/csharp/reference/account#iterateConnectedAppRequests).

### `account.revoke_connected_app()`

Remove a connected app

```python
def revoke_connected_app(
    client_id: str,
    *,
    api_key: str | None = None,
    timeout: float | None = None,
) -> RevokedConnectedAppResource
```

Deletes every token the app holds and the access the person gave it, so its next call is refused and it has to ask again, as removing it in Account, Connected apps does. Removing the app making the call disconnects it.

Scopes: `account:write`.

**Parameters**

- `client_id` (`str`, required): The app's `clientId` from `list_connected_apps`.
- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`RevokedConnectedAppResource` with `revoked` set to `True` and `tokensRevoked`.

**Example**

```python
from nextmail import nextmail

revoked = nextmail.account.revoke_connected_app('kZ3mQ9vT2xR7pL4wN8bY1cF6hJ5sD0aE')

print(revoked['clientId'], 'lost', revoked['tokensRevoked'], 'tokens')
```

**Notes**

- An app the person never connected is a 404 `resource_not_found`.
- Not retried automatically. A retry after a lost response is a 404, since the app is already gone.

Also available in: API [`DELETE /account/connected-apps/{clientId}`](https://nextmail.sh/docs/api/reference/your-account#delete-account-connected-apps-clientid); TypeScript [`nextmail.account.revokeConnectedApp()`](https://nextmail.sh/docs/sdk/reference/account#revokeConnectedApp); Ruby [`account.revoke_connected_app`](https://nextmail.sh/docs/ruby/reference/account#revokeConnectedApp); PHP [`account->revokeConnectedApp`](https://nextmail.sh/docs/php/reference/account#revokeConnectedApp); Go [`Account.RevokeConnectedApp`](https://nextmail.sh/docs/go/reference/account#revokeConnectedApp); Java [`account().revokeConnectedApp`](https://nextmail.sh/docs/java/reference/account#revokeConnectedApp); C# [`Account.RevokeConnectedAppAsync`](https://nextmail.sh/docs/csharp/reference/account#revokeConnectedApp); CLI [`nextmail account revoke-connected-app`](https://nextmail.sh/docs/cli/reference/account#account-revoke-connected-app).

### `account.list_sessions()`

List your signed-in devices

```python
def list_sessions(
    *,
    api_key: str | None = None,
    timeout: float | None = None,
) -> builtins.list[SessionResource]
```

Returns every browser and phone the person is signed in on, as Account, Security lists them, most recently used first: the browser and system, the country and city it was last used from, how it signed in and when.

No address is ever recorded, only the place. A key or an app is not a signed-in device, so `current` is always `False` here.

Scopes: `account:read`.

**Parameters**

- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`list[SessionResource]`, each with `id`, `device`, `authMethod`, `country`, `city`, `createdAt`, `lastActiveAt` and `expiresAt`.

**Example**

```python
from nextmail import nextmail

sessions = nextmail.account.list_sessions()

for session in sessions:
    device = session['device']

    print(device['browser'] or device['os'], session['city'], session['lastActiveAt'])
```

**Notes**

- `lastActiveAt` is accurate to within ten minutes.
- `authMethod` is `None` for a device that signed in before it was recorded.

Also available in: API [`GET /account/sessions`](https://nextmail.sh/docs/api/reference/your-account#get-account-sessions); TypeScript [`nextmail.account.listSessions()`](https://nextmail.sh/docs/sdk/reference/account#listSessions); Ruby [`account.list_sessions`](https://nextmail.sh/docs/ruby/reference/account#listSessions); PHP [`account->listSessions`](https://nextmail.sh/docs/php/reference/account#listSessions); Go [`Account.ListSessions`](https://nextmail.sh/docs/go/reference/account#listSessions); Java [`account().listSessions`](https://nextmail.sh/docs/java/reference/account#listSessions); C# [`Account.ListSessionsAsync`](https://nextmail.sh/docs/csharp/reference/account#listSessions); CLI [`nextmail account list-sessions`](https://nextmail.sh/docs/cli/reference/account#account-list-sessions).

### `account.revoke_session()`

Sign out one device

```python
def revoke_session(
    session_id: str,
    *,
    api_key: str | None = None,
    timeout: float | None = None,
) -> RevokedSessionResource
```

Signs one browser or phone out, as Sign out next to it in Account, Security does. Its next request is refused at once, and a phone stops getting notifications. It is written to the person's security log.

Scopes: `account:write`.

**Parameters**

- `session_id` (`str`, required): The device's `id` from `list_sessions`.
- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`RevokedSessionResource` with `revoked` set to `True`.

**Example**

```python
from nextmail import nextmail

sessions = nextmail.account.list_sessions()

for session in sessions:
    if session['device']['kind'] == 'browser':
        revoked = nextmail.account.revoke_session(session['id'])

        print(revoked['id'], 'signed out')
```

**Notes**

- A device that is not signed in to the account is a 404 `resource_not_found`.
- Not retried automatically. A retry after a lost response is a 404, since the device is already signed out.

Also available in: API [`DELETE /account/sessions/{sessionId}`](https://nextmail.sh/docs/api/reference/your-account#delete-account-sessions-sessionid); TypeScript [`nextmail.account.revokeSession()`](https://nextmail.sh/docs/sdk/reference/account#revokeSession); Ruby [`account.revoke_session`](https://nextmail.sh/docs/ruby/reference/account#revokeSession); PHP [`account->revokeSession`](https://nextmail.sh/docs/php/reference/account#revokeSession); Go [`Account.RevokeSession`](https://nextmail.sh/docs/go/reference/account#revokeSession); Java [`account().revokeSession`](https://nextmail.sh/docs/java/reference/account#revokeSession); C# [`Account.RevokeSessionAsync`](https://nextmail.sh/docs/csharp/reference/account#revokeSession); CLI [`nextmail account revoke-session`](https://nextmail.sh/docs/cli/reference/account#account-revoke-session).

### `account.revoke_sessions()`

Sign out everywhere

```python
def revoke_sessions(
    *,
    connected_apps: bool | None = None,
    api_key: str | None = None,
    timeout: float | None = None,
) -> SessionSweepResource
```

Signs the person out of every browser and phone at once, for when a device is lost or a password may have leaked. Each one is refused on its next request.

With `connected_apps=True` every connected app is removed as well, except the app making the call. A key or an app is not a signed-in device, so the call never ends its own access.

Scopes: `account:write`.

**Parameters**

- `connected_apps` (`bool`): `True` also removes every connected app, apart from the one making the call. Left out, apps stay.
- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`SessionSweepResource` with `sessionsRevoked` and `appsRevoked`.

**Example**

```python
from nextmail import nextmail

swept = nextmail.account.revoke_sessions(connected_apps=True)

print(swept['sessionsRevoked'], 'devices and', swept['appsRevoked'], 'apps signed out')
```

**Notes**

- Safe to repeat: a second call finds nothing left and answers zero for both counts.

Also available in: API [`DELETE /account/sessions`](https://nextmail.sh/docs/api/reference/your-account#delete-account-sessions); TypeScript [`nextmail.account.revokeSessions()`](https://nextmail.sh/docs/sdk/reference/account#revokeSessions); Ruby [`account.revoke_sessions`](https://nextmail.sh/docs/ruby/reference/account#revokeSessions); PHP [`account->revokeSessions`](https://nextmail.sh/docs/php/reference/account#revokeSessions); Go [`Account.RevokeSessions`](https://nextmail.sh/docs/go/reference/account#revokeSessions); Java [`account().revokeSessions`](https://nextmail.sh/docs/java/reference/account#revokeSessions); C# [`Account.RevokeSessionsAsync`](https://nextmail.sh/docs/csharp/reference/account#revokeSessions); CLI [`nextmail account revoke-sessions`](https://nextmail.sh/docs/cli/reference/account#account-revoke-sessions).

### `account.list_security_events()`

Read your security log

```python
def list_security_events(
    *,
    limit: int | None = None,
    cursor: str | None = None,
    api_key: str | None = None,
    timeout: float | None = None,
) -> Page[SecurityEventResource]
```

Returns one page of what happened to the sign-in of the account, newest first: each sign-in with its device and place, devices signed out, password changes and resets, two-factor turned on or off, and passkeys added or removed. Nothing is ever removed from it.

Scopes: `account:read`.

**Parameters**

- `limit` (`int`): Page size, from 1 to 100. The server defaults to 25.
- `cursor` (`str`): The `nextCursor` of the previous page. Leave it out for the first page.
- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`Page[SecurityEventResource]`, a dict with `items`, `hasMore` and `nextCursor`. Each item has `kind`, `at`, `device`, `country`, `city`, `authMethod` and `detail`.

**Example**

```python
from nextmail import nextmail

page = nextmail.account.list_security_events(limit=50)

for event in page['items']:
    print(event['at'], event['kind'], event['city'] or '')
```

**Notes**

- A sign-in from a device not seen before has `detail['newDevice']` set to `True`, and the person is told by email.
- A cursor that names nothing in this list is 400 `invalid_cursor`.

Also available in: API [`GET /account/security-events`](https://nextmail.sh/docs/api/reference/your-account#get-account-security-events); TypeScript [`nextmail.account.listSecurityEvents()`](https://nextmail.sh/docs/sdk/reference/account#listSecurityEvents); Ruby [`account.list_security_events`](https://nextmail.sh/docs/ruby/reference/account#listSecurityEvents); PHP [`account->listSecurityEvents`](https://nextmail.sh/docs/php/reference/account#listSecurityEvents); Go [`Account.ListSecurityEvents`](https://nextmail.sh/docs/go/reference/account#listSecurityEvents); Java [`account().listSecurityEvents`](https://nextmail.sh/docs/java/reference/account#listSecurityEvents); C# [`Account.ListSecurityEventsAsync`](https://nextmail.sh/docs/csharp/reference/account#listSecurityEvents); CLI [`nextmail account list-security-events`](https://nextmail.sh/docs/cli/reference/account#account-list-security-events).

### `account.list_all_security_events()`

Collect your whole security log into one list

```python
def list_all_security_events(
    *,
    limit: int | None = None,
    cursor: str | None = None,
    api_key: str | None = None,
    timeout: float | None = None,
) -> builtins.list[SecurityEventResource]
```

Walks every page of `list_security_events` and returns every entry in one list. The log is never pruned, so use `iterate_security_events` to stop early on an old account.

Scopes: `account:read`.

**Parameters**

- `limit` (`int`): Page size for each request, 1 to 100. The server defaults to 25.
- `cursor` (`str`): Starts the walk from this cursor instead of the newest entry.
- `api_key` (`str`): Overrides the client API key for every page of this walk.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`list[SecurityEventResource]`, newest first.

**Example**

```python
from nextmail import nextmail

events = nextmail.account.list_all_security_events(limit=100)
sign_ins = [event for event in events if event['kind'] == 'sign-in']

print(len(sign_ins), 'sign-ins on record')
```

**Notes**

- If any page fails, the call raises and the entries already fetched are discarded.

Also available in: API [`GET /account/security-events`](https://nextmail.sh/docs/api/reference/your-account#get-account-security-events); TypeScript [`nextmail.account.listAllSecurityEvents()`](https://nextmail.sh/docs/sdk/reference/account#listAllSecurityEvents); Ruby [`account.list_all_security_events`](https://nextmail.sh/docs/ruby/reference/account#listAllSecurityEvents); PHP [`account->listAllSecurityEvents`](https://nextmail.sh/docs/php/reference/account#listAllSecurityEvents); Go [`Account.ListAllSecurityEvents`](https://nextmail.sh/docs/go/reference/account#listAllSecurityEvents); Java [`account().listAllSecurityEvents`](https://nextmail.sh/docs/java/reference/account#listAllSecurityEvents); C# [`Account.ListAllSecurityEventsAsync`](https://nextmail.sh/docs/csharp/reference/account#listAllSecurityEvents).

### `account.iterate_security_events()`

Stream your security log one entry at a time

```python
def iterate_security_events(
    *,
    limit: int | None = None,
    cursor: str | None = None,
    api_key: str | None = None,
    timeout: float | None = None,
) -> Iterator[SecurityEventResource]
```

A generator over `list_security_events`, fetching a page only when the one before is drained. Nothing is requested until you start iterating.

Scopes: `account:read`.

**Parameters**

- `limit` (`int`): Page size for each request, 1 to 100. The server defaults to 25.
- `cursor` (`str`): Starts the walk from this cursor instead of the newest entry.
- `api_key` (`str`): Overrides the client API key for every page of this walk.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`Iterator[SecurityEventResource]`, a generator yielding one entry per step, newest first.

**Example**

```python
from nextmail import nextmail

for event in nextmail.account.iterate_security_events():
    if event['kind'] == 'password-changed':
        print('Password last changed', event['at'])
        break
```

**Notes**

- Breaking out of the loop stops the walk, and no further page is fetched.

Also available in: API [`GET /account/security-events`](https://nextmail.sh/docs/api/reference/your-account#get-account-security-events); TypeScript [`nextmail.account.iterateSecurityEvents()`](https://nextmail.sh/docs/sdk/reference/account#iterateSecurityEvents); Ruby [`account.iterate_security_events`](https://nextmail.sh/docs/ruby/reference/account#iterateSecurityEvents); PHP [`account->iterateSecurityEvents`](https://nextmail.sh/docs/php/reference/account#iterateSecurityEvents); Go [`Account.IterateSecurityEvents`](https://nextmail.sh/docs/go/reference/account#iterateSecurityEvents); Java [`account().iterateSecurityEvents`](https://nextmail.sh/docs/java/reference/account#iterateSecurityEvents); C# [`Account.IterateSecurityEventsAsync`](https://nextmail.sh/docs/csharp/reference/account#iterateSecurityEvents).

### `account.list_passkeys()`

List your passkeys

```python
def list_passkeys(
    *,
    api_key: str | None = None,
    timeout: float | None = None,
) -> builtins.list[PasskeyResource]
```

Returns the passkeys that can sign in to the account, oldest first, each with its name, whether it is synced between the person's devices and when it was last used.

A passkey is added on the device that holds it, in Account, Security, never through the API.

Scopes: `account:read`.

**Parameters**

- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`list[PasskeyResource]`, each with `id`, `name`, `synced`, `transports`, `createdAt` and `lastUsedAt`.

**Example**

```python
from nextmail import nextmail

passkeys = nextmail.account.list_passkeys()

for passkey in passkeys:
    print(passkey['name'], passkey['lastUsedAt'] or 'never used')
```

**Notes**

- The key itself is never returned, only its name and when it was used.

Also available in: API [`GET /account/passkeys`](https://nextmail.sh/docs/api/reference/your-account#get-account-passkeys); TypeScript [`nextmail.account.listPasskeys()`](https://nextmail.sh/docs/sdk/reference/account#listPasskeys); Ruby [`account.list_passkeys`](https://nextmail.sh/docs/ruby/reference/account#listPasskeys); PHP [`account->listPasskeys`](https://nextmail.sh/docs/php/reference/account#listPasskeys); Go [`Account.ListPasskeys`](https://nextmail.sh/docs/go/reference/account#listPasskeys); Java [`account().listPasskeys`](https://nextmail.sh/docs/java/reference/account#listPasskeys); C# [`Account.ListPasskeysAsync`](https://nextmail.sh/docs/csharp/reference/account#listPasskeys); CLI [`nextmail account list-passkeys`](https://nextmail.sh/docs/cli/reference/account#account-list-passkeys).

### `account.rename_passkey()`

Rename a passkey

```python
def rename_passkey(
    passkey_id: str,
    name: str,
    *,
    api_key: str | None = None,
    timeout: float | None = None,
) -> PasskeyResource
```

Gives a passkey a name the person will recognise, such as the device that holds it.

Scopes: `account:write`.

**Parameters**

- `passkey_id` (`str`, required): The passkey's `id` from `list_passkeys`.
- `name` (`str`, required): The new name, 1 to 60 characters.
- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`PasskeyResource` with its new `name`.

**Example**

```python
from nextmail import nextmail

passkeys = nextmail.account.list_passkeys()

if passkeys:
    renamed = nextmail.account.rename_passkey(passkeys[0]['id'], 'Work laptop')

    print(renamed['id'], renamed['name'])
```

**Notes**

- A passkey that is not on the account is a 404 `resource_not_found`.
- A name that is empty or longer than 60 characters is a 422 `invalid_parameter`.
- Retried automatically on network failure, since the same name sent twice changes nothing.

Also available in: API [`PATCH /account/passkeys/{passkeyId}`](https://nextmail.sh/docs/api/reference/your-account#patch-account-passkeys-passkeyid); TypeScript [`nextmail.account.renamePasskey()`](https://nextmail.sh/docs/sdk/reference/account#renamePasskey); Ruby [`account.rename_passkey`](https://nextmail.sh/docs/ruby/reference/account#renamePasskey); PHP [`account->renamePasskey`](https://nextmail.sh/docs/php/reference/account#renamePasskey); Go [`Account.RenamePasskey`](https://nextmail.sh/docs/go/reference/account#renamePasskey); Java [`account().renamePasskey`](https://nextmail.sh/docs/java/reference/account#renamePasskey); C# [`Account.RenamePasskeyAsync`](https://nextmail.sh/docs/csharp/reference/account#renamePasskey); CLI [`nextmail account rename-passkey`](https://nextmail.sh/docs/cli/reference/account#account-rename-passkey).

### `account.remove_passkey()`

Remove a passkey

```python
def remove_passkey(
    passkey_id: str,
    *,
    api_key: str | None = None,
    timeout: float | None = None,
) -> RemovedPasskeyResource
```

Removes a passkey, so it can no longer sign in or confirm a change. The person is told by email, and it is written to their security log. The passkey stays on the device until they delete it there.

Scopes: `account:write`.

**Parameters**

- `passkey_id` (`str`, required): The passkey's `id` from `list_passkeys`.
- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`RemovedPasskeyResource` with `removed` set to `True`.

**Example**

```python
from nextmail import NextmailApiError, nextmail

try:
    removed = nextmail.account.remove_passkey('pk_3f8a2c1e-9b47-4d6a-8e15-7c2b0a9d4f63')
except NextmailApiError as error:
    if not error.is_not_found:
        raise

    print('That passkey is already gone')
else:
    print(removed['id'], removed['removed'])
```

**Notes**

- A passkey that is not on the account is a 404 `resource_not_found`.
- Not retried automatically. A retry after a lost response is a 404, since the passkey is already gone.

Also available in: API [`DELETE /account/passkeys/{passkeyId}`](https://nextmail.sh/docs/api/reference/your-account#delete-account-passkeys-passkeyid); TypeScript [`nextmail.account.removePasskey()`](https://nextmail.sh/docs/sdk/reference/account#removePasskey); Ruby [`account.remove_passkey`](https://nextmail.sh/docs/ruby/reference/account#removePasskey); PHP [`account->removePasskey`](https://nextmail.sh/docs/php/reference/account#removePasskey); Go [`Account.RemovePasskey`](https://nextmail.sh/docs/go/reference/account#removePasskey); Java [`account().removePasskey`](https://nextmail.sh/docs/java/reference/account#removePasskey); C# [`Account.RemovePasskeyAsync`](https://nextmail.sh/docs/csharp/reference/account#removePasskey); CLI [`nextmail account remove-passkey`](https://nextmail.sh/docs/cli/reference/account#account-remove-passkey).

### `account.list_invitations()`

List your invitations

```python
def list_invitations(
    *,
    api_key: str | None = None,
    timeout: float | None = None,
) -> builtins.list[ReceivedInvitationResource]
```

Returns the invitations to join a workspace that are waiting for the address the person signs in with, oldest first. Expired, accepted and withdrawn ones are left out. The invitations a workspace sent are `members.list_invitations` instead.

Scopes: `account:read`.

**Parameters**

- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`list[ReceivedInvitationResource]`, each with `id`, `workspaceName`, `roleName`, `inviterName`, `addresses` and `expiresAt`.

**Example**

```python
from nextmail import nextmail

invitations = nextmail.account.list_invitations()

for invitation in invitations:
    print(invitation['workspaceName'], invitation['roleName'], invitation['expiresAt'])
```

**Notes**

- `addresses` counts the addresses and the whole domains the invitation gives together.

Also available in: API [`GET /account/invitations`](https://nextmail.sh/docs/api/reference/your-account#get-account-invitations); TypeScript [`nextmail.account.listInvitations()`](https://nextmail.sh/docs/sdk/reference/account#listInvitations); Ruby [`account.list_invitations`](https://nextmail.sh/docs/ruby/reference/account#listInvitations); PHP [`account->listInvitations`](https://nextmail.sh/docs/php/reference/account#listInvitations); Go [`Account.ListInvitations`](https://nextmail.sh/docs/go/reference/account#listInvitations); Java [`account().listInvitations`](https://nextmail.sh/docs/java/reference/account#listInvitations); C# [`Account.ListInvitationsAsync`](https://nextmail.sh/docs/csharp/reference/account#listInvitations); CLI [`nextmail account list-invitations`](https://nextmail.sh/docs/cli/reference/account#account-list-invitations).

### `account.accept_invitation()`

Accept an invitation

```python
def accept_invitation(
    invitation_id: str,
    *,
    activate: bool | None = None,
    api_key: str | None = None,
    timeout: float | None = None,
) -> AcceptedInvitationResource
```

Joins the workspace with the role and the addresses the invitation gives, as accepting it in the app or from its link does. `activate=True` also makes it the workspace the app opens for the person.

A workspace that asks everyone in it to sign in with two-factor authentication is refused with 403 `two_factor_required` until the person turns it on. An invitation that expired, was withdrawn or went to another address is a 422, and one that is not waiting any more a 404 `invitation_not_found`.

Scopes: `account:write`.

**Parameters**

- `invitation_id` (`str`, required): An invitation id from `list_invitations`.
- `activate` (`bool`): `True` to make it the workspace the app opens. Defaults to `False`.
- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`AcceptedInvitationResource` with `workspaceId`, `workspaceName`, `addressesGranted`, `domainsGranted` and `activated`.

**Example**

```python
from nextmail import nextmail

invitations = nextmail.account.list_invitations()

if invitations:
    joined = nextmail.account.accept_invitation(invitations[0]['id'], activate=True)

    print(joined['workspaceName'], joined['addressesGranted'], joined['activated'])
```

**Notes**

- Retried automatically on network failure, since accepting an invitation the person already accepted succeeds again and changes nothing.

Also available in: API [`POST /account/invitations/{invitationId}/accept`](https://nextmail.sh/docs/api/reference/your-account#post-account-invitations-invitationid-accept); TypeScript [`nextmail.account.acceptInvitation()`](https://nextmail.sh/docs/sdk/reference/account#acceptInvitation); Ruby [`account.accept_invitation`](https://nextmail.sh/docs/ruby/reference/account#acceptInvitation); PHP [`account->acceptInvitation`](https://nextmail.sh/docs/php/reference/account#acceptInvitation); Go [`Account.AcceptInvitation`](https://nextmail.sh/docs/go/reference/account#acceptInvitation); Java [`account().acceptInvitation`](https://nextmail.sh/docs/java/reference/account#acceptInvitation); C# [`Account.AcceptInvitationAsync`](https://nextmail.sh/docs/csharp/reference/account#acceptInvitation); CLI [`nextmail account accept-invitation`](https://nextmail.sh/docs/cli/reference/account#account-accept-invitation).

### `account.decline_invitation()`

Decline an invitation

```python
def decline_invitation(
    invitation_id: str,
    *,
    api_key: str | None = None,
    timeout: float | None = None,
) -> DeclinedInvitationResource
```

Turns the invitation down, so its link stops working, and tells whoever sent it. It cannot be taken back: they have to invite the person again. An invitation the person already accepted is refused with 409 `invitation_accepted`.

Scopes: `account:write`.

**Parameters**

- `invitation_id` (`str`, required): An invitation id from `list_invitations`.
- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `NextmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`DeclinedInvitationResource` with `declined` set to `True`.

**Example**

```python
from nextmail import nextmail

declined = nextmail.account.decline_invitation('winv_6bb640f5b99e47deb758f1f5')

print(declined['id'], declined['declined'])
```

**Notes**

- Retried automatically on network failure, since declining twice changes nothing.

Also available in: API [`POST /account/invitations/{invitationId}/decline`](https://nextmail.sh/docs/api/reference/your-account#post-account-invitations-invitationid-decline); TypeScript [`nextmail.account.declineInvitation()`](https://nextmail.sh/docs/sdk/reference/account#declineInvitation); Ruby [`account.decline_invitation`](https://nextmail.sh/docs/ruby/reference/account#declineInvitation); PHP [`account->declineInvitation`](https://nextmail.sh/docs/php/reference/account#declineInvitation); Go [`Account.DeclineInvitation`](https://nextmail.sh/docs/go/reference/account#declineInvitation); Java [`account().declineInvitation`](https://nextmail.sh/docs/java/reference/account#declineInvitation); C# [`Account.DeclineInvitationAsync`](https://nextmail.sh/docs/csharp/reference/account#declineInvitation); CLI [`nextmail account decline-invitation`](https://nextmail.sh/docs/cli/reference/account#account-decline-invitation).
