Skip to content
Directory & LifecycleMarkdown

Get started with Directory & Lifecycle

Add your first user and your first group, put the user in the group, and read it back, in four calls.

API

In this page you add Maya to your realm, create an engineering group, and make her a member of it. From then on, everything you give the group, such as an entitlement, a policy or a shared vault, reaches her, and leaves her the moment she leaves the group.

  • A realm administrator’s account. You need an account in a group that holds the realm’s RealmOwner privilege. See Delegated administration.
  • A session for the API. Sign in as that administrator and keep the session in $CVYUH_SESSION, as Call the API describes. Every call below sends it as a cookie.
  • curl, or any HTTP client. The calls use your realm’s own host; replace foobar with your realm’s.
  1. Check your session. Ask the realm who you are:

    Terminal window
    curl -X POST https://foobar.cvyuh.com/api/v0/am/whoami/v1 \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"

    The answer names you, your roles in the realm and how long the session has left (session.expiresInSecs). A 401 means the session has ended: sign in again.

  2. Add Maya. Create a user, naming it maya with ?id=, with her sign-in name in uid and a first password:

    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": "<a first password>" }'

    The realm answers 201 with her record:

    {
    "id": "<internal id>",
    "objectId": "maya",
    "typeName": "user",
    "rev": <rev>,
    "attributes": { "uid": "maya", "displayName": "Maya Chen", "email": "maya@example.com",
    "firstName": "Maya", "lastName": "Chen", "status": "active" },
    "createTime": "<RFC 3339 time>",
    "updateTime": "<RFC 3339 time>"
    }

    The realm filled status with active, and stored only a hash of her password, which no read returns.

  3. Create the group.

    Terminal window
    curl "https://foobar.cvyuh.com/api/v0/am/objects/v1/group?id=engineering" \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "displayName": "Engineering", "description": "Everyone who builds the product" }'

    The realm answers 201 with the group.

  4. Put Maya in the group. Link her to the group’s member list, naming her by her id:

    Terminal window
    curl https://foobar.cvyuh.com/api/v0/am/objects/v1/group/engineering/relationships/member \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -H "If-Match: *" \
    -d '{ "targetId": "maya" }'

    The realm answers 201 with the link and the group’s new revision:

    { "_id": "engineering", "property": "member", "targetId": "maya", "rev": <rev> }

Read Maya with her groups expanded:

Terminal window
curl "https://foobar.cvyuh.com/api/v0/am/objects/v1/user/maya?expand=memberOf/*" \
-H "Cookie: x-cvyuh-token=$CVYUH_SESSION"

Her attributes.memberOf lists one link, to engineering:

"memberOf": [
{ "id": "<internal id>", "edgeId": "<internal id>", "properties": {},
"objectId": "engineering", "type": "group",
"object": { "displayName": "Engineering", "description": "Everyone who builds the product" } }
]

The link is stored once and read from both ends, so the group’s member list holds Maya as well. Maya can now sign in to the realm with maya and her password.