Entity Type - Data Schema


The Data Schema defines what attributes Entities in an Entity Type are expected to have.

Entities may go against the schema and define their own attributes, however this means they won't be managed by the system and therefor lack care for data types, validation, and search optimizations.

An attribute in the schema must have a key, name, and data type defined. Structure attributes will contain an array of child attribute definitions.

We have an experimental API request for analyzing data to generate a schema and mapping you can learn more about here.

Data model

Below is a basic data model for a Data Schema record.

When documentation refers to IDataSchema or just a Data Schema, you can reference this data model.

interface IDataSchema {
    Key: "root",
    Name: "Root",
    Structure: IAttribute[],
    Type: EAttributeType.Structure
}

export interface IAttribute {
    // The attribute JSON key.
    // It is recommended to avoid special characters and spaces (dash and underscore are fine).
    // It is also recommended to avoid these keys that have special internal meanings:
    // 'Bruce', 'ID', 'location', 'transform', 'geometry', 'boundaries', and 'position'.
    Key: string;
    // The attribute human readable name.
    Name?: string;
    // The attribute human readable description.
    Description?: string;

    // The attribute type.
    Type?: EAttributeType;
    // If this attribute is a structure, this is the structure definition.
    Structure?: IAttribute[];

    // If this attribute is 'pinned' or not.
    // This indicates it should be displayed in tables and lists.
    IsImportant?: boolean;

    // The historic key (if any) this attribute is associated with.
    // This is a date-time attribute that drives the change for this attribute value.
    // Attribute path segments are separated by a forward slash. Eg: 'address/city'.
    HistoricKey?: string;
}

export enum EAttributeType {
    // Standard types.

    // Arbitrary text attribute.
    String = "String",
    // Floating point number attribute.
    Double = "Double",
    // Whole number attribute.
    Integer = "Integer",
    // iso8601 date time string.
    Datetime = "Datetime",
    // Group of attributes.
    Structure = "Structure",
    // Nextspace vector geometry.
    Geometry = "Geometry",
    // True/false attribute.
    Boolean = "Boolean",

    // Special types that help guide behavior.
    // These typically link to existing concepts, or allow UI to present the value/input differently.

    // String User ID.
    User = "User",
    // String Group ID.
    UserGroup = "UserGroup",
    // String Entity ID.
    Entity = "Entity",
    // String URL attribute.
    Url = "Url"
}

Alternative schemas

Typically, you manage an Entity Type's Data Schema directly through the Entity Type record.

However, if you want manage an alternative Data Schema to transform the response data with then you can use the below endpoints.

If you include the query param schema={schema_id} then the result Entities in an Entity or DataLab request will be mapped to your alternative schema. Note that the mapping is performed after record retrieval, so you can't use this to filter records.

Get Alternative Schemas

Response
interface IResponse {
    Items: {
        // ID of this alternative schema.
        "Schema.ID": string;
        // ID of the related Entity Type.
        "EntityType.ID": string;
        // Human-readable name of this schema.
        "DisplayName": string;
        // Human-readable description of this schema.
        "Description": string;
    }[];
}
Javascript example

Get Alternative Schema By ID

Response
interface IResponse {
    // ID of this alternative schema.
    "Schema.ID": string;
    // ID of the related Entity Type.
    "EntityType.ID": string;
    // Human-readable name of this schema.
    "DisplayName": string;
    // Human-readable description of this schema.
    "Description": string;
    // Alternative data schema from the default Entity Type one.
    "DataSchema": IDataSchema;
    // Read more about this in the Data Mapping documentation.
    "DataMapping": IDataMapping;
}
Javascript example

Create / Update Alternative Schema

Response
interface IResponse {
    // ID of this alternative schema.
    // The ID something you provide yourself, unknown IDs will create a new schema record.
    // We typically generate a short alpha-numeric ID, but you could use an easy to remember string.
    "Schema.ID": string;
    // ID of the related Entity Type.
    "EntityType.ID": string;
    // Human-readable name of this schema.
    "DisplayName": string;
    // Human-readable description of this schema.
    "Description": string;
    // Alternative data schema from the default Entity Type one.
    "DataSchema": IDataSchema;
    // Read more about this in the Data Mapping documentation.
    "DataMapping": IDataMapping;
}

Delete Alternative Schema

Javascript example