Skip to the documentation
C#

client.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.GetNotificationsAsync

Read your notification settings

Scopesaccount:read
Signature
Task<JsonObject> GetNotificationsAsync(    string? apiKey = null,    CancellationToken cancellationToken = default)

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.

Parameters

apiKeystring?

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

cancellationTokenCancellationToken

Cancels the request.

Returns

A JsonObject with email, a list with one object for each kind of email (category, label, description, required and enabled), and mutedWorkspaces, a list of workspace ids.

Example

var settings = await client.Account.GetNotificationsAsync(); foreach (var setting in settings["email"]?.AsArray() ?? []){    Console.WriteLine($"{setting?["category"]}: {((bool?)setting?["enabled"] == true ? "on" : "off")}{((bool?)setting?["required"] == true ? ", always on" : "")}");} Console.WriteLine($"{settings["mutedWorkspaces"]?.AsArray().Count} workspaces muted on the phone");

Notes

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

Also available in

API
GET /account/notifications
TypeScript
nextmail.account.getNotifications()
Python
account.get_notifications()
Ruby
account.get_notifications
PHP
account->getNotifications
Go
Account.GetNotifications
Java
account().getNotifications
CLI
nextmail account get-notifications

Account.SetEmailNotificationAsync

Turn a kind of email on or off

Scopesaccount:write
Signature
Task<JsonObject> SetEmailNotificationAsync(    string category,    IReadOnlyDictionary<string, object?> body,    string? apiKey = null,    CancellationToken cancellationToken = default)

["enabled"] = false stops Nextmail sending the person that kind of email, and 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.

Parameters

categorystringRequired

account, billing, activity or product, also in Nextmail\Constants\EmailNotificationCategories.

enabledboolRequired

True to receive that email, false to stop it.

apiKeystring?

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

cancellationTokenCancellationToken

Cancels the request.

Returns

The same object as Account.GetNotificationsAsync, as it is after the change.

Example

using Nextmail.Constants; var settings = await client.Account.SetEmailNotificationAsync(EmailNotificationCategories.Product, new Body { ["enabled"] = false }); foreach (var setting in settings["email"]?.AsArray() ?? []){    Console.WriteLine($"{setting?["label"]}: {((bool?)setting?["enabled"] == true ? "on" : "off")}");}

Notes

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

Also available in

API
PUT /account/notifications/email/{category}
TypeScript
nextmail.account.setEmailNotification()
Python
account.set_email_notification()
Ruby
account.set_email_notification
PHP
account->setEmailNotification
Go
Account.SetEmailNotification
Java
account().setEmailNotification
CLI
nextmail account set-email-notification

Account.SetPushMutedAsync

Mute a workspace on your phone

Scopesaccount:write
Signature
Task<JsonObject> SetPushMutedAsync(    string workspaceId,    IReadOnlyDictionary<string, object?> body,    string? apiKey = null,    CancellationToken cancellationToken = default)

["muted"] = true stops the phone app notifying the person about the mail of one workspace, on every phone they signed in on, and false lets it notify them again.

Parameters

workspaceIdstringRequired

A workspace id from Workspaces.ListAsync.

mutedboolRequired

True to mute it, false to let it notify again.

apiKeystring?

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

cancellationTokenCancellationToken

Cancels the request.

Returns

The same object as Account.GetNotificationsAsync, with the new mutedWorkspaces.

Example

var settings = await client.Account.SetPushMutedAsync("10417196-e324-4283-af98-66ec62167c47", new Body { ["muted"] = true }); Console.WriteLine($"Muted on the phone: {string.Join(", ", settings["mutedWorkspaces"]?.AsArray() ?? [])}");

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}
TypeScript
nextmail.account.setPushMuted()
Python
account.set_push_muted()
Ruby
account.set_push_muted
PHP
account->setPushMuted
Go
Account.SetPushMuted
Java
account().setPushMuted
CLI
nextmail account set-push-muted

Account.SetPhotoAsync

Set your profile photo

Scopesaccount:write
Signature
Task<JsonObject> SetPhotoAsync(    Stream data,    string? contentType = null,    string? apiKey = null,    CancellationToken cancellationToken = default)

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 a readable Stream. The type is read from contentType:. Without it the bytes go as application/octet-stream and the server refuses them with 422 invalid_image.

Parameters

dataStreamRequired

The image: a readable Stream.

contentTypestring?

image/png, image/jpeg, image/webp or image/gif. Required, because a Stream carries no type of its own.

apiKeystring?

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

cancellationTokenCancellationToken

Cancels the request.

Returns

A JsonObject with the new url.

Example

await using var photoFile = File.OpenRead("photo.jpg"); var photo = await client.Account.SetPhotoAsync(photoFile, contentType: "image/jpeg"); Console.WriteLine($"New photo at {photo["url"]}"); await using var avatar = File.OpenRead("avatar.png"); photo = await client.Account.SetPhotoAsync(avatar); Console.WriteLine($"Replaced by {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
TypeScript
nextmail.account.setPhoto()
Python
account.set_photo()
Ruby
account.set_photo
PHP
account->setPhoto
Go
Account.SetPhoto
Java
account().setPhoto
CLI
nextmail account set-photo

Account.RemovePhotoAsync

Remove your profile photo

Scopesaccount:write
Signature
Task<JsonObject> RemovePhotoAsync(    string? apiKey = null,    CancellationToken cancellationToken = default)

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.

Parameters

apiKeystring?

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

cancellationTokenCancellationToken

Cancels the request.

Returns

A JsonObject with url null.

Example

var photo = await client.Account.RemovePhotoAsync(); Console.WriteLine($"{photo["url"]?.ToString() ?? "No photo, the app shows initials"}");

Notes

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

Also available in

API
DELETE /account/photo
TypeScript
nextmail.account.removePhoto()
Python
account.remove_photo()
Ruby
account.remove_photo
PHP
account->removePhoto
Go
Account.RemovePhoto
Java
account().removePhoto
CLI
nextmail account remove-photo

Account.GetUsernameAsync

Read your username

Scopesaccount:read
Signature
Task<JsonObject> GetUsernameAsync(    string? apiKey = null,    CancellationToken cancellationToken = default)

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.

Parameters

apiKeystring?

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

cancellationTokenCancellationToken

Cancels the request.

Returns

A JsonObject with username, chosen and address.

Example

var username = await client.Account.GetUsernameAsync(); Console.WriteLine($"{username["username"]}{((bool?)username["chosen"] == true ? ", chosen" : ", made from the name")}"); if (username["address"] is not null){    Console.WriteLine($"Free address: {username["address"]}");}

Notes

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

Also available in

API
GET /account/username
TypeScript
nextmail.account.getUsername()
Python
account.get_username()
Ruby
account.get_username
PHP
account->getUsername
Go
Account.GetUsername
Java
account().getUsername
CLI
nextmail account get-username

Account.CheckUsernameAsync

Check a username

Scopesaccount:read
Signature
Task<JsonObject> CheckUsernameAsync(    string username,    string? apiKey = null,    CancellationToken cancellationToken = default)

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.

Parameters

usernamestringRequired

Up to 60 characters before it is tidied.

apiKeystring?

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

cancellationTokenCancellationToken

Cancels the request.

Returns

A JsonObject with username, status, available and a message that says why.

Example

using Nextmail.Constants; var check = await client.Account.CheckUsernameAsync("Ada Lovelace"); if ((bool?)check["available"] == true){    Console.WriteLine($"{check["username"]} is free");}else if ((string?)check["status"] == UsernameStatuses.Current){    Console.WriteLine("That is already your username");}else{    Console.WriteLine($"{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
TypeScript
nextmail.account.checkUsername()
Python
account.check_username()
Ruby
account.check_username
PHP
account->checkUsername
Go
Account.CheckUsername
Java
account().checkUsername
CLI
nextmail account check-username

Account.SetUsernameAsync

Choose your username

Scopesaccount:write
Signature
Task<JsonObject> SetUsernameAsync(    string username,    string? apiKey = null,    CancellationToken cancellationToken = default)

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 Account.CheckUsernameAsync.

Parameters

usernamestringRequired

3 to 30 lowercase letters, numbers and single dots once it is tidied.

apiKeystring?

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

cancellationTokenCancellationToken

Cancels the request.

Returns

A JsonObject with username, chosen set to true and address.

Example

try{    var username = await client.Account.SetUsernameAsync("ada.lovelace");     Console.WriteLine($"You are {username["username"]}, with the address {username["address"]?.ToString() ?? "none"}");}catch (NextmailApiException error) when (error.IsConflict){    Console.WriteLine($"{(error.Code == "username_locked" ? "Your username is already chosen" : "That username is taken")}");}

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
TypeScript
nextmail.account.setUsername()
Python
account.set_username()
Ruby
account.set_username
PHP
account->setUsername
Go
Account.SetUsername
Java
account().setUsername
CLI
nextmail account set-username

Account.ListConnectedAppsAsync

List your connected apps

Scopesaccount:read
Signature
Task<IReadOnlyList<JsonObject>> ListConnectedAppsAsync(    string? apiKey = null,    CancellationToken cancellationToken = default)

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.

Parameters

apiKeystring?

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

cancellationTokenCancellationToken

Cancels the request.

Returns

A list of JsonObject items, each with clientId, name, kind, status, current, grant, tokenCount and elevatedUntil.

Example

foreach (var app in (await client.Account.ListConnectedAppsAsync())){    Console.WriteLine($"{app["name"]}{((bool?)app["current"] == true ? " (this app)" : "")}: {app["status"]}, {app["tokenCount"]} tokens");    Console.WriteLine($"  reaches {app["grant"]?["workspaceName"]?.ToString() ?? "nothing"} until {app["accessUntil"]?.ToString() ?? "it is removed"}");}

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
TypeScript
nextmail.account.listConnectedApps()
Python
account.list_connected_apps()
Ruby
account.list_connected_apps
PHP
account->listConnectedApps
Go
Account.ListConnectedApps
Java
account().listConnectedApps
CLI
nextmail account list-connected-apps

Account.ListConnectedAppRequestsAsync

Read the request log of a connected app

Scopesaccount:readPages through results
Signature
Task<Page> ListConnectedAppRequestsAsync(    string clientId,    bool? failedOnly = null,    IEnumerable<int>? statuses = null,    DateTimeOffset? since = null,    DateTimeOffset? until = null,    int? limit = null,    string? cursor = null,    string? apiKey = null,    CancellationToken cancellationToken = default)

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. failedOnly, statuses, since and until narrow it, and they combine.

Parameters

clientIdstringRequired

The app's clientId from Account.ListConnectedAppsAsync.

failedOnlybool?

Only calls answered with a status of 400 or more.

statusesIEnumerable<int>?

Only calls answered with one of these HTTP status codes, such as new[] { 401, 403 }. At most 20, each from 100 to 599, sent comma-separated as status.

sinceDateTimeOffset?

Only calls at or after this instant. A DateTimeOffset, sent as ISO 8601 in UTC.

untilDateTimeOffset?

Only calls before this instant. It has to be later than since, or the server answers 400 invalid_parameter.

limitint?

Calls per page, a whole number from 1 to 100. The server defaults to 25.

cursorstring?

The nextCursor of the previous page, passed back unchanged. Leave it out for the first page.

apiKeystring?

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

cancellationTokenCancellationToken

Cancels the request.

Returns

A Page with items, hasMore and nextCursor. Each item has id, clientId, workspaceId, requestId, method, path, status, durationMs, userAgent and createdAt, plus the error code, read with call["errorCode"].

Example

var page = await client.Account.ListConnectedAppRequestsAsync("kZ3mQ9vT2xR7pL4wN8bY1cF6hJ5sD0aE", failedOnly: true, limit: 50); foreach (var call in page){    Console.WriteLine($"{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, Keys.ListRequestsAsync, not here.

Also available in

API
GET /account/connected-apps/{clientId}/requests
TypeScript
nextmail.account.listConnectedAppRequests()
Python
account.list_connected_app_requests()
Ruby
account.list_connected_app_requests
PHP
account->listConnectedAppRequests
Go
Account.ListConnectedAppRequests
Java
account().listConnectedAppRequests
CLI
nextmail account list-connected-app-requests

Account.ListAllConnectedAppRequestsAsync

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

Scopesaccount:readPages through results
Signature
Task<IReadOnlyList<JsonObject>> ListAllConnectedAppRequestsAsync(    string clientId,    bool? failedOnly = null,    IEnumerable<int>? statuses = null,    DateTimeOffset? since = null,    DateTimeOffset? until = null,    int? limit = null,    string? cursor = null,    string? apiKey = null,    CancellationToken cancellationToken = default)

Walks every page of Account.ListConnectedAppRequestsAsync under the same filters. The log is never pruned, so give it a window unless you mean to read a busy app's whole history, or use Account.IterateConnectedAppRequestsAsync to stop early.

Parameters

clientIdstringRequired

The app's clientId from Account.ListConnectedAppsAsync.

failedOnlybool?

Only calls answered with a status of 400 or more.

statusesIEnumerable<int>?

Only calls answered with one of these HTTP status codes, such as new[] { 401, 403 }. At most 20, each from 100 to 599, sent comma-separated as status.

sinceDateTimeOffset?

Only calls at or after this instant. A DateTimeOffset, sent as ISO 8601 in UTC.

untilDateTimeOffset?

Only calls before this instant. It has to be later than since, or the server answers 400 invalid_parameter.

limitint?

Page size for each request, 1 to 100. The server defaults to 25.

cursorstring?

Starts the walk from this cursor instead of the newest call.

apiKeystring?

Overrides the client API key for every page of this walk.

cancellationTokenCancellationToken

Cancels the request in flight and the walk with it.

Returns

A list of JsonObject items, one per call with the fields Account.ListConnectedAppRequestsAsync returns, newest first.

Example

var today = await client.Account.ListAllConnectedAppRequestsAsync("kZ3mQ9vT2xR7pL4wN8bY1cF6hJ5sD0aE", since: DateTimeOffset.UtcNow.AddDays(-1), limit: 100); Console.WriteLine($"{today.Count} calls in the last day");

Notes

  • If any page fails the call throws and the calls already fetched are discarded.

Also available in

API
GET /account/connected-apps/{clientId}/requests
TypeScript
nextmail.account.listAllConnectedAppRequests()
Python
account.list_all_connected_app_requests()
Ruby
account.list_all_connected_app_requests
PHP
account->listAllConnectedAppRequests
Go
Account.ListAllConnectedAppRequests
Java
account().listAllConnectedAppRequests

Account.IterateConnectedAppRequestsAsync

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

Scopesaccount:readPages through results
Signature
IAsyncEnumerable<JsonObject> IterateConnectedAppRequestsAsync(    string clientId,    bool? failedOnly = null,    IEnumerable<int>? statuses = null,    DateTimeOffset? since = null,    DateTimeOffset? until = null,    int? limit = null,    string? cursor = null,    string? apiKey = null,    CancellationToken cancellationToken = default)

An IAsyncEnumerable<JsonObject> over Account.ListConnectedAppRequestsAsync under the same filters, fetching a page only when the one before is drained.

Parameters

clientIdstringRequired

The app's clientId from Account.ListConnectedAppsAsync.

failedOnlybool?

Only calls answered with a status of 400 or more.

statusesIEnumerable<int>?

Only calls answered with one of these HTTP status codes, such as new[] { 401, 403 }. At most 20, each from 100 to 599, sent comma-separated as status.

sinceDateTimeOffset?

Only calls at or after this instant. A DateTimeOffset, sent as ISO 8601 in UTC.

untilDateTimeOffset?

Only calls before this instant. It has to be later than since, or the server answers 400 invalid_parameter.

limitint?

Page size for each request, 1 to 100. The server defaults to 25.

cursorstring?

Starts the walk from this cursor instead of the newest call.

apiKeystring?

Overrides the client API key for every page of this walk.

cancellationTokenCancellationToken

Cancels the request in flight and the walk with it.

Returns

An IAsyncEnumerable<JsonObject> that yields one call per step, newest first.

Example

await foreach (var call in client.Account.IterateConnectedAppRequestsAsync("kZ3mQ9vT2xR7pL4wN8bY1cF6hJ5sD0aE", failedOnly: true)){    Console.WriteLine($"Latest refused call at {call["createdAt"]} to {call["path"]}");     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
TypeScript
nextmail.account.iterateConnectedAppRequests()
Python
account.iterate_connected_app_requests()
Ruby
account.iterate_connected_app_requests
PHP
account->iterateConnectedAppRequests
Go
Account.IterateConnectedAppRequests
Java
account().iterateConnectedAppRequests

Account.RevokeConnectedAppAsync

Remove a connected app

Scopesaccount:write
Signature
Task<JsonObject> RevokeConnectedAppAsync(    string clientId,    string? apiKey = null,    CancellationToken cancellationToken = default)

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.

Parameters

clientIdstringRequired

The app's clientId from Account.ListConnectedAppsAsync.

apiKeystring?

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

cancellationTokenCancellationToken

Cancels the request.

Returns

A JsonObject with clientId, revoked set to true and tokensRevoked.

Example

foreach (var app in (await client.Account.ListConnectedAppsAsync())){    if ((int?)app["tokenCount"] == 0 && (bool?)app["current"] != true)    {        var revoked = await client.Account.RevokeConnectedAppAsync(app["clientId"]!.GetValue<string>());         Console.WriteLine($"Removed {app["name"]}, {revoked["tokensRevoked"]} tokens revoked");    }}

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}
TypeScript
nextmail.account.revokeConnectedApp()
Python
account.revoke_connected_app()
Ruby
account.revoke_connected_app
PHP
account->revokeConnectedApp
Go
Account.RevokeConnectedApp
Java
account().revokeConnectedApp
CLI
nextmail account revoke-connected-app

Account.ListSessionsAsync

List your signed-in devices

Scopesaccount:read
Signature
Task<IReadOnlyList<JsonObject>> ListSessionsAsync(    string? apiKey = null,    CancellationToken cancellationToken = default)

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.

Parameters

apiKeystring?

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

cancellationTokenCancellationToken

Cancels the request.

Returns

A list of JsonObject items, each with id, device, authMethod, country, city, createdAt, lastActiveAt and expiresAt.

Example

foreach (var session in (await client.Account.ListSessionsAsync())){    var device = session["device"];     Console.WriteLine($"{device?["browser"] ?? device?["name"] ?? device?["os"]}, last used {session["lastActiveAt"]} from {session["city"]?.ToString() ?? "an unknown place"}");    Console.WriteLine($"  signed in with {session["authMethod"]?.ToString() ?? "an older sign-in"} on {session["createdAt"]}");}

Notes

  • lastActiveAt is accurate to within ten minutes.

  • authMethod is null for a device that signed in before it was recorded.

  • The values of authMethod are in Nextmail.Constants.SessionAuthMethods, and those of kind in device are in Nextmail.Constants.SessionDeviceKinds.

Also available in

API
GET /account/sessions
TypeScript
nextmail.account.listSessions()
Python
account.list_sessions()
Ruby
account.list_sessions
PHP
account->listSessions
Go
Account.ListSessions
Java
account().listSessions
CLI
nextmail account list-sessions

Account.RevokeSessionAsync

Sign out one device

Scopesaccount:write
Signature
Task<JsonObject> RevokeSessionAsync(    string sessionId,    string? apiKey = null,    CancellationToken cancellationToken = default)

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.

Parameters

sessionIdstringRequired

The device's id from Account.ListSessionsAsync.

apiKeystring?

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

cancellationTokenCancellationToken

Cancels the request.

Returns

A JsonObject with the device id and revoked set to true.

Example

using Nextmail.Constants; foreach (var session in (await client.Account.ListSessionsAsync())){    if ((string?)session["device"]?["kind"] == SessionDeviceKinds.Browser)    {        var revoked = await client.Account.RevokeSessionAsync(session["id"]!.GetValue<string>());         Console.WriteLine($"Signed out {session["device"]?["browser"]?.ToString() ?? "a browser"}, last used {session["lastActiveAt"]}: {revoked["revoked"]}");    }}

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}
TypeScript
nextmail.account.revokeSession()
Python
account.revoke_session()
Ruby
account.revoke_session
PHP
account->revokeSession
Go
Account.RevokeSession
Java
account().revokeSession
CLI
nextmail account revoke-session

Account.RevokeSessionsAsync

Sign out everywhere

Scopesaccount:write
Signature
Task<JsonObject> RevokeSessionsAsync(    bool? connectedApps = null,    string? apiKey = null,    CancellationToken cancellationToken = default)

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 connectedApps: 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.

Parameters

connectedAppsbool?

True also removes every connected app, apart from the one making the call. Left out, apps stay.

apiKeystring?

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

cancellationTokenCancellationToken

Cancels the request.

Returns

A JsonObject with sessionsRevoked and appsRevoked.

Example

var swept = await client.Account.RevokeSessionsAsync(connectedApps: true); Console.WriteLine($"{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
TypeScript
nextmail.account.revokeSessions()
Python
account.revoke_sessions()
Ruby
account.revoke_sessions
PHP
account->revokeSessions
Go
Account.RevokeSessions
Java
account().revokeSessions
CLI
nextmail account revoke-sessions

Account.ListSecurityEventsAsync

Read your security log

Scopesaccount:readPages through results
Signature
Task<Page> ListSecurityEventsAsync(    int? limit = null,    string? cursor = null,    string? apiKey = null,    CancellationToken cancellationToken = default)

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.

Parameters

limitint?

Page size, from 1 to 100. The server defaults to 25.

cursorstring?

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

apiKeystring?

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

cancellationTokenCancellationToken

Cancels the request.

Returns

A Page with items, hasMore and nextCursor. Each item has kind, at, device, country, city, authMethod and detail.

Example

var page = await client.Account.ListSecurityEventsAsync(limit: 50); foreach (var entry in page){    Console.WriteLine($"{entry["at"]} {entry["kind"]} {entry["city"]}");} if (page.HasMore){    var older = await client.Account.ListSecurityEventsAsync(limit: 50, cursor: page.NextCursor);     Console.WriteLine($"{older.Count} older entries");}

Notes

  • A sign-in from a device not seen before has newDevice set to true in detail, and the person is told by email.

  • A cursor that names nothing in this list is 400 invalid_cursor.

  • The values of kind are in Nextmail.Constants.SecurityEventKinds.

Also available in

API
GET /account/security-events
TypeScript
nextmail.account.listSecurityEvents()
Python
account.list_security_events()
Ruby
account.list_security_events
PHP
account->listSecurityEvents
Go
Account.ListSecurityEvents
Java
account().listSecurityEvents
CLI
nextmail account list-security-events

Account.ListAllSecurityEventsAsync

Collect your whole security log into one list

Scopesaccount:readPages through results
Signature
Task<IReadOnlyList<JsonObject>> ListAllSecurityEventsAsync(    int? limit = null,    string? cursor = null,    string? apiKey = null,    CancellationToken cancellationToken = default)

Walks every page of Account.ListSecurityEventsAsync. The log is never pruned, so use Account.IterateSecurityEventsAsync to stop early on an old account.

Parameters

limitint?

Page size for each request, 1 to 100. The server defaults to 25.

cursorstring?

Starts the walk from this cursor instead of the newest entry.

apiKeystring?

Overrides the client API key for every page of this walk.

cancellationTokenCancellationToken

Cancels the request in flight and the walk with it.

Returns

A list of JsonObject items, one per entry with the fields Account.ListSecurityEventsAsync returns, newest first.

Example

using Nextmail.Constants; var events = await client.Account.ListAllSecurityEventsAsync(limit: 100); Console.WriteLine($"{events.Count(entry => (string?)entry["kind"] == SecurityEventKinds.SignIn)} sign-ins on record");

Notes

  • If any page fails the call throws and the entries already fetched are discarded.

Also available in

API
GET /account/security-events
TypeScript
nextmail.account.listAllSecurityEvents()
Python
account.list_all_security_events()
Ruby
account.list_all_security_events
PHP
account->listAllSecurityEvents
Go
Account.ListAllSecurityEvents
Java
account().listAllSecurityEvents

Account.IterateSecurityEventsAsync

Stream your security log one entry at a time

Scopesaccount:readPages through results
Signature
IAsyncEnumerable<JsonObject> IterateSecurityEventsAsync(    int? limit = null,    string? cursor = null,    string? apiKey = null,    CancellationToken cancellationToken = default)

An IAsyncEnumerable<JsonObject> over Account.ListSecurityEventsAsync, fetching a page only when the one before is drained.

Parameters

limitint?

Page size for each request, 1 to 100. The server defaults to 25.

cursorstring?

Starts the walk from this cursor instead of the newest entry.

apiKeystring?

Overrides the client API key for every page of this walk.

cancellationTokenCancellationToken

Cancels the request in flight and the walk with it.

Returns

An IAsyncEnumerable<JsonObject> that yields one entry per step, newest first.

Example

using Nextmail.Constants; await foreach (var entry in client.Account.IterateSecurityEventsAsync()){    if ((string?)entry["kind"] == SecurityEventKinds.PasswordChanged)    {        Console.WriteLine($"Password last changed {entry["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
TypeScript
nextmail.account.iterateSecurityEvents()
Python
account.iterate_security_events()
Ruby
account.iterate_security_events
PHP
account->iterateSecurityEvents
Go
Account.IterateSecurityEvents
Java
account().iterateSecurityEvents

Account.ListPasskeysAsync

List your passkeys

Scopesaccount:read
Signature
Task<IReadOnlyList<JsonObject>> ListPasskeysAsync(    string? apiKey = null,    CancellationToken cancellationToken = default)

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.

Parameters

apiKeystring?

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

cancellationTokenCancellationToken

Cancels the request.

Returns

A list of JsonObject items, each with id, name, synced, transports, createdAt and lastUsedAt.

Example

foreach (var passkey in (await client.Account.ListPasskeysAsync())){    Console.WriteLine($"{passkey["name"]}{((bool?)passkey["synced"] == true ? ", synced" : ", on one device")}, last used {passkey["lastUsedAt"]?.ToString() ?? "never"}");}

Notes

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

  • The values in transports are in Nextmail.Constants.PasskeyTransports.

Also available in

API
GET /account/passkeys
TypeScript
nextmail.account.listPasskeys()
Python
account.list_passkeys()
Ruby
account.list_passkeys
PHP
account->listPasskeys
Go
Account.ListPasskeys
Java
account().listPasskeys
CLI
nextmail account list-passkeys

Account.RenamePasskeyAsync

Rename a passkey

Scopesaccount:write
Signature
Task<JsonObject> RenamePasskeyAsync(    string passkeyId,    string name,    string? apiKey = null,    CancellationToken cancellationToken = default)

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

Parameters

passkeyIdstringRequired

The passkey's id from Account.ListPasskeysAsync.

namestringRequired

The new name, 1 to 60 characters.

apiKeystring?

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

cancellationTokenCancellationToken

Cancels the request.

Returns

A JsonObject for the passkey, with its new name.

Example

var passkeys = await client.Account.ListPasskeysAsync(); if (passkeys.Count > 0){    var renamed = await client.Account.RenamePasskeyAsync(passkeys[0]["id"]!.GetValue<string>(), "Work laptop");     Console.WriteLine($"Now called {renamed["name"]}");}

Notes

Also available in

API
PATCH /account/passkeys/{passkeyId}
TypeScript
nextmail.account.renamePasskey()
Python
account.rename_passkey()
Ruby
account.rename_passkey
PHP
account->renamePasskey
Go
Account.RenamePasskey
Java
account().renamePasskey
CLI
nextmail account rename-passkey

Account.RemovePasskeyAsync

Remove a passkey

Scopesaccount:write
Signature
Task<JsonObject> RemovePasskeyAsync(    string passkeyId,    string? apiKey = null,    CancellationToken cancellationToken = default)

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.

Parameters

passkeyIdstringRequired

The passkey's id from Account.ListPasskeysAsync.

apiKeystring?

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

cancellationTokenCancellationToken

Cancels the request.

Returns

A JsonObject with the passkey id and removed set to true.

Example

try{    var removed = await client.Account.RemovePasskeyAsync("pk_2b6f0c1e-7a54-4d0b-9c3e-8f1a5d2e4b70");     Console.WriteLine($"Removed {removed["id"]}, it can no longer sign in");}catch (NextmailApiException error) when (error.IsNotFound){    Console.WriteLine("That passkey is not on the account");}

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}
TypeScript
nextmail.account.removePasskey()
Python
account.remove_passkey()
Ruby
account.remove_passkey
PHP
account->removePasskey
Go
Account.RemovePasskey
Java
account().removePasskey
CLI
nextmail account remove-passkey

Account.ListInvitationsAsync

List your invitations

Scopesaccount:read
Signature
Task<IReadOnlyList<JsonObject>> ListInvitationsAsync(    string? apiKey = null,    CancellationToken cancellationToken = default)

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.ListInvitationsAsync instead.

Parameters

apiKeystring?

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

cancellationTokenCancellationToken

Cancels the request.

Returns

A list of JsonObject items, each with id, workspaceId, workspaceName, roleName, inviterName, addresses, expiresAt and createdAt.

Example

foreach (var invitation in (await client.Account.ListInvitationsAsync())){    Console.WriteLine($"{invitation["inviterName"]} invited you to {invitation["workspaceName"]} as {invitation["roleName"]}");    Console.WriteLine($"  {invitation["addresses"]} addresses, answer by {invitation["expiresAt"]}");}

Notes

  • addresses counts the addresses and the whole domains the invitation gives together.

Also available in

API
GET /account/invitations
TypeScript
nextmail.account.listInvitations()
Python
account.list_invitations()
Ruby
account.list_invitations
PHP
account->listInvitations
Go
Account.ListInvitations
Java
account().listInvitations
CLI
nextmail account list-invitations

Account.AcceptInvitationAsync

Accept an invitation

Scopesaccount:write
Signature
Task<JsonObject> AcceptInvitationAsync(    string invitationId,    bool? activate = null,    string? apiKey = null,    CancellationToken cancellationToken = default)

Joins the workspace with the role and the addresses the invitation gives, as accepting it in the app or from its link does. activate: 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.

Parameters

invitationIdstringRequired

An invitation id from Account.ListInvitationsAsync.

activatebool?

True to make it the workspace the app opens. Defaults to false.

apiKeystring?

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

cancellationTokenCancellationToken

Cancels the request.

Returns

A JsonObject with workspaceId, workspaceName, addressesGranted, domainsGranted and activated.

Example

try{    var joined = await client.Account.AcceptInvitationAsync("winv_6bb640f5b99e47deb758f1f5", activate: true);     Console.WriteLine($"Joined {joined["workspaceName"]} with {joined["addressesGranted"]} addresses and {joined["domainsGranted"]} domains");}catch (NextmailApiException error) when (error.IsPermission){    Console.WriteLine(error.Code == "two_factor_required" ? "Turn on two-factor sign-in first" : error.Message);}

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
TypeScript
nextmail.account.acceptInvitation()
Python
account.accept_invitation()
Ruby
account.accept_invitation
PHP
account->acceptInvitation
Go
Account.AcceptInvitation
Java
account().acceptInvitation
CLI
nextmail account accept-invitation

Account.DeclineInvitationAsync

Decline an invitation

Scopesaccount:write
Signature
Task<JsonObject> DeclineInvitationAsync(    string invitationId,    string? apiKey = null,    CancellationToken cancellationToken = default)

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.

Parameters

invitationIdstringRequired

An invitation id from Account.ListInvitationsAsync.

apiKeystring?

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

cancellationTokenCancellationToken

Cancels the request.

Returns

A JsonObject with the invitation id and declined set to true.

Example

var declined = await client.Account.DeclineInvitationAsync("winv_6bb640f5b99e47deb758f1f5"); if ((bool?)declined["declined"] == true){    Console.WriteLine("Declined, and the sender has been told");}

Notes

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

Also available in

API
POST /account/invitations/{invitationId}/decline
TypeScript
nextmail.account.declineInvitation()
Python
account.decline_invitation()
Ruby
account.decline_invitation
PHP
account->declineInvitation
Go
Account.DeclineInvitation
Java
account().declineInvitation
CLI
nextmail account decline-invitation