Create or update nodes/edges

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.

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.

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) [ 1 .. 1000 ] items

List of nodes and edges to create/update

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 or updated nodes and edges

400

The response for a failed request.

409

Ingestion conflict

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