Instances

Create or update nodes/edges

Required capabilities: dataModelsAcl:WRITE

Create or update nodes and edges in a transaction. The items field of the payload is an array of objects where each object describes a node or an edge to create, patch or replace. The instanceType field of each object must be node or edge and determines how the rest of the object is interpreted.

This operation is currently limited to 1000 nodes and/or edges at a time.

Individual nodes and edges are uniquely identified by their externalId and space.

Instances will be returned in the same order as they are supplied in the request.

For more details on ingesting instances into a graph, see [Ingesting instances] (https://docs.cognite.com/cdf/dm/dm_concepts/dm_ingestion).

Creating new instances

When there is no node or edge with the given externalId in the given space, a node will be created and the properties provided for each of the containers or views in the sources array will be populated for the node/edge. Nodes can also be created implicitly when an edge between them is created (if autoCreateStartNodes and/or autoCreateEndNodes is set), or when a direct relation property is set, the target node does not exist and autoCreateDirectRelations is set.

To add a node or edge, the user must have capabilities to access (write to) both the view(s) referenced in sources and the container(s) underlying these views, as well as any directly referenced containers.

Updating (patching) or replacing instances

When a node or edge (instance) with the given externalId already exists in a space, the properties named in the sources field will be written to the instance. Other properties will remain unchanged. To replace the whole set of properties for an instance (a node or an edge) rather than patch the instance, set the replace parameter to true.

Note: When using replace as true it will replace any omitted property to either it's default value as defined on the container(s) or null if no default value is set. All properties on the related container(s) referenced in the provided sources view(s) will be replaced, so even when the provided view(s) only contains a subset of properties from a container all the properties in that container for that instance will be replaced. If the underlying container(s) have any required properties that are not provided, the operation will fail.

If you use a writable view to update properties (that is, the source you are referring to in sources is a view), you must have write access to the view as well as all of its backing containers.

No-change patch operations

When a node/edge item has no changes compared to the existing instance - that is, when the supplied property values are equal to the corresponding values in the existing node/edge, the node/edge will stay unchanged. In this case, the lastUpdatedTime values for the nodes/edges in question will not change.

Deleting instances

It's also possible to delete instances by passing instance references to the delete field. Upserts and deletes can be combined in the same request and will be executed atomically. The total number of ingested and deleted items cannot exceed 1000. If an instance doesn’t exist, the delete operation skips it and it won't be included in the response.

Securityoidc-token or oauth2-client-credentials or oauth2-open-industrial-data or oauth2-auth-code
Request
Request Body schema: application/json
required

Nodes/edges to add or update.

required
Array of NodeWrite (object) or EdgeWrite (object) (NodeOrEdgeCreate) [ 0 .. 1000 ] items

List of nodes and edges to create/update

Array of objects (InstanceDelete) [ 0 .. 1000 ] items

List of nodes and edges to delete

autoCreateDirectRelations
boolean
Default: true

Should we create missing target nodes of direct relations? If the target-container constraint has been specified for a direct relation, the target node cannot be auto-created. If you want to point direct relations to a space where you have only read access, this option must be set to false.

autoCreateStartNodes
boolean
Default: false

Should we create missing start nodes for edges when ingesting? By default, the start node of an edge must exist before we can ingest the edge.

autoCreateEndNodes
boolean
Default: false

Should we create missing end nodes for edges when ingesting? By default, the end node of an edge must exist before we can ingest the edge.

skipOnVersionConflict
boolean
Default: false

If existingVersion is specified on any of the nodes/edges in the input, the default behaviour is that the entire ingestion will fail when version conflicts occur. If skipOnVersionConflict is set to true, items with version conflicts will be skipped instead. If no version is specified for nodes/edges, it will do the write directly.

replace
boolean
Default: false

How do we behave when a property value exists? Do we replace all matching and existing values with the supplied values (true)? Or should we merge in new values for properties together with the existing values (false)? Note: This setting applies for all nodes or edges specified in the ingestion call.

Responses
200

Created, deleted, and updated instances

400

The response for a failed request.

409

Ingestion conflict

post/models/instances
Request samples
application/json
{
  • "items": [
    ],
  • "delete": [
    ],
  • "autoCreateDirectRelations": true,
  • "autoCreateStartNodes": false,
  • "autoCreateEndNodes": false,
  • "skipOnVersionConflict": false,
  • "replace": false
}
Response samples
application/json
{
  • "items": [
    ],
  • "deleted": [
    ]
}

Filter nodes/edges

Required capabilities: dataModelsAcl:READ

Filter the instances - nodes and edges - in a project.

Securityoidc-token or oauth2-client-credentials or oauth2-open-industrial-data or oauth2-auth-code
Request
Request Body schema: application/json
required

Filter based on the instance type, the name, the external-ids, and on properties. The filter supports sorting and pagination. The instances must have data in all the views referenced by the sources field. Properties for up to 10 views can be retrieved in one query.

includeTyping
boolean (IncludeTyping)

Should we return property type information as part of the result?

Array of objects (SourceSelectorWithoutPropertiesV3) <= 10 items

Retrieve properties from the listed - by reference - views. The node/edge must have data in all the sources defined in the list.

instanceType
string
Default: "node"

The type of instance you are querying for; an edge or a node. If the instance type isn't specified, we list nodes. When instanceType is edge, property can refer to any container and is defined as ["edge", "type"], and value contains the value of the property.

Example:

{
    “includeTyping”: true,
    “instanceType”: "edge",
    “filter”: {
                “equals”: {
                    "property": [
                      "edge",
                      "type" // VALID VALUES:[space, externalId, createdTime, lastUpdatedTime, startNode, endNode, type ]
                    ],
                    "value": {
                    "space": "apm_simple",
                    "externalId": "WMT:23-FO-96187"
                    }
                  }
              }
}
Enum: "node" "edge"
object (DebugParameters)

Return query debug notices.

cursor
string
limit
integer [ 1 .. 1000 ]
Default: 1000

Limits the number of results to return.

Array of objects (PropertySortV3) <= 5 items
(BoolFilter (and (object) or or (object) or not (object))) or (LeafFilter (equals (object) or in (object) or range (object) or prefix (object) or exists (object) or containsAny (object) or containsAll (object) or matchAll (object) or nested (object) or overlaps (object) or hasData (object) or instanceReferences (object))) (FilterDefinition)
Responses
200

List of matching nodes and edges

400

The response for a failed request.

post/models/instances/list
Request samples
application/json
{
  • "includeTyping": false,
  • "sources": [
    ],
  • "instanceType": "node",
  • "debug": {
    },
  • "cursor": "4zj0Vy2fo0NtNMb229mI9r1V3YG5NBL752kQz1cKtwo",
  • "limit": 1000,
  • "sort": [
    ],
  • "filter": {
    }
}
Response samples
application/json
{
  • "items": [
    ],
  • "typing": {
    },
  • "nextCursor": "string",
  • "cursorCaughtUp": true
}

Retrieve nodes/edges by their external ids

Required capabilities: dataModelsAcl:READ

Retrieve up to 1000 nodes or edges by their external ids.

Securityoidc-token or oauth2-client-credentials or oauth2-open-industrial-data or oauth2-auth-code
Request
Request Body schema: application/json
required

List of external-ids for nodes or edges to retrieve. Properties for up to 10 unique views (in total across the external ids requested) can be retrieved in one query.

Array of objects <= 10 items

The node/edge must have data in all the sources defined in the list

required
Array of objects [ 1 .. 1000 ] items
includeTyping
boolean (IncludeTyping)

Should we return property type information as part of the result?

Responses
200

List of matching nodes and edges

400

The response for a failed request.

post/models/instances/byids
Request samples
application/json
{
  • "sources": [
    ],
  • "items": [
    ],
  • "includeTyping": false
}
Response samples
application/json
{
  • "items": [
    ],
  • "typing": {
    }
}

Search for nodes/edges

Required capabilities: DataModels:READ

Search text fields in views for nodes or edge(s). The service will return up to 1000 results. This operation orders the results by relevance, across the specified spaces.

Securityoidc-token or oauth2-client-credentials or oauth2-open-industrial-data or oauth2-auth-code
Request
Request Body schema: application/json
required

The search specification.

required
object (ViewReference)

Reference to a view

query
string

Query string that will be parsed and used for search.

instanceType
string
Default: "node"

Limit the search query to searching nodes or edges. Unless you set the item type to apply the search to, the service will default to searching nodes within the view.

Enum: "node" "edge"
properties
Array of strings

Optional array of properties you want to search through. If you do not specify one or more properties, the service will search all text fields within the view.

Array of objects (TargetUnits) [ 1 .. 10 ] items

Properties to convert to another unit. The API can only convert to another unit, if a unit has been defined as part of the type on the underlying container being queried.

(BoolFilter (and (object) or or (object) or not (object))) or (LeafFilter (equals (object) or in (object) or range (object) or prefix (object) or exists (object) or containsAny (object) or containsAll (object) or matchAll (object) or nested (object) or overlaps (object) or hasData (object) or instanceReferences (object))) (FilterDefinition)
includeTyping
boolean (IncludeTyping)

Should we return property type information as part of the result?

Array of objects (SearchSort) <= 5 items
operator
string (SearchOperator)

Controls how multiple search terms are combined when matching documents.

  • OR (default): A document matches if it contains any of the query terms in the searchable fields. This typically returns more results but with lower precision.

  • AND: A document matches only if it contains all of the query terms across the searchable fields. This typically returns fewer results but with higher relevance.

Enum: "AND" "OR"
limit
integer [ 1 .. 1000 ]
Default: 1000

Limits the number of results to return.

Responses
200

Search query results

400

The response for a failed request.

post/models/instances/search
Request samples
application/json
{
  • "view": {
    },
  • "query": "string",
  • "instanceType": "node",
  • "properties": [
    ],
  • "targetUnits": [
    ],
  • "filter": {
    },
  • "includeTyping": false,
  • "sort": [
    ],
  • "operator": "AND",
  • "limit": 1000
}
Response samples
application/json
{
  • "items": [
    ],
  • "typing": {
    }
}

Aggregate data across nodes/edges

Required capabilities: dataModelsAcl:READ

Aggregate data for nodes or edges in a project. You can use an optional query or filter specification to limit the result.

Securityoidc-token or oauth2-client-credentials or oauth2-open-industrial-data or oauth2-auth-code
Request
Request Body schema: application/json
required

Aggregation specification.

query
string

Optional query string. The API will parse the query string, and use it to match the text properties on elements to use for the aggregate(s).

properties
Array of strings [ 1 .. 200 ] items

Optional list (array) of properties you want to apply the query above to. If you do not list any properties, you search through text fields by default.

limit
integer [ 1 .. 1000 ]
Default: 100

Limit the number of results returned. The default limit is currently at 100 items.

Array of avg (object) or count (object) or min (object) or max (object) or sum (object) or histogram (object) (AggregationDefinition) <= 5 items
groupBy
Array of strings [ 1 .. 5 ] items

The selection of fields to group the results by when doing aggregations. You can specify up to 5 items to group by.

When you do not specify any aggregates, the fields listed in the groupBy clause will return the unique values stored for each field. The property types supported for groupBy are text, direct, int32, int64, float32, float64, boolean, and enum.

(BoolFilter (and (object) or or (object) or not (object))) or (LeafFilter (equals (object) or in (object) or range (object) or prefix (object) or exists (object) or containsAny (object) or containsAll (object) or matchAll (object) or nested (object) or overlaps (object) or hasData (object) or instanceReferences (object))) (FilterDefinition)
operator
string (SearchOperator)

Controls how multiple search terms are combined when matching documents.

  • OR (default): A document matches if it contains any of the query terms in the searchable fields. This typically returns more results but with lower precision.

  • AND: A document matches only if it contains all of the query terms across the searchable fields. This typically returns fewer results but with higher relevance.

Enum: "AND" "OR"
instanceType
string (InstanceType)

The type of instance

Enum: "node" "edge"
required
object (ViewReference)

Reference to a view

Array of objects (TargetUnits) [ 1 .. 10 ] items

Properties to convert to another unit. The API can only convert to another unit, if a unit has been defined as part of the type on the underlying container being queried.

includeTyping
boolean (IncludeTyping)

Should we return property type information as part of the result?

Responses
200

Aggregated query results

400

The response for a failed request.

post/models/instances/aggregate
Request samples
application/json
{
  • "query": "string",
  • "properties": [
    ],
  • "limit": 100,
  • "aggregates": [
    ],
  • "groupBy": [
    ],
  • "filter": {
    },
  • "operator": "AND",
  • "instanceType": "node",
  • "view": {
    },
  • "targetUnits": [
    ],
  • "includeTyping": false
}
Response samples
application/json
{
  • "items": [
    ],
  • "typing": {
    }
}

Delete nodes/edges

Required capabilities: dataModelsAcl:WRITE

Delete nodes and edges in a transaction. Limited to 1000 nodes/edges at a time.

When a node is selected for deletion, all connected incoming and outgoing edges that point to or from it are also deleted. However, please note that the operation might fail if the node has a high number of edge connections. If this is the case, consider deleting the edges connected to the node before deleting the node itself. Nodes and/or edges that do not exist in the graph when the delete request is processed will be ignored. The rationale for this is that the end-state will reflect the desired state regardless of the instance's previous state. Note that attempting to delete something from a space that does not exist will be considered an invalid request, as the API does not affect spaces themselves, only graph nodes and edges.

Securityoidc-token or oauth2-client-credentials or oauth2-open-industrial-data or oauth2-auth-code
Request
Request Body schema: application/json
required

List of types, spaces, and external-ids for nodes and edges to delete.

required
Array of objects (InstanceDelete) [ 1 .. 1000 ] items
Responses
200

Nodes or edges that were deleted

400

The response for a failed request.

post/models/instances/delete
Request samples
application/json
{
  • "items": [
    ]
}
Response samples
application/json
{
  • "items": [
    ]
}

Query nodes/edges

Required capabilities: dataModelsAcl:READ

Specification of query endpoint. For more information, see Query language.

Securityoidc-token or oauth2-client-credentials or oauth2-open-industrial-data or oauth2-auth-code
Request
Request Body schema: application/json
required

Query specification.

required
object [ 1 .. 50 ] properties
object <= 50 properties

Cursors returned from the previous query request. These cursors match the result set expressions you specified in the with clause for the query.

required
object [ 1 .. 50 ] properties

Select properties for each result set.

object

Values in filters can be parameterised. Parameters are provided as part of the query object, and referenced in the filter itself.

includeTyping
boolean (IncludeTyping)

Should we return property type information as part of the result?

object (DebugParameters)

Return query debug notices.

Responses
200

Matching nodes and edges

400

The response for a failed request.

post/models/instances/query
Request samples
application/json
{
  • "with": {
    },
  • "cursors": {
    },
  • "select": {
    },
  • "parameters": {
    },
  • "includeTyping": false,
  • "debug": {
    }
}
Response samples
application/json
{
  • "items": {
    },
  • "typing": {
    },
  • "nextCursor": {
    },
  • "cursorCaughtUp": {
    },
  • "debug": {
    }
}

Sync nodes/edges

Required capabilities: dataModelsAcl:READ

Subscribe to changes for nodes and edges in a project, matching a supplied filter. This endpoint will always return a NextCursor. The sync specification mirrors the query interface, but sorting is not currently supported. For more information, see Query language.

Securityoidc-token or oauth2-client-credentials or oauth2-open-industrial-data or oauth2-auth-code
Request
Request Body schema: application/json
required

Change filter specification

required
object [ 1 .. 50 ] properties
object <= 50 properties

Cursors returned from the previous sync request. These cursors match the result set expressions you specified in the with clause for the sync.

required
object [ 1 .. 50 ] properties
object

Parameters to return

includeTyping
boolean (IncludeTyping)

Should we return property type information as part of the result?

allowExpiredCursorsAndAcceptMissedDeletes
boolean
Default: false

Sync cursors will expire after 3 days. This is because soft-deleted instances are cleaned up after this grace period, so a client using a cursor older than that risks missing deletes. If this option is set to true, the API will allow the use of expired cursors.

allowPartialResponse
boolean
Default: false

By default, every returned batch is full until the sync cursor is caught up to the latest instances (except between phases in two-phase sync). If this flag is true, allow returning non-full batches, or even empty batches, before the cursor is caught up. This can help to avoid timeouts if the cursor falls behind. Consult cursorCaughtUp in the query response for information as to whether there is actually more data available by following the sync cursor immediately.

object (DebugParameters)

Return query debug notices.

Responses
200

Matching nodes and edges

400

The response for a failed request.

post/models/instances/sync
Request samples
application/json
{
  • "with": {
    },
  • "cursors": {
    },
  • "select": {
    },
  • "parameters": {
    },
  • "includeTyping": false,
  • "allowExpiredCursorsAndAcceptMissedDeletes": false,
  • "allowPartialResponse": false,
  • "debug": {
    }
}
Response samples
application/json
{
  • "items": {
    },
  • "typing": {
    },
  • "nextCursor": {
    },
  • "cursorCaughtUp": {
    },
  • "debug": {
    }
}

Inspect instances

Required capabilities: dataModelsAcl:READ

Securityoidc-token or oauth2-client-credentials or oauth2-open-industrial-data or oauth2-auth-code
Request
Request Body schema: application/json
required

Change filter specification

required
object
required
Array of objects [ 1 .. 1000 ] items
Responses
200

Instances along with which containers/views they are associated with

400

The response for a failed request.

post/models/instances/inspect
Request samples
application/json
{
  • "inspectionOperations": {
    },
  • "items": [
    ]
}
Response samples
application/json
{
  • "items": [
    ]
}