Entity records


If you're using the web libraries then you don't have to implement your own request handing for Nextspace records. Below we'll cover some basics about how to get, update, and create Entity records.

The library supports a wide range of functions that may not be covered below. If a particular use-case is not covered, please contact us and we'll add it.

Getting records

If you've setup your environment by reading the getting started documentation then you should be good to go for communication with your Nextspace account.

Below is a few code examples on getting records.

Typescript
Javascript
import { Entity } from "bruce-models";

// Get by known Entity ID.
Entity.Get({
    entityId: "my-entity-id"
}).then((data) => {
    console.log("entity", data.entity);
}).catch((e) => {
    // Forbidden, not-found, etc...
    console.error("error", e);
})

// Get by known array of IDs.
Entity.GetListByIds({
    entityIds: ["my-entity-id-1", "my-entity-id-2"]
}).then((data) => {
    console.log("entities", data.entities);
}).catch((e) => {
    // Server error.
    console.error("error", e);
});

// Get by known entity-type ID.
Entity.GetList({
    filter: {
        entityTypeId: "my-entity-type-id",
        pageSize: 100,
        pageIndex: 0
    }
}).then((data) => {
    console.log("entities", data.entities);
}).catch((e) => {
    // Server error.
    console.error("error", e);
});

Update a record

If you'd like to update a record it is standard practice to get the latest data before shipping your changes.

We offer request parameters to only update attributes that you pass, but it's best to get the latest data and swap out the attributes you want changed when you want to save.

If you'd like re-render your Entity in the scene so the Style is refreshed, read through the Entity Interaction documentation.

Typescript
Javascript
import { Entity } from "bruce-models";

const myEntityData = {
    // Bruce is an old codeword for our API :)
    Bruce: {
        // ID and Entity Type ID are required when updating your record.
        // The Entity Type ID ensures we're working with the data-schema you expect.
        ID: "my-entity-id",
        "EntityType.ID": "my-entity-type-id"
    },
    "myAttribute": "my-value"
};

Entity.Update({
    entity: myEntityData,
    // If true, will override any existing data. If false, only supplied attributes will be updated.
    // Ensure your data-schema matches the data well otherwise sub-attributes will be overridden regardless!
    override: false
}).then((data) => {
    // The full record is returned back to you.
    console.log("entity", data.entity);
}).catch((e) => {
    // Forbidden, server error, etc...
    console.error("error", e);
});

Create a record

Creating a record is the same as updating except you don't need to supply an ID. The server will generate one for you.

Typescript
Javascript
import { Entity } from "bruce-models";

const myEntityData = {
    Bruce: {
        ID: null,
        // Entity Type ID is required when creating your record.
        // This will ensure we're working with the data-schema you expect.
        "EntityType.ID": "my-entity-type-id"
    },
    // Attributes are optional. Empty records are allowed.
    "myAttribute": "my-value",
    "myOtherAttribute": "my-other-value"
};

Entity.Update({
    entity: myEntityData
}).then((data) => {
    // The created record is returned back to you.
    console.log("entity", data.entity);
}).catch((e) => {
    // Forbidden, server error, etc...
    console.error("error", e);
});