DataLab queries


DataLab is a powerful API you can utilize to perform complex queries, and later actions against those queries.

Here we'll run through a few common queries you might want to perform.

Basic query / Entity Type criteria

Here is an example of the most basic query you can perform, this is a query for a page of Entities from a specific Entity Type.

DataLab query | Entity Type

Request body
interface IPostBody {
    // Definition of the criteria for the query.
    // Each item in the primary selection is an AND/OR condition.
    // An item can also represent a '()' group that contains sub-conditions to help portion the AND/OR conditions.
    "PrimarySelection": {
        "Items": [
            // Reduce response to a specific Entity Type.
            {
                "key": "EntityType",
                "EntityType": {
                    "EntityType.ID": string
                }
            }
        ]
    }
    // Pagination.
    "Skip"?: number;
    "Load"?: number;
}
Response
interface IResponse {
    // Array of Entities.
    "Items": any[];
    // Array of any encountered errors.
    // Typically, this is for external data sources that might have failed to be retrieved.
    "Error"?: string[];
}

Criteria: Attributes

Here is how you can add an attribute criteria to your query.

DataLab query | Entity Type + attribute

Request body
interface IPostBody {
    "PrimarySelection": {
        "Items": [
            // Reduce response to a specific Entity Type.
            {
                "key": "EntityType",
                "EntityType": {
                    "EntityType.ID": string
                },
                "LogicOperator": "AND"
            },
            // Reduce response to Entities that have a specific attribute.
            {
                "key": "Attribute",
                // This is a Nextspace path string.
                // Attribute path segments are separated by a forward slash. Eg: 'address/city'.
                "AttributePath": "my-attribute-path",
                // This is the value you want to search for.
                "OperandA": "search-value",
                // This is the operator you want to use.
                "Operator": "EQUALS",
                // You can use "AND NOT" if you want to exclude Entities that match this criteria.
                // Eg: You can use the Operator "NULL" with "AND NOT" to find Entities that have this attribute.
                "LogicOperator": "AND"

                // If you pass a string value into OperatorA, you can use these operators:
                // "EQUALS", "CONTAINS", "STARTS WITH", and "ENDS WITH".
                // If you pass an array to 'OperandA', then you can use the "IN" operator to perform a search against the array of values.

                // If you pass a numeric value into OperatorA, you can use these operators:
                // "=", ">", "<", ">=", "<=", and "IN" (for an array of values).

                // If you pass a date value into OperatorA, you can use these operators:
                // "=", ">", "<", ">=", and "<=".

                // If you want to use a "Between" operator for numeric or date values, you have to specify both a OperandA and OperandB value.

                // All Operators support the "NULL" operator as well. This value is needed.
                // This will check if the attribute both exists and is not an empty string.
                // For dates, this will ensure the value parses into a valid date (means it's not in ISO 8601 format).
            }
        ]
    }
    "Skip"?: number;
    "Load"?: number;
}

Criteria: Tags

DataLab query | Entity Type + Tags

Request body
interface IPostBody {
    "PrimarySelection": {
        "Items": [
            // Reduce response to a specific Entity Type.
            {
                "key": "EntityType",
                "EntityType": {
                    "EntityType.ID": string
                },
                "LogicOperator": "AND"
            },
            // Reduce response to Entities that have specific Tags.
            {
                // Layer is the original keyword for Tag.
                "key": "Layer",
                "Layers": {
                    // Array of Tag IDs.
                    "Layer.ID": [
                        1, 2, 3
                    ],
                    // Operator 'all' means that the Entity must have all of the Tags.
                    // Operator 'either' means that the Entity must have at least one of the Tags.
                    // Operator 'neither' means that the Entity must not have any of the Tags.
                    // Operator 'none' means that the Entity must not have any Tags. You don't need to pass an array of Tag IDs for this Operator.
                    "Operator": "all"
                },
                "LogicOperator": "AND"
            }
        ]
    }
    "Skip"?: number;
    "Load"?: number;
}

Criteria: User

DataLab query | Entity Type + User

Request body
interface IPostBody {
    "PrimarySelection": {
        "Items": [
            // Reduce response to a specific Entity Type.
            {
                "key": "EntityType",
                "EntityType": {
                    "EntityType.ID": string
                },
                "LogicOperator": "AND"
            },
            // Reduce response to Entities created by a specific User.
            {
                "key": "CreatedBy",
                "CreatedBy": {
                    "User.ID": "some-user-id"
                },
                "LogicOperator": "AND"
            }
        ]
    }
    "Skip"?: number;
    "Load"?: number;
}

Criteria: LOD

As assemblies can include Entities that act as groups without a visual representation, this is commonly used to narrow down an assembly's Entities into just those that can be seen.

DataLab query | Entity Type + LOD

Request body
interface IPostBody {
    "PrimarySelection": {
        "Items": [
            // Reduce response to a specific Entity Type.
            {
                "key": "EntityType",
                "EntityType": {
                    "EntityType.ID": string
                },
                "LogicOperator": "AND"
            },
            // Reduce response to Entities to those that have a LOD (level of detail).
            {
                "key": "LOD",
                "LOD": {
                    // Commonly "GLB".
                    "Type": "some-lod-category-id",
                    // You can use "have-not" to find those without any LODs of the specified type.
                    "LogicOperator": "have"
                },
                "LogicOperator": "AND"
            }
        ]
    }
    "Skip"?: number;
    "Load"?: number;
}

Criteria: Assembly

This is a criteria for finding Entities that are part of a specific assembly. You specify the root Entity ID and all Entities (including the root) are included.

WARNING: You cannot perform 'OR' logic operators with this criteria at this time.

DataLab query | Assembly

Request body
interface IPostBody {
    "PrimarySelection": {
        "Items": [
            {
                "key": "Root",
                // It is recommended to keep this at 'true' as it will ignore UCS Entities.
                // A UCS is an Entity that is used to share coordinates between multiple assemblies, which means it is not part of the assembly itself.
                "IgnoreUCSRoots": true,
                // You can choose to exclude assemblies that have Tilesets.
                // This is a useful option to find assemblies that don't have a Tileset yet, which often means they aren't being used.
                "IgnoreWithTilesets": false,
                "LogicOperator": "AND"
            }
        ]
    }
    "Skip"?: number;
    "Load"?: number;
}

Criteria: List assemblies

This is a criteria for finding assembly root Entities. These Entities' IDs are typically used to generate Tilesets (optimized graphics for rendering), and to search against hierarchies generated from a file import (IFC/RVT/etc).

DataLab query | Assembly

Request body
interface IPostBody {
    "PrimarySelection": {
        "Items": [
            {
                "key": "AssemblyRoot",
                "RootID": "some-root-entity-id",
                "LogicOperator": "AND"
            }
        ]
    }
    "Skip"?: number;
    "Load"?: number;
}

Criteria: Reference to another DataLab query

You can perform an IN search against an attribute in another query.

For example, "Find all Work Order Entities that have a 'status' value in my "Valid Work Order status" query".

DataLab query | Assembly

Request body
interface IPostBody {
    "PrimarySelection": {
        "Items": [
            {
                "key": "attribute-join",
                "AttributeJoin": {
                    // Attribute within this query to perform the IN against.
                    // Attribute path segments are separated by a forward slash. Eg: 'address/city'.
                    "InputAttributePath": string;

                    // A saved DataLab query to reference by ID.
                    "DataLabQueryID": number;
                    // Attribute within the referenced query to gather valid values from.
                    // Attribute path segments are separated by a forward slash. Eg: 'address/city'.
                    "TargetAttributePath": string;
                },
                "LogicOperator": "AND"
            }
        ]
    }
    "Skip"?: number;
    "Load"?: number;
}

Criteria: '()' groups

Below is an example of how you can use '()' groups to help portion your criteria.

DataLab query | '()' groups

Request body
interface IPostBody {
    "PrimarySelection": {
        "Items": [
            // Reduce response to a specific Entity Type.
            {
                "key": "EntityType",
                "EntityType": {
                    "EntityType.ID": string
                },
                "LogicOperator": "AND"
            },
            // A criteria for finding Entities that include 'A' or 'B' in a specific attribute.
            {
                "key": "SubQuery",
                "LogicOperator": "AND",
                "Subquery": {
                    "Items": [
                        {
                            "key": "Attribute",
                            // Attribute path segments are separated by a forward slash. Eg: 'address/city'.
                            "AttributePath": "my-attribute-path",
                            "OperandA": "A",
                            "Operator": "CONTAINS",
                            "LogicOperator": "OR"
                        },
                        {
                            "key": "Attribute",
                            // Attribute path segments are separated by a forward slash. Eg: 'address/city'.
                            "AttributePath": "my-attribute-path",
                            "OperandA": "B",
                            "Operator": "CONTAINS"
                        }
                    ]
                }
            }
        ]
    }
    "Skip"?: number;
    "Load"?: number;
}