Skip to the documentation
Python

nextmail.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

Scopesaccount:readPages through results
Signature
def list(    *,    limit: int | None = None,    cursor: str | None = None,    api_key: str | None = None,    timeout: float | None = None,) -> 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 unreadCount 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 None on a kind that is about something else, so skip a kind you do not know.

Parameters

limitint

Page size, from 1 to 50. The server defaults to 20.

cursorstr

The nextCursor of the previous page. Leave it out for the first page.

api_keystr

Overrides the client's API key for this call only.

timeoutfloat

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

NotificationPage, a dict with items, unreadCount, hasMore and nextCursor. Each item is a NotificationResource with id, kind, read, readAt, notifiedAt and invitation, a NotificationInvitation with id, workspaceName, roleName, inviterName, inviterEmail, inviterImage, addresses, status and expiresAt.

Example

from nextmail import nextmail page = nextmail.notifications.list() print(page['unreadCount'], 'unread') for notification in page['items']:    invitation = notification['invitation']     if invitation is not None and invitation['status'] == 'open':        print('Invited to', invitation['workspaceName'])

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
TypeScript
notifications.list()
Ruby
notifications.list
PHP
notifications->list
Go
Notifications.List
Java
notifications().list
C#
Notifications.ListAsync
CLI
nextmail notifications list

notifications.unread_count()

Count your unread notifications

Scopesaccount:read
Signature
def unread_count(    *,    api_key: str | None = None,    timeout: float | None = None,) -> NotificationCountResource

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.

Parameters

api_keystr

Overrides the client's API key for this call only.

timeoutfloat

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

NotificationCountResource with object set to notification_count and unreadCount.

Example

from nextmail import nextmail unread = nextmail.notifications.unread_count()['unreadCount'] if unread > 0:    print(unread, 'new notifications')

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
TypeScript
notifications.unreadCount()
Ruby
notifications.unread_count
PHP
notifications->unreadCount
Go
Notifications.UnreadCount
Java
notifications().unreadCount
C#
Notifications.UnreadCountAsync
CLI
nextmail notifications unread-count

notifications.mark_read()

Mark notifications read

Scopesaccount:write
Signature
def mark_read(    ids: Sequence[str],    *,    api_key: str | None = None,    timeout: float | None = None,) -> NotificationsReadResource

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.

Parameters

idsSequence[str]Required

Notification ids from list, 1 to 100 of them.

api_keystr

Overrides the client's API key for this call only.

timeoutfloat

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

NotificationsReadResource with object set to notifications_read, marked and the unreadCount left.

Example

from nextmail import nextmail page = nextmail.notifications.list()unread = [notification['id'] for notification in page['items'] if not notification['read']] if unread:    result = nextmail.notifications.mark_read(unread)     print(result['marked'], 'marked read')

Notes

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

Also available in

API
POST /notifications/read
TypeScript
notifications.markRead()
Ruby
notifications.mark_read
PHP
notifications->markRead
Go
Notifications.MarkRead
Java
notifications().markRead
C#
Notifications.MarkReadAsync
CLI
nextmail notifications mark-read

notifications.mark_all_read()

Mark every notification read

Scopesaccount:write
Signature
def mark_all_read(    *,    api_key: str | None = None,    timeout: float | None = None,) -> NotificationsReadResource

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.

Parameters

api_keystr

Overrides the client's API key for this call only.

timeoutfloat

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

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

Example

from nextmail import nextmail result = nextmail.notifications.mark_all_read() print(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
TypeScript
notifications.markAllRead()
Ruby
notifications.mark_all_read
PHP
notifications->markAllRead
Go
Notifications.MarkAllRead
Java
notifications().markAllRead
C#
Notifications.MarkAllReadAsync
CLI
nextmail notifications mark-all-read

notifications.clear()

Clear your notifications

Scopesaccount:write
Signature
def clear(    *,    decline_invitations: bool | None = None,    api_key: str | None = None,    timeout: float | None = None,) -> NotificationsClearedResource

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.

Parameters

decline_invitationsbool

True to 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_keystr

Overrides the client's API key for this call only.

timeoutfloat

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

NotificationsClearedResource with how many notifications were cleared, how many invitations it declined (declinedInvitations), how many are still open (openInvitations) and the unreadCount left.

Example

from nextmail import nextmail result = nextmail.notifications.clear() if result['openInvitations'] > 0:    print(result['openInvitations'], 'invitations are still open and stay listed')

Notes

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

Also available in

API
POST /notifications/clear
TypeScript
notifications.clear()
Ruby
notifications.clear
PHP
notifications->clear
Go
Notifications.Clear
Java
notifications().clear
C#
Notifications.ClearAsync
CLI
nextmail notifications clear