Skip to content
Directory & LifecycleMarkdown

Custom types

Define object types of your own, such as a department or a cost center, and link them to your users and groups.

AvailableAPIJSON Schema 2020-12

Some of what you keep isn’t an attribute of a user. A department has its own name, budget code and members; a cost center has its own owner; a project has its members. Define each as a type of your own, and its objects are stored, checked, searched, linked and audited exactly as users and groups are, through the same calls. A custom type belongs to your realm alone, and is ready to use the moment you define it.

  • Privilege: RealmOwner, or a privilege of your own over type definitions (*REALM/entity/type/*) and over the new type’s objects (*REALM/entity/department/*). See Who may do what.
  • Where: the API, with your session in $CVYUH_SESSION (see Call the API).

A type is a JSON Schema document with four parts that matter: its name; its category, which for a type of your own is managed; its cardinality, collection for a type that holds many objects or singleton for one; and its schema, the attributes and links its objects carry. Its policies hold the rules every write must pass, as for attributes: see Attributes and validation.

A link is an attribute marked with x-relationship: the type it points at, one or many, and the name of the attribute on the other end that points back. Declare both ends, and a link made from either end shows on both.

"members": { "type": "array",
"x-relationship": { "target": "user", "cardinality": "many", "reverse": "departments" } }
  1. Define the type. A department, with a budget code and its members:

    Terminal window
    curl https://foobar.cvyuh.com/api/v0/am/types/v1 \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{
    "name": "department", "category": "managed", "cardinality": "collection",
    "description": "A department, with its budget code and its members",
    "schema": { "type": "object", "properties": {
    "displayName": { "type": "string" },
    "budgetCode": { "type": "string" },
    "members": { "type": "array",
    "x-relationship": { "target": "user", "cardinality": "many", "reverse": "departments" } }
    } },
    "policies": { "displayName": ["required"], "budgetCode": ["unique"] }
    }'

    The realm answers 201.

  2. Add the other end, departments, to your realm’s user type, as Attributes and validation describes:

    "departments": { "type": "array",
    "x-relationship": { "target": "department", "cardinality": "many", "reverse": "members" } }
  3. Create a department, and add a member:

    Terminal window
    curl "https://foobar.cvyuh.com/api/v0/am/objects/v1/department?id=finance" \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "displayName": "Finance", "budgetCode": "FIN-100" }'
    curl https://foobar.cvyuh.com/api/v0/am/objects/v1/department/finance/relationships/members \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -H "If-Match: *" \
    -d '{ "targetId": "ben" }'

    Read Ben with ?expand=departments/*, and the Finance department is there.

WhatDefault or limit
categorymanaged for a type of your own
cardinalitycollection or singleton; fixed once the type exists
Types per realm, attributes per typeNo fixed cap
A definitionAbout 2 MB
Links per object read with expandAt most 10,000 per link attribute
The same pair linked twiceNot refused unless the link attribute is marked "unique": true; then 409
A one link already setA second is refused 409 (SINGLETON_EXISTS); remove the first
AnswerCodeWhat it meansWhat to do
400POLICY_VIOLATIONThe definition breaks a rule, such as a category other than managedUse managed
400INVALID_REQUESTThe definition is malformed, such as a link listed under requiredLinks can’t be required; check the definition
405METHOD_NOT_ALLOWEDA PATCH or DELETE on a typeSave the whole type with PUT

Defining a type is recorded as CREATED, and each save as UPDATED, with the definition before and after. Objects of the type are recorded like users and groups: see The identity model.

SymptomCauseFix
A link shows on one end onlyThe other end isn’t declared, or its reverse doesn’t name this attributeDeclare both ends, each naming the other in reverse
A user is linked to the same department twiceLinks aren’t unique unless markedRemove the extra link; mark the link attribute "unique": true, beside its x-relationship
  • Types are never deleted. A type you no longer need stays defined; a DELETE on it answers 405.
  • A type’s kind can’t change. category and cardinality are fixed once the type exists.
  • Members found by rule. A type of your own can work out a link from a rule on users’ attributes: see Rule-based membership.
  • Sign users in against your own type. See Your own user type.