Skip to content
Directory & LifecycleMarkdown

Attributes and validation

Add the attributes your organization keeps about users and groups, with the rules every write must pass.

AvailableAPIJSON Schema 2020-12

Add an employee number, a department or a start date to your realm’s user and group types, and they behave like the shipped attributes: stored, searched, checked on every write, and shown in every read. Give each the rules it must pass, and the realm refuses a bad value with every failure named at once.

  • Privilege: RealmOwner, or a privilege of your own over type definitions (*REALM/entity/type/* with MODIFY). Reading a type needs RealmViewer. See Who may do what.
  • Where: the API, with your session in $CVYUH_SESSION (see Call the API).

Each realm has its own user, group and agent types, made from the shipped definitions when the realm was created. You change your realm’s copy by saving its definition again with what you’ve added.

The shipped attributes are marked "x-carried": true. Sign-in, tokens, the secrets store and the rest of the realm rely on them, so you may change only their default and description. Everything else about them stays: you can’t remove one, change its kind, or drop its required entry or its rules. A save that tries is refused 400 (POLICY_VIOLATION), naming the attribute. Everything you add beside them is yours to change or remove.

Each attribute can carry policies, checks run on every create and every change. A write that fails any of them is refused 400 with every failure listed, each naming the attribute, the policy and what was wrong.

PolicyWhat it checks
required, not-null, not-emptyThe attribute is there, and not blank
uniqueNo other object of the type has the same value
min-length, max-lengthLength, with value as the limit
regex-matchThe value matches pattern
valid-email, valid-phone, valid-name, valid-dateThe value is shaped like one
valid-typeThe value’s JSON type is one of types
no-duplicatesA list holds no value twice
at-least-capitals, at-least-numbers, cannot-contain-characters, cannot-contain-value, cannot-contain-othersPassword strength, for a password attribute: see Password rules

The schema’s own keywords are checked too: required, minLength, pattern, enum, and the attribute’s type. format is not checked: a schema’s "format": "date-time" or "format": "email" describes the value but doesn’t refuse a malformed one. To enforce a shape, use a policy: valid-date, valid-email, valid-phone or regex-match.

  1. Read your realm’s type:

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

    The answer is the whole definition, name, category, cardinality, schema and policies, with its rev.

  2. Add your attributes under schema.properties, and any rules for them under policies, keeping everything that was there:

    "employeeId": { "type": "string", "x-searchable": true },
    "department": { "type": "string" },
    "startDate": { "type": "string", "format": "date" }
    "policies": { "uid": ["unique", "required"],
    "employeeId": ["unique", { "id": "regex-match", "pattern": "^E[0-9]{6}$" }],
    "startDate": ["valid-date"] }
  3. Save the whole definition back, naming the revision you read:

    Terminal window
    curl -X PUT https://foobar.cvyuh.com/api/v0/am/types/v1/user \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -H 'If-Match: "<rev>"' \
    -d @user-type.json

    user-type.json is the definition you read, with your additions. The realm answers with the saved type and its new rev. Without If-Match it answers 428; if the type changed since you read it, 412.

  4. Write the new attributes like any other:

    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" \
    -d '{ "employeeId": "E004211", "department": "Engineering" }'
WhatDefault or limit
Attributes per typeNo fixed cap
Length of a valueNo cap unless you set one: add max-length to every free-text attribute you add
A type’s definition, or any request bodyAbout 2 MB
Carried attributesOnly default and description can change
valid-dateAn RFC 3339 time, a date (2027-03-31), or a date and time without an offset
AnswerCodeWhat it meansWhat to do
400POLICY_VIOLATIONA save removed or changed a carried attribute, or a write broke a policy; each failure is namedRestore the carried attribute; fix the value
400SCHEMA_VALIDATION_FAILEDA value’s kind, pattern, enum or minLength failedFix the value
400INVALID_REQUESTThe definition is malformed, such as a mark on the wrong kind of attributeCheck the attribute’s definition
412REVISION_CONFLICTThe type changed since you read itRead it again, reapply your additions
428PRECONDITION_REQUIREDThe save had no If-MatchSend the rev you read

Each save of a type is recorded as UPDATED, with the definition before and after and who saved it; a new type as CREATED. Writes of the attributes themselves are recorded on each object’s change history. See What is recorded.

SymptomCauseFix
A malformed date or email was storedformat describes, it doesn’t checkAdd valid-date or valid-email to the attribute’s policies
An attribute you added earlier is goneA PUT without it replaced the typeAdd it back; always start from a fresh read
Stored objects break a new ruleRules apply from the next writeRead them with a search and fix them, or let each next write catch them
A new shipped attribute isn’t on your realm’s typeYour realm’s types are copies made when it was createdAdd it yourself; see What’s next for attributes
  • The body replaces the type. A PUT that leaves out an attribute you added earlier removes it from the type. Always start from a fresh read.
  • Types are never deleted. A DELETE on a type always answers 405.
  • A type’s kind can’t change. A change of category or cardinality is refused, since it would change what the objects already stored mean.
  • x-searchable: true indexes an attribute. Every attribute can be filtered; mark the ones you search often.
  • Your realm’s types are its own copies. An improvement to the shipped user, group or agent doesn’t reach a realm that already exists: see What’s next for attributes.
  • New rules apply from the next write. Objects already stored aren’t checked again until they’re next changed, and then the whole object must pass.