Most methods assume the current user is authenticated. If not, a 401 Unauthorized error will be returned.
Setting the Current Tenant
You can manually set the current tenant usingawait nile.withContext({ tenantId }). withContext returns a copy of the nile instance with a context that captures what was passed. It also accepts a second parameter for convenience for multiple requests.
Returns a nile with the context
Self contained callback
Framework-specific integrations may set context automatically, so calling
withContext every time may not be necessary in those environments. see extensions for more information- The result of
create() - A specific tenant via
get() - A selected tenant from
list()
create
Create a new tenant usingPOST /api/tenants. The current user is automatically linked to the new tenant.
Parameters
name: Name of the tenant (required)id: Optional. Unique ID to use instead of auto-generating
Returns
If successful, resolves to aTenant object:
Response with 401 or 400 on failure.
get
Fetch a specific tenant or the current tenant usingGET /api/tenants/{id}.
Parameters
id: Optional. If omitted, uses the current context
Returns
ATenant object or a raw Response.
update
Update the name of the current tenant viaPUT /api/tenants/{id}.
Parameters
name: New name of the tenantid: Optional. If omitted, uses context
Returns
UpdatedTenant object or a Response.
Only the name is currently updatable.
delete
Mark a tenant as deleted usingDELETE /api/tenants/{id}. This is a soft delete.
Returns
AResponse with status 204 on success.
list
List all tenants the current user belongs to viaGET /api/tenants/by-user.
Returns
Array ofTenant objects:
users
List users who are members of a given tenant (or the current one).Returns
Array ofUser objects, or a Response on error.
addMember
Add a user to the current tenant using their user ID.Returns
The addedUser object or a Response.
removeMember
Remove a user from the tenant.Returns
AResponse.
leaveTenant
Removes the current user from a tenant they belong to.Returns
AResponse.
invites
Fetch all invites for the current tenant:Returns
An array ofInvite objects.
invite
Invite a new user by email to the current tenant. thecallbackUrl is the value that is used to return the user to a page that renders HTML. There is a primary endpoint that is used to exchange the token in the email to join the tenant. Upon a successful exchange, the user will be redirected to the callbackUrl
Parameters
email: Email of the user to invitecallbackUrl: Optional URL to redirect after acceptanceredirectUrl: Optional URL used as the base in the email
Returns
AnInvite object or a Response.
acceptInvite
Accept an invite using an emailed token and email address.Returns
AResponse indicating success or failure.
deleteInvite
Delete a previously sent invite.Returns
AResponse.