Skip to main content

Creating Object Types

Now that your account is set up and you have an API key, you can start creating object types.

Object types allow you to model your application's resources by defining the relationships that exist between them and your users as a simple JSON schema. Object types can then be referenced in warrants (access rules) to define complex and powerful access control schemes that can be enforced in your application at runtime.

Creating an Object Type#

Here's an example of an object type for a store object in an e-commerce application:

{    "type": "store",    "relations": {        "owner": {},        "creator": {},        "editor": {            "type": "anyOf",            "rules": [                {                    "type": "userset",                    "relation": "owner"                }            ]        },        "viewer": {            "type": "anyOf",            "rules": [                {                    "type": "userset",                    "relation": "editor"                }            ]        }    }}

The json above defines an object type called store with the following direct and inherited relations:

  • A store can have an owner (direct)
  • A store can have a creator (direct)
  • A store can have an editor (direct)
  • An owner of a store is also an editor of that store (inherited)
  • A store can have a viewer (direct)
  • An editor of a store is also a viewer of that store (inherited)

Object types can be created directly in the dashboard or via a POST /v1/object-types request:

curl "" \    -X POST \    -H "Authorization: ApiKey YOUR_KEY" \    --data-raw \    '{        "type": "store",        "relations": {            "owner": {},            "creator": {},            "editor": {                "type": "anyOf",                "rules": [                    {                        "type": "userset",                        "relation": "owner"                    }                ]            },            "viewer": {                "type": "anyOf",                "rules": [                    {                        "type": "userset",                        "relation": "editor"                    }                ]            }        }    }'