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: their name, the email notifications they get, their profile photo and username, the apps they connected, the invitations and the offers to own a workspace 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.SetNameAccount.GetNotificationsAccount.SetEmailNotificationAccount.SetPhotoAccount.RemovePhotoAccount.GetUsernameAccount.CheckUsernameAccount.SetUsernameAccount.ListConnectedAppsAccount.ListConnectedAppRequestsAccount.ListAllConnectedAppRequestsAccount.IterateConnectedAppRequestsAccount.RevokeConnectedAppAccount.EndConnectedAppElevationAccount.ListSessionsAccount.RevokeSessionAccount.RevokeSessionsAccount.ListSecurityEventsAccount.ListAllSecurityEventsAccount.IterateSecurityEventsAccount.ListPasskeysAccount.RenamePasskeyAccount.RemovePasskeyAccount.ListSignInMethodsAccount.ConnectSignInMethodAccount.DisconnectSignInMethodAccount.ListInvitationsAccount.AcceptInvitationAccount.DeclineInvitationAccount.ListOwnershipOffersAccount.AcceptOwnershipOfferAccount.DeclineOwnershipOffer
Account.SetName
Change your name
SetName(ctx context.Context, name string, opts ...nextmail.RequestOption) (nextmail.Object, error)Sets the name of the person, the one their team sees in Nextmail and the emails Nextmail sends them greet them by, as Account, Profile does. It does not change the name mail goes out under, which belongs to each address.
Parameters
namestringRequiredThe new name, 1 to 100 characters once it is trimmed.
nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The nextmail.Object with object: 'account', id, the new name and email, the address the person signs in with.
Example
account, err := client.Account.SetName(ctx, "Ada Lovelace")if err != nil { return err} fmt.Println(account.String("name"), account.String("email"))Notes
An empty name, or one longer than 100 characters, is 422
invalid_parameteronname.Retried automatically on network failure, since the same name sent twice changes nothing.
Also available in
Account.GetNotifications
Read your notification settings
GetNotifications(ctx context.Context, opts ...nextmail.RequestOption) (nextmail.Object, error)Returns which kinds of email Nextmail sends the person, as Account, Notifications shows them. An API key answers for the workspace owner, and an app for the person who connected it.
Parameters
nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The nextmail.Object with email, one EmailNotificationSetting for each kind of email.
Example
settings, err := client.Account.GetNotifications(ctx)if err != nil { return err} fmt.Println(settings.String("object"))Notes
accountandbillingemail are always on, andrequiredsays so.
Also available in
Account.SetEmailNotification
Turn a kind of email on or off
SetEmailNotification(ctx context.Context, category string, body nextmail.Body, opts ...nextmail.RequestOption) (nextmail.Object, error)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
categorystringRequiredaccount,billing,activityorproduct.enabledboolRequiredTrue to receive that email, false to stop it.
nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The nextmail.Object as it is after the change.
Example
settings, err := client.Account.SetEmailNotification(ctx, "product", nextmail.Body{"enabled": false})if err != nil { return err} fmt.Println(settings.String("object"))Notes
Retried automatically on network failure, since the same setting sent twice changes nothing.
Also available in
- API
PUT /account/notifications/email/{category}- TypeScript
account.setEmailNotification()- Python
account.set_email_notification()- Ruby
account.set_email_notification- PHP
account->setEmailNotification- Java
account().setEmailNotification- C#
Account.SetEmailNotificationAsync- CLI
nextmail account set-email-notification
Account.SetPhoto
Set your profile photo
SetPhoto(ctx context.Context, data io.Reader, opts ...nextmail.RequestOption) (nextmail.Object, error)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 100 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 an io.Reader. The type is read from nextmail.WithContentType. Without either the bytes go as application/octet-stream and the server refuses them with 422 invalid_image.
Parameters
dataio.ReaderRequiredThe image, as an
io.Reader.nextmail.WithContentTypestringimage/png,image/jpeg,image/webporimage/gif. The server needs it to accept the image.nextmail.WithCropnextmail.ImageCropThe part of the image to keep, as a
nextmail.ImageCropwhoseX,Y,WidthandHeightare each a fraction of the image from 0 to 1, measured from its top left as it shows upright. Leave it out to keep the whole image.nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The nextmail.Object with the new url.
Example
source, err := os.Open("photo.jpg")if err != nil { return err} defer source.Close() photo, err := client.Account.SetPhoto( ctx, source, nextmail.WithContentType("image/jpeg"), nextmail.WithCrop(nextmail.ImageCrop{X: 0.125, Y: 0, Width: 0.75, Height: 1}),)if err != nil { return err} fmt.Println(photo.String("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.
A crop that does not fit inside the image is refused with 422
invalid_parameteroncrop.
Also available in
Account.RemovePhoto
Remove your profile photo
RemovePhoto(ctx context.Context, opts ...nextmail.RequestOption) (nextmail.Object, error)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
nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The nextmail.Object with url null.
Example
photo, err := client.Account.RemovePhoto(ctx)if err != nil { return err} fmt.Println(photo.String("object"))Notes
Safe to replay, so the SDK retries it after a network failure.
Also available in
Account.GetUsername
Read your username
GetUsername(ctx context.Context, opts ...nextmail.RequestOption) (nextmail.Object, error)Returns the person's username, and whether they chose it or it was made for them from their name. They can replace one made for them at any time, and change a chosen one once a year.
Parameters
nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The nextmail.Object with username and chosen.
Example
username, err := client.Account.GetUsername(ctx)if err != nil { return err} fmt.Println(username.String("username"), username.Bool("chosen"))Notes
The first read makes a username for an account that has none.
Also available in
Account.CheckUsername
Check a username
CheckUsername(ctx context.Context, username string, opts ...nextmail.RequestOption) (nextmail.Object, error)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
usernamestringRequiredUp to 60 characters before it is tidied.
nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The nextmail.Object with status, available and a message that says why.
Example
check, err := client.Account.CheckUsername(ctx, "ada.lovelace")if err != nil { return err} fmt.Println(check.Bool("available"), check.String("message"))Notes
statusiscurrentfor the username the person already has, andavailableis false for it.
Also available in
Account.SetUsername
Choose your username
SetUsername(ctx context.Context, username string, opts ...nextmail.RequestOption) (nextmail.Object, error)Chooses or changes the person's username. A username made for them can be replaced by one they choose at any time. After that it can change once a year: a change within a year of the last one is refused with 409 username_locked, and its message says when the next change is possible. The old username is never given to anyone else, so a username another account has or had is a 409 username_taken. 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 CheckUsername.
Parameters
usernamestringRequired3 to 30 lowercase letters, numbers and single dots once it is tidied.
nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The nextmail.Object with chosen: true.
Example
username, err := client.Account.SetUsername(ctx, "ada.lovelace")if err != nil { return err} fmt.Println(username.String("username"), username.String("object"))Notes
Not retried automatically, but a retry after a lost response is safe: sending the username the person already has changes nothing and answers with it.
Also available in
Account.ListConnectedApps
List your connected apps
ListConnectedApps(ctx context.Context, opts ...nextmail.RequestOption) ([]nextmail.Object, error)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
nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
A []nextmail.Object, each with clientId, name, kind, status, grant and tokenCount.
Example
apps, err := client.Account.ListConnectedApps(ctx)if err != nil { return err} for _, app := range apps { fmt.Println(app.String("name"), app.String("status"), app.Bool("current"))}Notes
A sign-in of the command line tool shows as
kind: 'cli', with its device incliDevice.
Also available in
Account.ListConnectedAppRequests
Read the request log of a connected app
ListConnectedAppRequests(ctx context.Context, clientID string, opts ...nextmail.RequestOption) (*nextmail.Page, error)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. nextmail.WithFailedOnly, nextmail.WithStatusCodes, nextmail.WithSince and nextmail.WithUntil narrow it, and they combine.
Parameters
clientIDstringRequiredThe app's
clientIdfromListConnectedApps.nextmail.WithFailedOnlyboolOnly calls answered with a status of 400 or more.
nextmail.WithStatusCodes...intOnly calls answered with one of these HTTP status codes, such as
401and403. At most 20, each from 100 to 599, sent comma-separated asstatus.nextmail.WithSincetime.TimeOnly calls at or after this instant. A
time.Time, sent as an ISO 8601 instant.nextmail.WithUntiltime.TimeOnly calls before this instant. It has to be later than
since, or the server answers 400invalid_parameter.nextmail.WithLimitintCalls per page, a whole number from 1 to 100. The server defaults to 25.
nextmail.WithCursorstringThe
NextCursorof the previous page, passed back unchanged. Leave it out for the first page.nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The *nextmail.Page with Items, HasMore and NextCursor. Each item has id, clientId, workspaceId, requestId, method, path, status, errorCode, durationMs, userAgent and createdAt.
Example
page, err := client.Account.ListConnectedAppRequests(ctx, "app_3f9c2a7b1e4d8f60", nextmail.WithFailedOnly(true), nextmail.WithLimit(50))if err != nil { return err} for _, request := range page.Items { fmt.Println(request.String("createdAt"), request.String("method"), request.String("path"), request.Int("status"), request.String("errorCode"))} fmt.Println(page.HasMore, page.NextCursor)Notes
An app the person never connected is a 404
resource_not_found, and a cursor this log did not hand out is a 400invalid_cursor.Calls made with an API key are in the request log of that key,
Keys.ListRequests, not here.
Also available in
- API
GET /account/connected-apps/{clientId}/requests- TypeScript
account.listConnectedAppRequests()- Python
account.list_connected_app_requests()- Ruby
account.list_connected_app_requests- PHP
account->listConnectedAppRequests- Java
account().listConnectedAppRequests- C#
Account.ListConnectedAppRequestsAsync- CLI
nextmail account list-connected-app-requests
Account.ListAllConnectedAppRequests
Collect the whole request log of a connected app into one slice
ListAllConnectedAppRequests(ctx context.Context, clientID string, opts ...nextmail.RequestOption) ([]nextmail.Object, error)Walks every page of ListConnectedAppRequests 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 IterateConnectedAppRequests to stop early.
Parameters
clientIDstringRequiredThe app's
clientIdfromListConnectedApps.nextmail.WithFailedOnlyboolOnly calls answered with a status of 400 or more.
nextmail.WithStatusCodes...intOnly calls answered with one of these HTTP status codes, such as
401and403. At most 20, each from 100 to 599, sent comma-separated asstatus.nextmail.WithSincetime.TimeOnly calls at or after this instant. A
time.Time, sent as an ISO 8601 instant.nextmail.WithUntiltime.TimeOnly calls before this instant. It has to be later than
since, or the server answers 400invalid_parameter.nextmail.WithLimitintPage size for each request, 1 to 100. The server defaults to 25.
nextmail.WithCursorstringStarts the walk from this cursor instead of the newest call.
nextmail.WithAPIKeystringOverrides the client API key for every page of this walk.
Returns
A []nextmail.Object, newest first.
Example
today, err := client.Account.ListAllConnectedAppRequests(ctx, "app_3f9c2a7b1e4d8f60", nextmail.WithSince(time.Now().Add(-24*time.Hour)), nextmail.WithLimit(100))if err != nil { return err} fmt.Println(len(today), "calls in the last day")Notes
If any page fails the call fails and the calls already fetched are discarded.
Also available in
- API
GET /account/connected-apps/{clientId}/requests- TypeScript
account.listAllConnectedAppRequests()- Python
account.list_all_connected_app_requests()- Ruby
account.list_all_connected_app_requests- PHP
account->listAllConnectedAppRequests- Java
account().listAllConnectedAppRequests- C#
Account.ListAllConnectedAppRequestsAsync
Account.IterateConnectedAppRequests
Stream the request log of a connected app one call at a time
IterateConnectedAppRequests(ctx context.Context, clientID string, opts ...nextmail.RequestOption) *nextmail.IteratorAn iterator over ListConnectedAppRequests under the same filters, fetching a page only when the one before is drained.
Parameters
clientIDstringRequiredThe app's
clientIdfromListConnectedApps.nextmail.WithFailedOnlyboolOnly calls answered with a status of 400 or more.
nextmail.WithStatusCodes...intOnly calls answered with one of these HTTP status codes, such as
401and403. At most 20, each from 100 to 599, sent comma-separated asstatus.nextmail.WithSincetime.TimeOnly calls at or after this instant. A
time.Time, sent as an ISO 8601 instant.nextmail.WithUntiltime.TimeOnly calls before this instant. It has to be later than
since, or the server answers 400invalid_parameter.nextmail.WithLimitintPage size for each request, 1 to 100. The server defaults to 25.
nextmail.WithCursorstringStarts the walk from this cursor instead of the newest call.
nextmail.WithAPIKeystringOverrides the client API key for every page of this walk.
Returns
The *nextmail.Iterator yielding one call per step, newest first.
Example
for request, err := range client.Account.IterateConnectedAppRequests(ctx, "app_3f9c2a7b1e4d8f60", nextmail.WithFailedOnly(true)).All() { if err != nil { return err } fmt.Println("Latest refused call at", request.String("createdAt"), request.String("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
account.iterateConnectedAppRequests()- Python
account.iterate_connected_app_requests()- Ruby
account.iterate_connected_app_requests- PHP
account->iterateConnectedAppRequests- Java
account().iterateConnectedAppRequests- C#
Account.IterateConnectedAppRequestsAsync
Account.RevokeConnectedApp
Remove a connected app
RevokeConnectedApp(ctx context.Context, clientID string, opts ...nextmail.RequestOption) (nextmail.Object, error)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
clientIDstringRequiredThe app's
clientIdfromListConnectedApps.nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The nextmail.Object with revoked: true and tokensRevoked.
Example
app, err := client.Account.RevokeConnectedApp(ctx, "app_3f9c2a7b1e4d8f60")if err != nil { return err} fmt.Println(app.String("object"))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
Account.EndConnectedAppElevation
Make a connected app ask for codes again
EndConnectedAppElevation(ctx context.Context, clientID string, opts ...nextmail.RequestOption) (nextmail.Object, error)Ends the time the person allowed the app to make the changes that ask for a verification code without one, or that a code it verified still covers, so it asks for a code again. It changes nothing else about the app, and ending it when there is none changes nothing.
Allowing an app to skip codes stays in the app, on Account, Connected apps, and never happens through the API.
Parameters
clientIDstringRequiredThe app's
clientIdfromListConnectedApps.nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The nextmail.Object with object: 'connected_app', clientId and elevatedUntil, which is always null.
Example
apps, err := client.Account.ListConnectedApps(ctx)if err != nil { return err} for _, app := range apps { if app.Bool("current") { continue } ended, err := client.Account.EndConnectedAppElevation(ctx, app.String("clientId")) if err != nil { return err } fmt.Println(ended.String("clientId"), ended.String("elevatedUntil"))}Notes
An app the person never connected is a 404.
Retried automatically on network failure, since ending an elevation that has already ended changes nothing.
Also available in
- API
DELETE /account/connected-apps/{clientId}/elevation- TypeScript
account.endConnectedAppElevation()- Python
account.end_connected_app_elevation()- Ruby
account.end_connected_app_elevation- PHP
account->endConnectedAppElevation- Java
account().endConnectedAppElevation- C#
Account.EndConnectedAppElevationAsync- CLI
nextmail account end-connected-app-elevation
Account.ListSessions
List your signed-in devices
ListSessions(ctx context.Context, opts ...nextmail.RequestOption) ([]nextmail.Object, error)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
nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
A []nextmail.Object, each with id, device, authMethod, country, city, createdAt, lastActiveAt and expiresAt.
Example
sessions, err := client.Account.ListSessions(ctx)if err != nil { return err} for _, session := range sessions { device := session.Object("device") fmt.Println(device.String("browser"), device.String("os"), session.String("city"), session.String("lastActiveAt"))}Notes
lastActiveAtis accurate to within ten minutes.authMethodis null for a device that signed in before it was recorded. Its values are inconstants.SessionAuthMethodsValues, and the kinds of device inconstants.SessionDeviceKindsValues.
Also available in
Account.RevokeSession
Sign out one device
RevokeSession(ctx context.Context, sessionID string, opts ...nextmail.RequestOption) (nextmail.Object, error)Signs one browser or phone out, as Sign out next to it in Account, Security does. Its next request is refused at once. It is written to the person's security log.
Parameters
sessionIDstringRequiredThe device's
idfromListSessions.nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The nextmail.Object with the device id and revoked: true.
Example
sessions, err := client.Account.ListSessions(ctx)if err != nil { return err} for _, session := range sessions { if session.Object("device").String("kind") != "browser" { continue } revoked, err := client.Account.RevokeSession(ctx, session.ID()) if err != nil { return err } fmt.Println(revoked.ID(), revoked.Bool("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
Account.RevokeSessions
Sign out everywhere
RevokeSessions(ctx context.Context, opts ...nextmail.RequestOption) (nextmail.Object, error)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 nextmail.WithConnectedApps(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
nextmail.WithConnectedAppsboolAlso removes every connected app, apart from the one making the call. Left out, apps stay.
nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The nextmail.Object with sessionsRevoked and appsRevoked.
Example
swept, err := client.Account.RevokeSessions(ctx, nextmail.WithConnectedApps(true))if err != nil { return err} fmt.Println(swept.Int("sessionsRevoked"), "devices and", swept.Int("appsRevoked"), "apps signed out")Notes
Safe to repeat: a second call finds nothing left and answers zero for both counts.
Also available in
Account.ListSecurityEvents
Read your security log
ListSecurityEvents(ctx context.Context, opts ...nextmail.RequestOption) (*nextmail.Page, error)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
nextmail.WithLimitintPage size, from 1 to 100. The server defaults to 25.
nextmail.WithCursorstringThe
NextCursorof the previous page. Leave it out for the first page.nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The *nextmail.Page with Items, HasMore and NextCursor. Each item has kind, at, device, country, city, authMethod and detail.
Example
page, err := client.Account.ListSecurityEvents(ctx, nextmail.WithLimit(50))if err != nil { return err} for _, event := range page.Items { fmt.Println(event.String("at"), event.String("kind"), event.String("city"))} fmt.Println(page.HasMore, page.NextCursor)Notes
A sign-in from a device not seen before has
detail.newDevice: true, and the person is told by email.Every
kindis inconstants.SecurityEventKindsValues.A cursor that names nothing in this list is 400
invalid_cursor.
Also available in
Account.ListAllSecurityEvents
Collect your whole security log into one slice
ListAllSecurityEvents(ctx context.Context, opts ...nextmail.RequestOption) ([]nextmail.Object, error)Walks every page of ListSecurityEvents. The log is never pruned, so use IterateSecurityEvents to stop early on an old account.
Parameters
nextmail.WithLimitintPage size for each request, 1 to 100. The server defaults to 25.
nextmail.WithCursorstringStarts the walk from this cursor instead of the newest entry.
nextmail.WithAPIKeystringOverrides the client API key for every page of this walk.
Returns
A []nextmail.Object, newest first.
Example
events, err := client.Account.ListAllSecurityEvents(ctx, nextmail.WithLimit(100))if err != nil { return err} signIns := 0 for _, event := range events { if event.String("kind") == "sign-in" { signIns++ }} fmt.Println(signIns, "sign-ins on record")Notes
If any page fails the call fails and the entries already fetched are discarded.
Also available in
Account.IterateSecurityEvents
Stream your security log one entry at a time
IterateSecurityEvents(ctx context.Context, opts ...nextmail.RequestOption) *nextmail.IteratorAn iterator over ListSecurityEvents, fetching a page only when the one before is drained.
Parameters
nextmail.WithLimitintPage size for each request, 1 to 100. The server defaults to 25.
nextmail.WithCursorstringStarts the walk from this cursor instead of the newest entry.
nextmail.WithAPIKeystringOverrides the client API key for every page of this walk.
Returns
The *nextmail.Iterator yielding one entry per step, newest first.
Example
for event, err := range client.Account.IterateSecurityEvents(ctx).All() { if err != nil { return err } if event.String("kind") == "password-changed" { fmt.Println("Password last changed", event.String("at")) break }}Notes
Breaking out of the loop stops the walk, and no further page is fetched.
Also available in
Account.ListPasskeys
List your passkeys
ListPasskeys(ctx context.Context, opts ...nextmail.RequestOption) ([]nextmail.Object, error)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
nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
A []nextmail.Object, each with id, name, synced, transports, createdAt and lastUsedAt.
Example
passkeys, err := client.Account.ListPasskeys(ctx)if err != nil { return err} for _, passkey := range passkeys { fmt.Println(passkey.String("name"), passkey.Bool("synced"), passkey.String("lastUsedAt"))}Notes
The key itself is never returned, only its name and when it was used.
lastUsedAtis null for a passkey that was never used, and every value oftransportsis inconstants.PasskeyTransportsValues.
Also available in
Account.RenamePasskey
Rename a passkey
RenamePasskey(ctx context.Context, passkeyID string, name string, opts ...nextmail.RequestOption) (nextmail.Object, error)Gives a passkey a name the person will recognise, such as the device that holds it.
Parameters
passkeyIDstringRequiredThe passkey's
idfromListPasskeys.namestringRequiredThe new name, 1 to 60 characters.
nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The nextmail.Object with its new name.
Example
passkey, err := client.Account.RenamePasskey(ctx, "pk_8d2f6a1c-4b7e-4c35-9a10-6e3f5b2d7c84", "Work laptop")if err != nil { return err} fmt.Println(passkey.ID(), passkey.String("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.
Also available in
Account.RemovePasskey
Remove a passkey
RemovePasskey(ctx context.Context, passkeyID string, opts ...nextmail.RequestOption) (nextmail.Object, error)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
passkeyIDstringRequiredThe passkey's
idfromListPasskeys.nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The nextmail.Object with the passkey id and removed: true.
Example
removed, err := client.Account.RemovePasskey(ctx, "pk_8d2f6a1c-4b7e-4c35-9a10-6e3f5b2d7c84")if err != nil { return err} fmt.Println(removed.ID(), removed.Bool("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
Account.ListSignInMethods
List your sign-in methods
ListSignInMethods(ctx context.Context, opts ...nextmail.RequestOption) (nextmail.Object, error)Returns every way the person signs in to the account: whether a password is set, how many passkeys can sign in, and for Google and GitHub whether each is set up on this server, whether it is connected and when, and whether it can be removed now.
canDisconnect is false for a provider that is not connected, and for the one that is the only way to sign in. The passkeys themselves are listed by ListPasskeys, and passkeys here is only how many there are.
Parameters
nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The nextmail.Object with methods, Google first and then GitHub, each with provider, configured, connected, connectedAt and canDisconnect. It also has passwordSet and passkeys, the number of passkeys.
Example
signIn, err := client.Account.ListSignInMethods(ctx)if err != nil { return err} for _, method := range signIn.Objects("methods") { fmt.Println(method.String("provider"), method.Bool("connected"), method.String("connectedAt"))}Also available in
Account.ConnectSignInMethod
Get the link that connects a sign-in method
ConnectSignInMethod(ctx context.Context, provider string, opts ...nextmail.RequestOption) (nextmail.Object, error)Returns the link that connects Google or GitHub as a way to sign in to the account. A program cannot follow the link itself, because the sign-in at the provider runs in the person's own browser. Hand the url to the person and ask them to open it while they are signed in to the account, then approve the sign-in at the provider. Nothing on the account changes until they do.
Parameters
providerstringRequiredThe sign-in provider:
googleorgithub.nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The nextmail.Object with the provider and the url to hand to the person.
Example
link, err := client.Account.ConnectSignInMethod(ctx, "github")if err != nil { return err} fmt.Println("Ask the person to open", link.String("url"), "while they are signed in")Notes
An OAuth access token needs a verification code first, and is refused with 403
step_up_requireduntil the app has verified one in the last 60 minutes. The error matchesnextmail.ErrStepUpRequired. An API key is refused with 403console_only, since a key cannot give a code, so the change is made in the console.A provider the account already has is a 409
sign_in_method_already_connected, and one this server does not set up is a 503sign_in_method_not_configured. An account whose email address is not verified, a demo account or a mailbox login is a 403sign_in_method_link_refused.Not retried automatically. Calling it changes nothing on the account.
Also available in
- API
POST /account/sign-in-methods/{provider}/connect- TypeScript
account.connectSignInMethod()- Python
account.connect_sign_in_method()- Ruby
account.connect_sign_in_method- PHP
account->connectSignInMethod- Java
account().connectSignInMethod- C#
Account.ConnectSignInMethodAsync- CLI
nextmail account connect-sign-in-method
Account.DisconnectSignInMethod
Remove a sign-in method
DisconnectSignInMethod(ctx context.Context, provider string, opts ...nextmail.RequestOption) (nextmail.Object, error)Removes Google or GitHub as a way to sign in to the account, so the provider can no longer sign the person in, and it is written to their security log. The last way to sign in cannot be removed, so connect another sign-in method first.
Parameters
providerstringRequiredThe sign-in provider:
googleorgithub.nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The nextmail.Object with the provider and removed: true.
Example
removed, err := client.Account.DisconnectSignInMethod(ctx, "github")if err != nil { return err} fmt.Println(removed.String("provider"), removed.Bool("removed"))Notes
A provider the account does not have is a 404
sign_in_method_not_connected, and removing the last way to sign in is a 409last_sign_in_method.An OAuth access token needs a verification code first, and is refused with 403
step_up_requireduntil the app has verified one in the last 60 minutes. The error matchesnextmail.ErrStepUpRequired. An API key is refused with 403console_only, since a key cannot give a code, so the change is made in the console.Not retried automatically. A retry after a lost response is a 404, since the provider is already removed.
Also available in
- API
DELETE /account/sign-in-methods/{provider}- TypeScript
account.disconnectSignInMethod()- Python
account.disconnect_sign_in_method()- Ruby
account.disconnect_sign_in_method- PHP
account->disconnectSignInMethod- Java
account().disconnectSignInMethod- C#
Account.DisconnectSignInMethodAsync- CLI
nextmail account disconnect-sign-in-method
Account.ListInvitations
List your invitations
ListInvitations(ctx context.Context, opts ...nextmail.RequestOption) ([]nextmail.Object, error)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.ListInvitations instead.
Parameters
nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
A []nextmail.Object, each with id, workspaceName, roleName, inviterName, addresses and expiresAt.
Example
invitations, err := client.Account.ListInvitations(ctx)if err != nil { return err} for _, invitation := range invitations { fmt.Println(invitation.String("workspaceName"), invitation.String("roleName"))}Notes
addressescounts the addresses and the whole domains the invitation gives together.
Also available in
Account.AcceptInvitation
Accept an invitation
AcceptInvitation(ctx context.Context, invitationID string, opts ...nextmail.RequestOption) (nextmail.Object, error)Joins the workspace with the role and the addresses the invitation gives, as accepting it in the app or from its link does. nextmail.WithActivate 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
invitationIDstringRequiredAn invitation id from
ListInvitations.nextmail.WithActivateboolTrue to make it the workspace the app opens. Defaults to false.
nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The nextmail.Object with workspaceId, workspaceName, addressesGranted, domainsGranted and activated.
Example
joined, err := client.Account.AcceptInvitation(ctx, "winv_6bb640f5b99e47deb758f1f5", nextmail.WithActivate(true))if err != nil { return err} fmt.Println(joined.String("workspaceName"))Notes
Retried automatically on network failure, since accepting an invitation the person already accepted succeeds again and changes nothing.
Also available in
Account.DeclineInvitation
Decline an invitation
DeclineInvitation(ctx context.Context, invitationID string, opts ...nextmail.RequestOption) (nextmail.Object, error)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
invitationIDstringRequiredAn invitation id from
ListInvitations.nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The nextmail.Object with declined: true.
Example
invitation, err := client.Account.DeclineInvitation(ctx, "winv_6bb640f5b99e47deb758f1f5")if err != nil { return err} fmt.Println(invitation.String("id"), invitation.String("object"))Notes
Retried automatically on network failure, since declining twice changes nothing.
Also available in
Account.ListOwnershipOffers
List the offers to own a workspace
ListOwnershipOffers(ctx context.Context, opts ...nextmail.RequestOption) ([]nextmail.Object, error)Returns the offers waiting for the person to become the owner of a workspace, in any workspace they belong to, each with the workspace, the owner who made it and when it ends unanswered. An owner makes one with Workspaces.OfferOwnership.
Parameters
nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
A []nextmail.Object, each with object: 'ownership_offer', workspaceId, workspaceName, from (userId, name and email of the owner), offeredAt and expiresAt.
Example
offers, err := client.Account.ListOwnershipOffers(ctx)if err != nil { return err} for _, offer := range offers { fmt.Println(offer.Object("from").String("email"), "offers you", offer.String("workspaceName"), "until", offer.String("expiresAt"))}Notes
An API key acts for the workspace owner, so it lists the offers made to the owner.
Also available in
Account.AcceptOwnershipOffer
Accept an offer to own a workspace
AcceptOwnershipOffer(ctx context.Context, workspaceID string, opts ...nextmail.RequestOption) (nextmail.Object, error)Makes the person the owner of the workspace that was offered to them, with its plan and billing, as answering the offer in the app does. The owner who offered it stays in it as an admin and is told.
A workspace that requires two-factor sign-in is refused with 403 two_factor_required until the person turns it on. An account that already owns a workspace on the Starter plan cannot take over another one on Starter, which is 403 workspace_allowance_reached.
An API key acts for the workspace owner, but it is still refused here with 403 console_only, so the person answers the offer in the console or through an app they connected.
Parameters
workspaceIDstringRequiredThe workspace whose owner offered it, as
ListOwnershipOfferslists it.nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The nextmail.Object with object: 'ownership_transfer', workspaceId, workspaceName, accepted: true, previousOwner and previousOwnerRoleName, the role the previous owner holds now, usually Admin.
Example
offers, err := client.Account.ListOwnershipOffers(ctx)if err != nil { return err} if len(offers) == 0 { return nil} transfer, err := client.Account.AcceptOwnershipOffer(ctx, offers[0].String("workspaceId"))if err != nil { return err} fmt.Println("You own", transfer.String("workspaceName"), "and", transfer.Object("previousOwner").String("email"), "is", transfer.String("previousOwnerRoleName"))Notes
An offer that is not waiting is a 404
ownership_offer_not_found. A workspace that changed while the answer was on its way is 409ownership_changed, an account that cannot own a workspace yet 409ownership_not_eligible, and a workspace with a domain being moved in or out 409domain_moving.An OAuth access token needs a verification code for this call, and is refused with 403
step_up_requireduntil the app has verified one in the last 60 minutes. The error matchesnextmail.ErrStepUpRequired. A key cannot give a code, which is why an API key is refused with 403console_only.Not retried automatically. A retry after a lost response is a 404
ownership_offer_not_found, since the offer was answered.
Also available in
- API
POST /account/ownership-offers/{workspaceId}/accept- TypeScript
account.acceptOwnershipOffer()- Python
account.accept_ownership_offer()- Ruby
account.accept_ownership_offer- PHP
account->acceptOwnershipOffer- Java
account().acceptOwnershipOffer- C#
Account.AcceptOwnershipOfferAsync- CLI
nextmail account accept-ownership-offer
Account.DeclineOwnershipOffer
Decline an offer to own a workspace
DeclineOwnershipOffer(ctx context.Context, workspaceID string, opts ...nextmail.RequestOption) (nextmail.Object, error)Declines the offer. The owner who made it is told, and nothing else changes: they keep the workspace and the person stays the member they were.
An API key acts for the workspace owner, but it is still refused here with 403 console_only, so the person answers the offer in the console or through an app they connected.
Parameters
workspaceIDstringRequiredThe workspace whose owner offered it, as
ListOwnershipOfferslists it.nextmail.WithAPIKeystringOverrides the client's API key for this call only.
Returns
The nextmail.Object with object: 'ownership_offer', workspaceId, workspaceName, declined: true and owner, the owner who offered it and still owns it.
Example
offers, err := client.Account.ListOwnershipOffers(ctx)if err != nil { return err} for _, offer := range offers { declined, err := client.Account.DeclineOwnershipOffer(ctx, offer.String("workspaceId")) if err != nil { return err } fmt.Println(declined.String("workspaceName"), declined.Bool("declined"))}Notes
An offer that is not waiting is a 404
ownership_offer_not_found.Not retried automatically. A retry after a lost response is a 404
ownership_offer_not_found, since the offer was answered.
Also available in
- API
POST /account/ownership-offers/{workspaceId}/decline- TypeScript
account.declineOwnershipOffer()- Python
account.decline_ownership_offer()- Ruby
account.decline_ownership_offer- PHP
account->declineOwnershipOffer- Java
account().declineOwnershipOffer- C#
Account.DeclineOwnershipOfferAsync- CLI
nextmail account decline-ownership-offer