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

# client.notifications

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

## Methods

What the bell in the app shows the person behind the key or the app: the invitations to join a workspace sent to their address, read or unread, open or answered, with the count of unread ones and a way to mark them read.

### `notifications.list`

List your notifications

```ruby
list(limit: nil, cursor: nil, api_key: nil) -> Nextmail::NotificationPage
```

Returns one page of the notifications of the person behind the key or the app, newest first, as the bell in the app lists them, with `unread_count` for every unread one on any page.

Today each notification is an invitation to join a workspace, sent to the address the person signs in with. It stays listed once it is answered, withdrawn or expires, and `invitation[:status]` says which: `open`, `accepted`, `declined`, `withdrawn` or `expired`. Answer an open one with `account.accept_invitation` or `account.decline_invitation` and the id in `invitation[:id]`, which also marks it read. New kinds of notification will be added, and `invitation` is nil on a kind that is about something else, so skip a `kind` you do not know.

Scopes: `account:read`.

**Parameters**

- `limit` (`Integer`): Page size, from 1 to 50. The server defaults to 20.
- `cursor` (`String`): The `next_cursor` of the previous page. Leave it out for the first page.
- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

The `Nextmail::NotificationPage` with `items`, `unread_count`, `has_more?` and `next_cursor`. Each notification is a Hash with `id`, `kind`, `read`, `readAt`, `notifiedAt` and `invitation`, a Hash with `id`, `workspaceName`, `roleName`, `inviterName`, `inviterEmail`, `inviterImage`, `addresses`, `status` and `expiresAt`.

**Example**

```ruby
page = client.notifications.list

puts "#{page.unread_count} unread"

page.items.each do |notification|
  invitation = notification[:invitation]
  puts "Invited to #{invitation[:workspaceName]}" if invitation && invitation[:status] == "open"
end
```

**Notes**

- An invitation sent again comes back to the top unread, so `notifiedAt` is when the person was last told, not when the invitation was first sent.
- A cursor that names nothing in this list is 400 `invalid_cursor`.

Also available in: API [`GET /notifications`](https://nextmail.sh/docs/api/reference/your-account#get-notifications); TypeScript [`notifications.list()`](https://nextmail.sh/docs/sdk/reference/notifications#list); Python [`notifications.list()`](https://nextmail.sh/docs/python/reference/notifications#list); PHP [`notifications->list`](https://nextmail.sh/docs/php/reference/notifications#list); Go [`Notifications.List`](https://nextmail.sh/docs/go/reference/notifications#list); Java [`notifications().list`](https://nextmail.sh/docs/java/reference/notifications#list); C# [`Notifications.ListAsync`](https://nextmail.sh/docs/csharp/reference/notifications#list); CLI [`nextmail notifications list`](https://nextmail.sh/docs/cli/reference/notifications#notifications-list).

### `notifications.unread_count`

Count your unread notifications

```ruby
unread_count(api_key: nil) -> Hash
```

Returns how many notifications the person behind the key or the app has not read yet, the number on the bell in the app. It is cheaper than `list`, so poll this one and list only when it changes.

Scopes: `account:read`.

**Parameters**

- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash with `object` set to `notification_count` and `unreadCount`.

**Example**

```ruby
unread = client.notifications.unread_count[:unreadCount]

puts "#{unread} new notifications" if unread.positive?
```

**Notes**

- An invitation sent to the person before they signed up counts as soon as they have an account.

Also available in: API [`GET /notifications/unread-count`](https://nextmail.sh/docs/api/reference/your-account#get-notifications-unread-count); TypeScript [`notifications.unreadCount()`](https://nextmail.sh/docs/sdk/reference/notifications#unreadCount); Python [`notifications.unread_count()`](https://nextmail.sh/docs/python/reference/notifications#unreadCount); PHP [`notifications->unreadCount`](https://nextmail.sh/docs/php/reference/notifications#unreadCount); Go [`Notifications.UnreadCount`](https://nextmail.sh/docs/go/reference/notifications#unreadCount); Java [`notifications().unreadCount`](https://nextmail.sh/docs/java/reference/notifications#unreadCount); C# [`Notifications.UnreadCountAsync`](https://nextmail.sh/docs/csharp/reference/notifications#unreadCount); CLI [`nextmail notifications unread-count`](https://nextmail.sh/docs/cli/reference/notifications#notifications-unread-count).

### `notifications.mark_read`

Mark notifications read

```ruby
mark_read(ids, api_key: nil) -> Hash
```

Marks the notifications with these ids read, up to 100 at a time. An id that is already read, or that is not one of the person's notifications, is skipped, so `marked` counts only the ones that changed. Reading a notification never answers it: an open invitation stays open.

Scopes: `account:write`.

**Parameters**

- `ids` (`Array<String>`, required): Notification ids from `list`, 1 to 100 of them.
- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash with `object` set to `notifications_read`, `marked` and the `unreadCount` left.

**Example**

```ruby
unread = client.notifications.list.items.reject { |notification| notification[:read] }.map { |notification| notification[:id] }

unless unread.empty?
  result = client.notifications.mark_read(unread)

  puts "#{result[:marked]} marked read"
end
```

**Notes**

- Retried automatically on network failure, since marking a notification read twice changes nothing.

Also available in: API [`POST /notifications/read`](https://nextmail.sh/docs/api/reference/your-account#post-notifications-read); TypeScript [`notifications.markRead()`](https://nextmail.sh/docs/sdk/reference/notifications#markRead); Python [`notifications.mark_read()`](https://nextmail.sh/docs/python/reference/notifications#markRead); PHP [`notifications->markRead`](https://nextmail.sh/docs/php/reference/notifications#markRead); Go [`Notifications.MarkRead`](https://nextmail.sh/docs/go/reference/notifications#markRead); Java [`notifications().markRead`](https://nextmail.sh/docs/java/reference/notifications#markRead); C# [`Notifications.MarkReadAsync`](https://nextmail.sh/docs/csharp/reference/notifications#markRead); CLI [`nextmail notifications mark-read`](https://nextmail.sh/docs/cli/reference/notifications#notifications-mark-read).

### `notifications.mark_all_read`

Mark every notification read

```ruby
mark_all_read(api_key: nil) -> Hash
```

Marks every notification of the person behind the key or the app read, as Mark all as read in the app does, and clears the number on the bell. Open invitations stay open and can still be answered.

Scopes: `account:write`.

**Parameters**

- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash with `marked` and the `unreadCount` left, which is 0 unless a notification arrived meanwhile.

**Example**

```ruby
result = client.notifications.mark_all_read

puts "#{result[:marked]} marked read"
```

**Notes**

- Retried automatically on network failure, since marking everything read twice changes nothing.

Also available in: API [`POST /notifications/read-all`](https://nextmail.sh/docs/api/reference/your-account#post-notifications-read-all); TypeScript [`notifications.markAllRead()`](https://nextmail.sh/docs/sdk/reference/notifications#markAllRead); Python [`notifications.mark_all_read()`](https://nextmail.sh/docs/python/reference/notifications#markAllRead); PHP [`notifications->markAllRead`](https://nextmail.sh/docs/php/reference/notifications#markAllRead); Go [`Notifications.MarkAllRead`](https://nextmail.sh/docs/go/reference/notifications#markAllRead); Java [`notifications().markAllRead`](https://nextmail.sh/docs/java/reference/notifications#markAllRead); C# [`Notifications.MarkAllReadAsync`](https://nextmail.sh/docs/csharp/reference/notifications#markAllRead); CLI [`nextmail notifications mark-all-read`](https://nextmail.sh/docs/cli/reference/notifications#notifications-mark-all-read).

### `notifications.clear`

Clear your notifications

```ruby
clear(decline_invitations: nil, api_key: nil) -> Hash
```

Removes the notifications of the person behind the key or the app, as Clear notifications in the app does. The notification of an invitation that is still open stays, because the invitation still waits for an answer, unless `decline_invitations:` is true: then every open invitation is declined first, as `account.decline_invitation` declines one, and its notification goes too. A declined invitation cannot be accepted, so only a new invitation brings the person in.

Scopes: `account:write`.

**Parameters**

- `decline_invitations` (`Boolean`): Decline every invitation that is still open first, so its notification goes too. False when left out, which keeps open invitations and their notifications.
- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash with `object` set to `notifications_cleared`, how many notifications were `cleared`, how many invitations it declined (`declinedInvitations`), how many are still open (`openInvitations`) and the `unreadCount` left.

**Example**

```ruby
result = client.notifications.clear

puts "#{result[:openInvitations]} invitations are still open and stay listed" if result[:openInvitations].positive?
```

**Notes**

- Retried automatically on network failure, since clearing again removes nothing more and declines nothing twice.

Also available in: API [`POST /notifications/clear`](https://nextmail.sh/docs/api/reference/your-account#post-notifications-clear); TypeScript [`notifications.clear()`](https://nextmail.sh/docs/sdk/reference/notifications#clear); Python [`notifications.clear()`](https://nextmail.sh/docs/python/reference/notifications#clear); PHP [`notifications->clear`](https://nextmail.sh/docs/php/reference/notifications#clear); Go [`Notifications.Clear`](https://nextmail.sh/docs/go/reference/notifications#clear); Java [`notifications().clear`](https://nextmail.sh/docs/java/reference/notifications#clear); C# [`Notifications.ClearAsync`](https://nextmail.sh/docs/csharp/reference/notifications#clear); CLI [`nextmail notifications clear`](https://nextmail.sh/docs/cli/reference/notifications#notifications-clear).
