Before you begin
You need:- An access token. See the quickstart.
- A service account whose role allows the user actions you call: list, get, create, invite, update, delete, assign app, update KODE OS role, and unassign app. Each operation needs its own action.
- For app access, the
buildingIdof each building the user can open. See List buildings.
userId from another organization returns 404.
How users and app access fit together
A new user has no app access. The organization role and the KODE OS role are separate, and each has its own operation to change it.
List users
Call List users. Each item indata is a user, with the apps the user can access in assignedInApps.
Users come back by
_id, highest first. Use asc or dsc to sort by another field, such as email. Stop requesting pages when page equals pageCount. See pagination.
Keep the _id of the user you want. Every other operation takes it as userId.
Create or invite a user
Choose the operation by where the person belongs.Create a user
200 and holds the new user, with its _id.
Keep these rules in mind:
- The email address must be unique in your organization, in any letter case. KODE stores it in lower case. A duplicate returns
400. firstNameandlastNamecan have up to 40 characters, andpositionup to 200.phonemust be an international number that starts with+.- Values that contain HTML tags are stored HTML-escaped.
Invite a guest
200 and holds the guest, with memberType set to GUEST, active set to true, and invitationStatus set to PENDING. The guest has no name. If trustedOrganizationId does not match an organization, or the email already belongs to a user, the request fails with 400.
Give app access to a user
App access is asynchronous. You send the assignment, KODE finishes it in the background, and you read the user to see the result. Only thebms app can be assigned through the API.
1
Assign the app
Call Assign an app to a user with The response is
bms as the appId. Send the KODE OS role in role. Use a role of your organization’s bms app, for example ViewOnly. To limit access to some buildings, send their IDs in buildingIds.202 with no body. That means KODE accepted the request, not that access is ready. A user who already has the app gets 400.2
Wait until the assignment finishes
Call Get a user until the Read
bms entry in assignedInApps reaches a final status.assignedInApps[].assignmentStatus:Poll every few seconds and stop on
SUCCEEDED or FAILED.The buildings you send in
buildingIds are not returned by the API. assignedInApps lists the app, the role, and the status only.Change a role
A user has two roles. Use the operation that matches the one you want to change.Update a user
firstName, lastName, phone, position, and the organization role. You cannot change email. To change active, update the status of the user. Setting role to CLIENT_ADMIN returns 403.
Update the KODE OS role
The user must already have the app, and the assignment must be finished. Wait forSUCCEEDED or FAILED first.
204 with no body. This changes the role in the app only, not the organization role. If the user does not have the app, the request fails with 400 and the message “App not found”.
Remove app access
Call Remove app access from a user. The user stays in your organization.204 with no body. Read the user to confirm that the bms entry is gone from assignedInApps. If the user does not have the app, the request fails with 400 and the message “App not found”. You can remove access that is still PENDING.
Activate or deactivate a user
Call Update the status of a user withactive set to true or false. The user stays in your organization.
200 and holds the updated user. If the user already has the status you sent, the request fails with 400 and the message “Invalid status update”. To take away app access and keep the account enabled, remove the app access as in the previous section.
Delete a user
To remove the user, call Delete a user.204 with no body. Read the user afterwards to confirm: it returns 404. A second delete of the same user also returns 404. No email is sent. If you later create a user with the same email address, the new user gets the same _id.
Handle errors
Error responses hold anerror object with a code, a message, and, for field checks, fields.
After a timeout or a
5xx on a create or invite, search the list with q before you send the request again, because the user can already exist. See retry failed requests.

