nextmail.members
Every method in this namespace: its signature, its parameters, what it returns and an example.
Methods
People who share the workspace, their role and the addresses they may use, the invitations still waiting, and directory sync, through which a company directory adds people and takes them out again.
members.list()members.list_all()members.iterate()members.get()members.add()members.update()members.remove()members.grant_address()members.revoke_address()members.grant_domain()members.revoke_domain()members.list_invitations()members.list_all_invitations()members.iterate_invitations()members.revoke_invitation()members.resend_invitation()members.get_directory_sync()members.connect_directory_sync()members.disconnect_directory_sync()members.list_directory_people()members.set_directory_default_role()members.set_directory_group_role()
members.list()
List everybody with access to the workspace
def list( *, limit: int | None = None, cursor: str | None = None, q: str | None = None, api_key: str | None = None, timeout: float | None = None,) -> Page[MemberResource]Returns one page of the workspace's members, the owner first and the rest by email. list_all collects every page into one list and iterate walks them lazily. Each row carries two axes that a client must not merge: role and permissions say what the person may do, and addresses and domains say what they may do it to, each with its own access. A whole domain reaches every address on it, including ones made later. A send needs both axes, so emails:send with nothing granted sends from nothing.
The one exception is addresses:all. When permissions holds it, the person reaches every address on every domain of the workspace, including ones added later, and sends as any of them when permissions also holds emails:send. addresses and domains still list only the grants made to them directly, which they may have kept from before or been given since, or none at all. Read reach from permissions first, and from those two lists only when it lacks addresses:all.
The list is a union of people with a membership row and people who only hold address or domain grants and no membership row. The second group comes back with implied set to True and with role['id'] and createdAt set to None, and their role is inferred from their grants: Member if any grant has access set to member, Viewer otherwise. Until someone calls update for them, widening their addresses silently widens what they may do.
The workspace owner is the FIRST row, with isOwner set to True, so an unshared workspace returns one member rather than an empty page. They hold every permission by definition, and add, update and remove refuse them with member_is_owner. Skip the row whose isOwner is True when counting seats.
Parameters
limitintPage size, from 1 to 100. The server defaults to 25.
cursorstrThe
nextCursorof the previous page. Leave it out for the first page.qstrNarrows to people whose name, email, user id, role, or one of the addresses and domains they were given matches, up to 200 characters. Every word has to appear in one of them, ignoring case and accents, and when nothing matches exactly the search allows for a typo instead.
api_keystrOverrides the client API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
Page[MemberResource], a dict with items, hasMore and nextCursor. Each item has userId, email, name, image, isOwner, role, implied, permissions, addresses, domains and createdAt.
Example
from nextmail import nextmail page = nextmail.members.list(limit=50) for member in page['items']: if member['implied']: print(member['email'], member['role']['name'], len(member['addresses'])) if page['hasMore']: print('more after', page['nextCursor'])Notes
Every other method here takes
user_id, the account id inuserId, not the email address.An access token acting for the member who connected a mailbox, whose role lacks
members:readbut whose app was given it, gets only the people that member can give the mailbox to:userId,email,nameandimage, with the role, permissions, addresses and domains empty and without the owner.An address granted with
accessset toviewerblocks sending from it even when the role holdsemails:send, unless the role also holdsaddresses:all. Otherwise the two axes are ANDed, never added.The cursor is opaque and holds where the last row sat in this order, so a row deleted or edited between pages never breaks the walk: the next page starts at the first row that sorts after it. A cursor this list did not hand out is a 400
invalid_cursor.
Also available in
- API
GET /members- TypeScript
members.list()- Ruby
members.list- PHP
members->list- Go
Members.List- Java
members().list- C#
Members.ListAsync- CLI
nextmail members list
members.list_all()
Collect every member into one list
def list_all( *, limit: int | None = None, cursor: str | None = None, q: str | None = None, api_key: str | None = None, timeout: float | None = None,) -> builtins.list[MemberResource]Walks every page of list and returns all members in one list, the owner first and the rest by email. One request per page.
Parameters
limitintPage size for each request, from 1 to 100. The server defaults to 25.
cursorstrStarts the walk after this cursor instead of the first page.
qstrNarrows to people whose name, email, user id, role, or one of the addresses and domains they were given matches, up to 200 characters. Every word has to appear in one of them, ignoring case and accents, and when nothing matches exactly the search allows for a typo instead.
api_keystrOverrides the client API key for every page of this walk.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
list[MemberResource] holding every member.
Example
from nextmail import nextmail members = nextmail.members.list_all(limit=100)seats = [member for member in members if not member['isOwner']] print(len(seats), 'seats in use')Notes
If any page fails, the call raises and the members already fetched are discarded.
Also available in
members.iterate()
Stream the members one at a time
def iterate( *, limit: int | None = None, cursor: str | None = None, q: str | None = None, api_key: str | None = None, timeout: float | None = None,) -> Iterator[MemberResource]Returns a generator that yields members one at a time, the owner first and the rest by email, and requests the next page only once the current one is used up. Nothing is fetched until the loop starts, and breaking out of it stops the requests.
Parameters
limitintPage size for each request, from 1 to 100. The server defaults to 25.
cursorstrStarts the walk after this cursor instead of the first page.
qstrNarrows to people whose name, email, user id, role, or one of the addresses and domains they were given matches, up to 200 characters. Every word has to appear in one of them, ignoring case and accents, and when nothing matches exactly the search allows for a typo instead. Sent with every page.
api_keystrOverrides the client API key for every page of this walk.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
Iterator[MemberResource], a generator yielding one member per step.
Example
from nextmail import nextmail for member in nextmail.members.iterate(): addresses = [grant['address'] for grant in member['addresses']] print(member['email'], member['role']['name'], addresses)Notes
The generator is lazy, so an abandoned loop costs only the pages you consumed.
Also available in
- API
GET /members- TypeScript
members.iterate()- Ruby
members.iterate- PHP
members->iterate- Go
Members.Iterate- Java
members().iterate- C#
Members.IterateAsync
members.get()
Read one member by account id
def get( user_id: str, *, api_key: str | None = None, timeout: float | None = None,) -> MemberResourceReturns a single member with their role, resolved permissions and address grants. The lookup runs over the same union as list, so a legacy grant holder with no membership row is found here too, with implied set to True, and the owner's account id returns their row, with isOwner set to True.
The path takes the account id from list, not an email. An email can change on the account, and a stale one would point at the wrong person.
Parameters
user_idstrRequiredThe account id from
list, not the email address.api_keystrOverrides the client API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
MemberResource with role (id, name, builtin), implied, the resolved permissions, and addresses holding addressId, address and access.
Example
from nextmail import nextmail member = nextmail.members.get('q7Vd3kX9mT2pLw8RzN4bYc6HfJ1sGa5E') print(member['role']['name'], member['implied'])print([(grant['address'], grant['access']) for grant in member['addresses']])Notes
A missing member is 404
resource_not_found.For an implied member,
permissionsare the Member or Viewer template permissions, not a stored role thatroles.getcould read.
Also available in
- API
GET /members/{userId}- TypeScript
members.get()- Ruby
members.get- PHP
members->get- Go
Members.Get- Java
members().get- C#
Members.GetAsync- CLI
nextmail members get
members.add()
Invite somebody to the workspace with a role
def add( body: MemberAdd, *, api_key: str | None = None, timeout: float | None = None,) -> InvitationResourceSends an invitation to join the workspace. Whether or not the address already has an account on Nextmail, the answer is an invitation rather than a member: nobody is put into a workspace without accepting, and this method is held to the same rule as the app.
The invitation carries the role, the addresses and the whole domains you name, and grants exactly those the moment it is accepted. Nothing is granted before that. Calling it again for the same address within ten minutes is refused with 409 invitation_too_soon. After that it refreshes the one outstanding invitation rather than sending a second.
Somebody already in the workspace is refused with 422 member_is_owner. Change what an existing member may do with update, grant_address and revoke_address, which only work on people already in.
Role and grants are separate axes. access applies to every id in addressIds and domainIds, and it never widens the role: an access of member under a role without emails:send still cannot send. A role holding addresses:all reaches every address without any ids, and no key or access token can invite with one, because none of them holds that console-only permission.
Parameters
body['email']strRequiredWho to invite. Trimmed and lowercased. It does not need to have an account yet.
body['roleId']strRequiredRole id from
roles.list. The owner role is refused with 409role_immutable, and a role holding more than the key itself holds is refused with 403insufficient_authority. That covers every role with a console-only permission in it, such asaddresses:all.body['addressIds']list[str]Up to 64 address ids on this workspace the invitation carries, all at
access.body['domainIds']list[str]Up to 64 domain ids on this workspace the invitation carries, all at
access. A whole domain covers every address on it, including ones made later.body['access']MemberAccessmemberreads and sends as the granted addresses,vieweronly reads them. Defaults tomember.api_keystrOverrides the client API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
InvitationResource, answered with a 202: the invitation id, what it carries, when it expires, and delivered, which is False when the email did not leave the mail server.
Example
from nextmail import nextmail invitation = nextmail.members.add( { 'email': '[email protected]', 'roleId': 'role_8b1f4c2e9a7d3b60e5f1a2c4', 'domainIds': ['93542ff8-2baa-4f2f-841d-5ceaa074ab0d'], 'access': 'member', }) print(invitation['id'], invitation['delivered'], invitation['expiresAt'])Notes
An unknown
roleIdis 404role_not_foundwithparamset toroleId. An address or domain id that is not on this workspace is 422member_not_foundwithparamset toaddressIdordomainId.The workspace owner, and anybody already in the workspace, is refused with 422
member_is_owner.deliveredset toFalsemeans the invitation exists but the email did not go out. Send it again withresend_invitation, or from the app, once the ten minute cooldown has passed.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.is_step_up_requiredon the error says so. An API key is never asked for a code.Not retried automatically. Re-posting the same body inside ten minutes is 409 rather than a duplicate.
Also available in
- API
POST /members- TypeScript
members.add()- Ruby
members.add- PHP
members->add- Go
Members.Add- Java
members().add- C#
Members.AddAsync- CLI
nextmail members add
members.update()
Change the role a member holds
def update( user_id: str, patch: MemberPatch, *, api_key: str | None = None, timeout: float | None = None,) -> MemberResourceMoves a member to a different role and changes nothing else, for somebody ALREADY in the workspace. Their address and domain grants are untouched, and grants cannot be patched here at all: grant_address and revoke_address change one grant at a time.
This is also how a legacy grant holder stops being implied. They have address or domain grants and no membership row, this writes one, and from then on implied is False and their permissions come from a role someone chose rather than from what their access implied.
Nobody joins through update. An account that is not in the workspace is 422 member_not_found: invite them with add and they are in once they accept. The owner role cannot be handed out, which is 409 role_immutable, and the workspace owner cannot be given a role, which is 422 member_is_owner.
Parameters
user_idstrRequiredThe account id from
list, not the email address.patch['roleId']strRequiredId of the role to move them to.
api_keystrOverrides the client API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
MemberResource with the new role and permissions, and implied set to False.
Example
from nextmail import nextmail member = nextmail.members.update( 'q7Vd3kX9mT2pLw8RzN4bYc6HfJ1sGa5E', {'roleId': 'role_2c7e9a1f4b8d3e60c5a7f1b9'}) print(member['role']['name'], member['implied'])Notes
The account has to be in the workspace already, by membership row or by a grant. Anybody else is 422
member_not_found. Useaddto invite them.An unknown
roleIdis 404role_not_found, and a user id with no Nextmail account behind it is 404user_not_found.A role holding more than the key itself holds is 403
insufficient_authority. No key or access token holds a console-only permission, so a role withaddresses:all, billing orworkspace:managein it is handed out only in the app. That includes the seeded Admin, which holds billing.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.is_step_up_requiredon the error says so. An API key is never asked for a code.Retried automatically on network failure, since it names the role it wants and a replay lands on the same row.
Also available in
members.remove()
Remove a member and every address grant they hold
def remove( user_id: str, *, api_key: str | None = None, timeout: float | None = None,) -> RemovedMemberResourceTakes somebody out of the workspace entirely: the membership row and every address grant they hold on it. Removing only the row would drop them from the list while they kept reading the mail, so both go together.
It does not 404 for somebody who is not a member. The people this most needs to reach are legacy grant holders with no membership row, so there is no existence check, and addressesRevoked reports what actually happened. Zero is the honest answer for a no-op.
Their account, their sent mail and anything they wrote are untouched. Only their access to this workspace ends.
Parameters
user_idstrRequiredThe account id from
list, not the email address.api_keystrOverrides the client API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
RemovedMemberResource with object set to member, the userId, deleted set to True and addressesRevoked.
Example
from nextmail import nextmail removed = nextmail.members.remove('q7Vd3kX9mT2pLw8RzN4bYc6HfJ1sGa5E') print(removed['deleted'], removed['addressesRevoked'])Notes
Idempotent on the server, but the SDK does not retry it automatically, so repeat it yourself after a network failure.
The workspace owner is refused with 422
member_is_owner, because their access never came from a membership.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.is_step_up_requiredon the error says so. An API key is never asked for a code.
Also available in
members.grant_address()
Grant a member one address or change their access to it
def grant_address( user_id: str, body: MemberAddressGrant, *, api_key: str | None = None, timeout: float | None = None,) -> MemberResourceGives one person one address on this workspace, or changes the access they already have to it. It is an upsert: there is one grant per person and address, so posting again with a different access turns a viewer into a member rather than adding a second grant.
This is the address axis and it cannot widen the role. An access of member lets somebody send as the address only if their role also holds emails:send, and otherwise it lets them read.
Granting an address to an account with no membership row makes them appear in list as an implied member whose role is inferred from their grants, so call update as well if the role should be a decision. The whole member comes back, which lets a client redraw the row without another read.
Parameters
user_idstrRequiredThe account id from
list, not the email address.body['addressId']strRequiredId of an address on this workspace.
body['access']MemberAccessmemberreads and sends as the address,vieweronly reads it. Defaults tomember.api_keystrOverrides the client API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
MemberResource with the grant applied, including the full addresses list.
Example
from nextmail import nextmail member = nextmail.members.grant_address( 'q7Vd3kX9mT2pLw8RzN4bYc6HfJ1sGa5E', {'addressId': '4f0c1b6e-2d7a-4a9e-8c35-91b2e7d4f6a0', 'access': 'viewer'},) print([(grant['address'], grant['access']) for grant in member['addresses']])Notes
An address id that is not on this workspace is 422 with code
member_not_foundandparamset toaddressId.The workspace owner is refused with 422
member_is_owner, since they already reach every address, and the member who connected a mailbox at the address with 422member_is_connector, since they already have it in full. A user id with no Nextmail account behind it is 404user_not_found.Gated on
members:writerather than on owning the address, so an admin who owns nothing can still manage grants.The member who connected a mailbox may give its address without
members:writein their role, through an access token whose app was givenmembers:write. That token reaches the connected address alone.A workspace whose plan has no team access is refused with 403
plan_required, and an access token acting for a member can only give an address that member reaches, at the level they reach it, or it is refused with 403insufficient_authority. A grant that changes the access is written to the workspace security log asaddress-access-granted.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.is_step_up_requiredon the error says so. An API key is never asked for a code.Retried automatically on network failure, since replaying the same grant lands on the same row.
Also available in
members.revoke_address()
Take one address back from a member
def revoke_address( user_id: str, address_id: str, *, api_key: str | None = None, timeout: float | None = None,) -> MemberResourceRemoves one address grant and leaves the person in the workspace with their role and their other addresses. This is the narrow revocation to use when somebody changes team.
An address id that is not on this workspace is refused with 422 member_not_found rather than ignored, so a typo cannot report a revocation that never happened. An address that is on the workspace but was never granted to this person is a silent no-op, and the member comes back unchanged.
The member is returned rather than a tombstone, because the useful answer is what they can still reach.
Parameters
user_idstrRequiredThe account id from
list, not the email address.address_idstrRequiredId of an address on this workspace.
api_keystrOverrides the client API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
MemberResource with the remaining addresses.
Example
from nextmail import nextmail member = nextmail.members.revoke_address( 'q7Vd3kX9mT2pLw8RzN4bYc6HfJ1sGa5E', '4f0c1b6e-2d7a-4a9e-8c35-91b2e7d4f6a0') print([grant['address'] for grant in member['addresses']])Notes
Revoking the last grant of an implied member removes them from the workspace entirely. The call still succeeds and returns the member as they stood, without that address.
Somebody who is not a member of this workspace is a 404.
The member who connected a mailbox at the address keeps it while they are in the workspace, so taking it from them is refused with 422
member_is_connector. Disconnect the mailbox withconnected_mailboxes.disconnect, or remove them withremove, instead.The member who connected a mailbox may take its address back from anybody else without
members:writein their role, through an access token whose app was givenmembers:write.An access token acting for a member can only take back a grant that member reaches at the same level, or it is refused with 403
insufficient_authority. A revocation that removed a grant is written to the workspace security log asaddress-access-revoked.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.is_step_up_requiredon the error says so. An API key is never asked for a code.Not retried automatically by the SDK.
Also available in
members.grant_domain()
Grant a member a whole domain or change their access to it
def grant_domain( user_id: str, body: MemberDomainGrant, *, api_key: str | None = None, timeout: float | None = None,) -> MemberResourceGives one person every address on one domain of this workspace, including addresses added after the grant, or changes the access they already have to it. It is an upsert: there is one grant per person and domain, so calling it again with a different access turns a viewer into a member rather than adding a second grant.
This is the address axis and it cannot widen the role. An access of member lets somebody send from the domain only if their role also holds emails:send, and otherwise it lets them read.
The person has to be in the workspace already, so invite them with add first. The whole member comes back, with the grant in domains.
Parameters
user_idstrRequiredThe account id from
list, not the email address.body['domainId']strRequiredId of a domain on this workspace, as
domains.listreturns it.body['access']MemberAccessmemberreads and sends from the domain,vieweronly reads it. Defaults tomember.api_keystrOverrides the client API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
MemberResource with the grant applied, including the full domains list.
Example
from nextmail import nextmail member = nextmail.members.grant_domain( 'q7Vd3kX9mT2pLw8RzN4bYc6HfJ1sGa5E', {'domainId': '7d2a9c41-5b3e-4f8a-9c06-1e2b3c4d5e6f', 'access': 'viewer'},) print([(grant['domain'], grant['access']) for grant in member['domains']])Notes
A domain id that is not on this workspace is 422 with code
member_not_foundandparamset todomainId. Somebody who is not in the workspace yet is refused the same way withparamset touserId.The workspace owner is refused with 422
member_is_owner, since they already reach every domain. A user id with no Nextmail account behind it is 404user_not_found.A workspace whose plan has no team access is refused with 403
plan_required. A key or an access token limited to particular addresses or domains is refused with 422capability_unsupported, and an access token acting for a member can only give a domain that member reaches, or it is refused with 403insufficient_authority. A grant that changes the access is written to the workspace security log asdomain-access-granted.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.is_step_up_requiredon the error says so. An API key is never asked for a code.Retried automatically on network failure, since replaying the same grant lands on the same row.
Also available in
members.revoke_domain()
Take a whole domain back from a member
def revoke_domain( user_id: str, domain_id: str, *, api_key: str | None = None, timeout: float | None = None,) -> MemberResourceRemoves one domain grant and leaves the person in the workspace with their role and their other grants. Addresses on that domain that were granted to them one by one stay granted.
A domain id that is not on this workspace is refused with 422 member_not_found rather than ignored, so a typo cannot report a revocation that never happened. A domain that is on the workspace but was never granted to this person is a silent no-op, and the member comes back unchanged.
The member is returned rather than a tombstone, because the useful answer is what they can still reach.
Parameters
user_idstrRequiredThe account id from
list, not the email address.domain_idstrRequiredId of a domain on this workspace.
api_keystrOverrides the client API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
MemberResource with the remaining domains.
Example
from nextmail import nextmail member = nextmail.members.revoke_domain( 'q7Vd3kX9mT2pLw8RzN4bYc6HfJ1sGa5E', '7d2a9c41-5b3e-4f8a-9c06-1e2b3c4d5e6f') print([grant['domain'] for grant in member['domains']])Notes
Somebody who is not a member of this workspace is a 404.
A key or an access token limited to particular addresses or domains is refused with 422
capability_unsupported, and an access token acting for a member can only take back a grant that member reaches at the same level, or it is refused with 403insufficient_authority. A revocation that removed a grant is written to the workspace security log asdomain-access-revoked.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.is_step_up_requiredon the error says so. An API key is never asked for a code.Not retried automatically by the SDK.
Also available in
members.list_invitations()
List the invitations nobody has accepted yet
def list_invitations( *, limit: int | None = None, cursor: str | None = None, api_key: str | None = None, timeout: float | None = None,) -> Page[InvitationResource]Returns one page of the invitations to this workspace that are still waiting, by email: the role and the addresses and whole domains each one grants once accepted, when it expires, and whether the last email reached them. list_all_invitations collects every page into one list and iterate_invitations walks them lazily.
A waiting invitation grants nothing. It becomes access only at the moment somebody accepts it, which is why it is listed apart from list. An expired one stays on the list with expired set to True until it is sent again or withdrawn.
Parameters
limitintPage size, from 1 to 100. The server defaults to 25.
cursorstrThe
nextCursorof the previous page. Leave it out for the first page.api_keystrOverrides the client API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
Page[InvitationResource], a dict with items, hasMore and nextCursor. Each item has id, email, role, addresses, domains, expiresAt, expired, lastSentAt, delivered, deliveryError and createdAt.
Example
from nextmail import nextmail page = nextmail.members.list_invitations()expired = [invitation['email'] for invitation in page['items'] if invitation['expired']] print('expired, send again or withdraw:', expired)Notes
deliveredisNonewhen no send outcome was recorded, andFalsewhen the email did not leave the mail server, with the reason indeliveryError.A key limited to particular addresses or domains lists only the invitations that grant nothing outside them.
Also available in
members.list_all_invitations()
Collect every waiting invitation into one list
def list_all_invitations( *, limit: int | None = None, cursor: str | None = None, api_key: str | None = None, timeout: float | None = None,) -> builtins.list[InvitationResource]Walks every page of list_invitations and returns every waiting invitation in one list, by email. One request per page.
Parameters
limitintPage size for each request, from 1 to 100. The server defaults to 25.
cursorstrStarts the walk after this cursor instead of the first page.
api_keystrOverrides the client API key for every page of this walk.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
list[InvitationResource] holding every waiting invitation.
Example
from nextmail import nextmail invitations = nextmail.members.list_all_invitations() for invitation in invitations: print(invitation['email'], invitation['role']['name'], invitation['expiresAt'])Notes
If any page fails, the call raises and the invitations already fetched are discarded.
Also available in
members.iterate_invitations()
Stream the waiting invitations one at a time
def iterate_invitations( *, limit: int | None = None, cursor: str | None = None, api_key: str | None = None, timeout: float | None = None,) -> Iterator[InvitationResource]Returns a generator that yields one invitation at a time, by email, and requests the next page only once the current one is used up. Nothing is fetched until the loop starts, and breaking out of it stops the requests.
Parameters
limitintPage size for each request, from 1 to 100. The server defaults to 25.
cursorstrStarts the walk after this cursor instead of the first page.
api_keystrOverrides the client API key for every page of this walk.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
Iterator[InvitationResource], a generator yielding one invitation per step.
Example
from nextmail import nextmail for invitation in nextmail.members.iterate_invitations(): if invitation['delivered'] is False: print(invitation['email'], invitation['deliveryError'])Notes
The generator is lazy, so an abandoned loop costs only the pages you consumed.
Also available in
members.revoke_invitation()
Withdraw an invitation
def revoke_invitation( invitation_id: str, *, api_key: str | None = None, timeout: float | None = None,) -> RevokedInvitationResourceWithdraws an invitation nobody has accepted. Its link stops working at once and nothing it would have granted is granted. It is Withdraw on the members screen. Inviting the same address later with add sends a new one.
Parameters
invitation_idstrRequiredThe invitation id from
list_invitations.api_keystrOverrides the client API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
RevokedInvitationResource with object set to invitation, the id and email, and revoked set to True.
Example
from nextmail import NextmailApiError, nextmail try: revoked = nextmail.members.revoke_invitation('winv_6bb640f5b99e47deb758f1f5')except NextmailApiError as error: if error.code != 'invitation_accepted': raise print('Already accepted. Remove the member instead.')else: print('Withdrew the invitation to', revoked['email'])Notes
An invitation that was accepted first answers 409
invitation_accepted: remove the member instead. One that is unknown or already withdrawn answers 404.A key limited to particular addresses or domains can withdraw only an invitation that grants nothing outside them.
Also available in
members.resend_invitation()
Send an invitation again
def resend_invitation( invitation_id: str, *, api_key: str | None = None, timeout: float | None = None,) -> InvitationResourceSends a waiting invitation again: a new link, fourteen more days, and the old link retired, so only the newest email works. It is Send again on the members screen, and it renews an expired invitation too.
Parameters
invitation_idstrRequiredThe invitation id from
list_invitations.api_keystrOverrides the client API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
InvitationResource with the new expiresAt and lastSentAt, and delivered for this send.
Example
from nextmail import nextmail invitation = nextmail.members.resend_invitation('winv_6bb640f5b99e47deb758f1f5') print(invitation['expiresAt'], invitation['delivered'])Notes
The same address cannot be sent to twice within ten minutes: that is 409
invitation_too_soon. The daily limit on invitations is 409invitation_limit_reached.The invitation's role cannot hold more than the key does, the rule
addapplies too: a role with a permission the key or access token lacks, any console-only one such asaddresses:allincluded, is 403insufficient_authority. An access token acting for a member is also refused with it when the invitation carries addresses or domains that member does not reach.The SDK does not retry it, because each call sends an email.
Also available in
members.get_directory_sync()
Read directory sync
def get_directory_sync( *, api_key: str | None = None, timeout: float | None = None,) -> DirectorySyncResourceReturns where directory sync (SCIM) stands, as the owner sees it on the Privacy tab: whether it is on, whether the plan includes it, the base URL to give the company directory, the last four characters of its token and when the directory last used it, how many people it synced and where each stands, and the groups it synced with the role each gives.
Directory sync lets a company directory, such as Okta or Microsoft Entra, add people to the workspace and take them out again. The directory calls the SCIM endpoints itself with the token connect_directory_sync returns.
Parameters
api_keystrOverrides the client API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
DirectorySyncResource, a dict with object set to directory_sync, connected, available, baseUrl, tokenLast4, tokenRotatedAt, lastSeenAt, connectedAt, defaultRoleId, users (total, members, invited, waiting and inactive) and groups, each with id, displayName, members and roleId.
Example
from nextmail import nextmail sync = nextmail.members.get_directory_sync() if sync['connected']: users = sync['users'] print( users['members'], 'of', users['total'], 'synced people joined, last seen', sync['lastSeenAt'], )Notes
Only the workspace owner, or a member whose role holds
workspace:manage, may read it: an access token acting for anybody else is refused with 403insufficient_authority. An API key acts for the owner.tokenLast4,tokenRotatedAtandconnectedAtareNonewhile directory sync is off, andlastSeenAtisNoneuntil the directory first calls with the token.
Also available in
members.connect_directory_sync()
Turn on directory sync
def connect_directory_sync( *, api_key: str | None = None, timeout: float | None = None,) -> DirectorySyncTokenResourceTurns directory sync on and returns the token the company directory sends as its bearer token, with status, where directory sync stands now. When it is already on, this makes a new token and the old one stops working at once.
The token is in this answer only and can never be read again, so store it in the directory straight away, with baseUrl in status as the SCIM base URL.
Directory sync comes with the Max and Enterprise plans: on any other plan the call is refused with 403 plan_required, and available on get_directory_sync says which applies.
Parameters
api_keystrOverrides the client API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
DirectorySyncTokenResource, a dict with object set to directory_sync_token, token, shown this once, and status, the DirectorySyncResource that get_directory_sync returns.
Example
from nextmail import nextmail connected = nextmail.members.connect_directory_sync()status = connected['status'] print('SCIM base URL', status['baseUrl'], 'token ending', status['tokenLast4'])print(connected['token'])Notes
Only the workspace owner, or a member whose role holds
workspace:manage, may turn it on: an access token acting for anybody else is refused with 403insufficient_authority. A key limited to particular addresses or domains is refused with 422capability_unsupported, because the people it changes reach beyond them.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.is_step_up_requiredon the error says so. An API key is never asked for a code.Not retried automatically, since every call replaces the token: a retry after a lost response would leave the directory holding a token that no longer works. The success status is 201.
Also available in
members.disconnect_directory_sync()
Turn off directory sync
def disconnect_directory_sync( *, api_key: str | None = None, timeout: float | None = None,) -> DirectorySyncDisconnectedResourceTurns directory sync off. Its token stops working at once and the people and groups it synced are forgotten, while everyone who already joined stays a member with the role they hold. Turning it off when it is off changes nothing, and disconnected is then False.
Parameters
api_keystrOverrides the client API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
DirectorySyncDisconnectedResource, a dict with object set to directory_sync and disconnected, True when directory sync was on and is off now.
Example
from nextmail import nextmail result = nextmail.members.disconnect_directory_sync() print('Directory sync is off' if result['disconnected'] else 'It was already off')Notes
Only the workspace owner, or a member whose role holds
workspace:manage, may turn it off: an access token acting for anybody else is refused with 403insufficient_authority. A key limited to particular addresses or domains is refused with 422capability_unsupported.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.is_step_up_requiredon the error says so. An API key is never asked for a code.Not retried automatically. A second call after a lost response answers
disconnectedset toFalseand changes nothing.
Also available in
members.list_directory_people()
List the people the directory synced
def list_directory_people( *, start_index: int | None = None, count: int | None = None, api_key: str | None = None, timeout: float | None = None,) -> DirectoryPersonListResourceReturns one page of the people the company directory synced into the workspace, in the order it sent them, with where each stands: member once they joined, invited while an invitation waits, waiting before one is sent, and inactive when the directory switched them off. DIRECTORY_PERSON_STATES holds the values.
Pages are counted from 1, as SCIM pages are: pass start_index= plus the number of people returned for the next page, while that is at most total.
Parameters
start_indexintWhere the page starts, counted from 1. Leave it out for the first page.
countintHow many people to return, from 1 to 100. Leave it out for 100.
api_keystrOverrides the client API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
DirectoryPersonListResource, a dict with object set to list, data, total, how many people the directory synced in all, and startIndex. Each person has id, userName, email, name, state, groups, the names of the groups they are in, and updatedAt.
Example
from nextmail import nextmail start_index = 1 while True: page = nextmail.members.list_directory_people(start_index=start_index, count=100) for person in page['data']: print(person['userName'], person['state'], person['groups']) start_index += len(page['data']) if not page['data'] or start_index > page['total']: breakNotes
Only the workspace owner, or a member whose role holds
workspace:manage, may read it: an access token acting for anybody else is refused with 403insufficient_authority. An API key acts for the owner.While directory sync is off, or before the directory synced anybody, the list is empty and
totalis 0.
Also available in
members.set_directory_default_role()
Choose the default role of directory sync
def set_directory_default_role( role_id: str | None, *, api_key: str | None = None, timeout: float | None = None,) -> DirectorySyncResourceChooses the role directory sync gives somebody that none of their groups gives a role, and returns where directory sync stands now. None goes back to the built-in Member role.
The owner role cannot be given out this way, which is 422 invalid_parameter on roleId, and a role that is not in the workspace is 422 role_not_found. Anybody but the owner can only give a role that holds nothing they lack themselves, or the call is refused with 403 insufficient_authority. While directory sync is off the call is 409 directory_sync_not_connected.
Parameters
role_idstr | NoneRequiredThe id of a role in this workspace, as
roles.listreturns it, orNonefor the built-in Member role.api_keystrOverrides the client API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
DirectorySyncResource with the new defaultRoleId.
Example
from nextmail import nextmail sync = nextmail.members.set_directory_default_role('role_2c7e9a1f4b8d3e60c5a7f1b9') print(sync['defaultRoleId'])Notes
Only the workspace owner, or a member whose role holds
workspace:manage, may change it: an access token acting for anybody else is refused with 403insufficient_authority. A key limited to particular addresses or domains is refused with 422capability_unsupported.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.is_step_up_requiredon the error says so. An API key is never asked for a code.Retried automatically on network failure, since it names the role it wants and a replay changes nothing.
Also available in
- API
PUT /directory-sync/default-role- TypeScript
members.setDirectoryDefaultRole()- Ruby
members.set_directory_default_role- PHP
members->setDirectoryDefaultRole- Go
Members.SetDirectoryDefaultRole- Java
members().setDirectoryDefaultRole- C#
Members.SetDirectoryDefaultRoleAsync- CLI
nextmail members set-directory-default-role
members.set_directory_group_role()
Choose the role of a directory group
def set_directory_group_role( group_id: str, role_id: str | None, *, api_key: str | None = None, timeout: float | None = None,) -> DirectorySyncResourceChooses the role a group the company directory synced gives its people, moves everyone in it to that role now, and returns where directory sync stands. None stops the group giving a role, so its people fall back to the default role set_directory_default_role chose.
The same rules about roles apply as for the default role: the owner role cannot be given out (422 invalid_parameter), a role that is not in the workspace is 422 role_not_found, and anybody but the owner can only give a role that holds nothing they lack themselves (403 insufficient_authority). A group that is not in the workspace is a 404, and while directory sync is off the call is 409 directory_sync_not_connected.
Parameters
group_idstrRequiredA group the directory synced, as
get_directory_synclists it ingroups.role_idstr | NoneRequiredThe id of a role in this workspace, as
roles.listreturns it, orNoneto give no role from this group.api_keystrOverrides the client API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
NextmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Returns
DirectorySyncResource with the new roleId on the group in groups.
Example
from nextmail import nextmail sync = nextmail.members.set_directory_group_role( '3b8f1d2e-7a4c-4e9b-a5d0-6c2f8e1b9a74', 'role_2c7e9a1f4b8d3e60c5a7f1b9') for group in sync['groups']: print(group['displayName'], group['roleId'])Notes
Only the workspace owner, or a member whose role holds
workspace:manage, may change it: an access token acting for anybody else is refused with 403insufficient_authority. A key limited to particular addresses or domains is refused with 422capability_unsupported.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.is_step_up_requiredon the error says so. An API key is never asked for a code.Retried automatically on network failure, since it names the role it wants and a replay changes nothing.
Also available in
- API
PUT /directory-sync/groups/{groupId}/role- TypeScript
members.setDirectoryGroupRole()- Ruby
members.set_directory_group_role- PHP
members->setDirectoryGroupRole- Go
Members.SetDirectoryGroupRole- Java
members().setDirectoryGroupRole- C#
Members.SetDirectoryGroupRoleAsync- CLI
nextmail members set-directory-group-role
