Skip to content
Directory & LifecycleMarkdown

Add and change users

Create the users of your realm, read them back, change only the attributes that changed, and delete them when you're done.

AvailableAPIRFC 7396, RFC 6902, RFC 9110

Every user in your realm is written through one API: create them with a profile and a first password, read them back, change any attribute without resending the rest, and delete them. Every write is checked against the user type’s rules, and a revision on every record stops two administrators from overwriting each other.

  • Privilege: RealmViewer to read users; RealmOwner, or a privilege of your own over users, to create, change and delete them. See Who may do what.
  • Where: the API, with your session in $CVYUH_SESSION (see Call the API).
  • Your own attributes first. To keep an attribute the shipped user doesn’t have, such as employeeId, add it to your user type before you write it, so it’s checked and searchable: see Attributes and validation.

Every user is an object of the user type. Its id is the name you give it when you create it, such as maya, and the realm uses it in every address for that user. Its uid is the name the user signs in with. Use the same value for both, so the address and the sign-in name never disagree.

AttributeWhat it holds
uidThe sign-in name. Required, and unique in the realm
displayName, firstName, lastNameHow the user is named
email, telephoneNumberHow to reach them. email can be looked up directly, like uid
locale, timeZone, languageTheir preferences, for apps to read
statusactive or inactive. Filled active when you leave it out
accountExpiryWhen their access ends, as an RFC 3339 time
passwordHashTheir password. You write it; no read ever returns it
memberOfTheir groups. See Add groups and members

Other parts of the realm add attributes of their own to the same user: the entitlements they hold in grants (see Entitlements), their riskClass, their second factors in devices, the agents they own in ownedAgents, and per-user session limits (maxSessionMinutes, maxIdleMinutes, sessionQuota). You can add your own as well: see Attributes and validation.

Passwords are hashed before they are stored. Write the password as given in passwordHash; the realm stores a bcrypt hash of it. A value that is already a bcrypt hash is stored as it is, which is how users brought from another system keep their passwords (see Bring users in).

Every write is checked. A write that breaks a rule of the type, such as a missing or duplicate uid, is refused with 400 and a list of every failure at once, so you fix them in one pass.

  1. Create the user, naming it with id:

    Terminal window
    curl "https://foobar.cvyuh.com/api/v0/am/objects/v1/user?id=maya" \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "uid": "maya", "firstName": "Maya", "lastName": "Chen", "displayName": "Maya Chen",
    "email": "maya@example.com", "passwordHash": "<her first password>" }'

    The realm answers 201 with the user: its objectId, its attributes (without the password), and its revision, rev, also sent as the ETag header.

  2. Read it back. Add ?expand=memberOf/* to see the user’s groups too:

    Terminal window
    curl "https://foobar.cvyuh.com/api/v0/am/objects/v1/user/maya?expand=memberOf/*" \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
  3. Change only what changed, naming the revision you read:

    Terminal window
    curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/user/maya \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -H 'If-Match: "<rev>"' \
    -d '{ "telephoneNumber": "+44 20 7946 0000", "locale": "en-GB" }'

    A JSON object is a merge patch (RFC 7396): the fields you send are set, a field sent as null is removed, and the rest are left alone. A JSON array is a list of JSON Patch (RFC 6902) operations.

  4. To delete the user, send DELETE to the same address with If-Match:

    Terminal window
    curl -X DELETE https://foobar.cvyuh.com/api/v0/am/objects/v1/user/maya \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H 'If-Match: "<rev>"'

    The realm answers { "status": "deleted" }.

WhatDefault or limit
uidRequired, and unique in the realm ignoring case: Maya and maya are the same sign-in name
emailUnique in the realm ignoring case, when set
statusactive when left out
idThe ?id= you give, or one the realm makes; can’t change
A request bodyAbout 2 MB; a larger one is refused 400
Password rulesThe realm’s password policy, checked on every write of passwordHash: see Password rules
AnswerCodeWhat it meansWhat to do
400POLICY_VIOLATIONA rule of the type failed, such as a duplicate uid or a password too weak; detail lists every failureFix each one named and send again
400SCHEMA_VALIDATION_FAILEDA value has the wrong kind or isn’t one of its allowed values, such as a status other than active or inactiveCheck the type with GET /types/v1/user
403FORBIDDENYour privileges don’t cover this user or this changeAsk an administrator holding RealmOwner
404NOT_FOUNDNo user with that idCheck the id; ids are the objectId, not uid
409ALREADY_EXISTSThe id you gave is takenPick another id, or PATCH the user that’s there
412REVISION_CONFLICTThe user changed since you read itRead it again, and reapply your change

Every write is on the audit trail and in the user’s change history: CREATED for a create, PATCHED for a PATCH, UPDATED for a PUT or a change to their links, DELETED for a delete, each with who made it and the values before and after. The password and every other value no read returns are left out.

SymptomCauseFix
A new user can’t sign inTheir status is inactive, their accountExpiry has passed, or they have no passwordHashRead the user and check all three; see Turn access off and on
A change you made is goneSomeone else wrote after you without If-Match, or a PUT replaced the attributesSend If-Match with the revision you read; use PATCH for partial changes
An attribute you wrote can’t be searched (400, unknown filter field)It isn’t on your user type: an attribute the type doesn’t define is stored as sent, but it isn’t checked or searchableAdd it to the type (Attributes and validation), and check its spelling
  • If-Match stops lost updates. With it, a write made after someone else’s change is refused 412, and you read the user again before retrying. If-Match: * writes whatever the revision. Without the header, a PATCH writes over any change made since you read.
  • A replace is whole. PUT on the user’s address replaces every attribute you can see with the body. Use PATCH unless you mean to clear what you leave out. Values no read returns, such as the password, are kept.
  • Creating with an id that’s taken is refused. Leave out ?id= and the realm makes an id for you, but you’ll want ids you can read.
  • An attribute the type doesn’t define is stored as sent. It isn’t refused, so a misspelled attribute name is kept beside the right one, unchecked and not searchable. Define every attribute you write on the type.
  • The id can’t change. To change a sign-in name, change uid; the id in the address stays as it was.
  • Deleting is final. It removes the user and every link to them: their group memberships, the grants made to them, and their personal vault (see Deleting an owner). To take access away and keep the record, set them inactive instead: see Turn access off and on.
  • Deleting a user leaves their agents without an owner. Each agent’s businessOwner link goes with the user, and nothing requires an agent to have one. Before you delete a user, list their agents with ?expand=ownedAgents/* and hand each to a new owner: see Agent records.