Skip to main content
POST
/
models
/
instances
Python SDK
from cognite.client.data_classes.data_modeling import EdgeApply, NodeOrEdgeData, NodeApply
node = NodeApply("mySpace", "myNodeId")
res = client.data_modeling.instances.apply(node)

from cognite.client.data_classes.data_modeling import EdgeApply, NodeOrEdgeData, NodeApply, ViewId
actor = NodeApply(
    space="actors",
    external_id="arnold_schwarzenegger",
    sources=[
        NodeOrEdgeData(
            ViewId("mySpace", "PersonView", "v1"),
            {"name": "Arnold Schwarzenegger", "birthYear": 1947}
        ),
        NodeOrEdgeData(
            ViewId("mySpace", "ActorView", "v1"),
            {"wonOscar": False}
        )
    ]
)
movie = NodeApply(
    space="movies",
    external_id="Terminator",
    sources=[
        NodeOrEdgeData(
            ViewId("mySpace", "MovieView", "v1"),
            {"title": "Terminator", "releaseYear": 1984}
        )
    ]
)
# This is one-to-many edge, in this case from a person to a movie
actor_to_movie = EdgeApply(
    space="actors",
    external_id="relation:arnold_schwarzenegger:terminator",
    type=("types", "acts-in"),
    start_node=("actors", "arnold_schwarzenegger"),
    end_node=("movies", "Terminator"),
)
res = client.data_modeling.instances.apply([actor, movie], [actor_to_movie])

from cognite.client.data_classes.data_modeling import EdgeApply
actor_to_movie = EdgeApply(
    space="actors",
    external_id="relation:arnold_schwarzenegger:terminator",
    type=("types", "acts-in"),
    start_node=("actors", "arnold_schwarzenegger"),
    end_node=("movies", "Terminator"),
)
res = client.data_modeling.instances.apply(
    edges=actor_to_movie,
    auto_create_start_nodes=True,
    auto_create_end_nodes=True
)

from cognite.client.utils import datetime_to_ms_iso_timestamp
from datetime import datetime, timezone
my_date = datetime(2020, 3, 14, 15, 9, 26, 535000, tzinfo=timezone.utc)
data_model_timestamp = datetime_to_ms_iso_timestamp(my_date)  # "2020-03-14T15:09:26.535+00:00"

from cognite.client.data_classes.data_modeling import TypedNodeApply, PropertyOptions
class PersonApply(TypedNodeApply):
    birth_year = PropertyOptions(identifier="birthYear")

    def __init__(self, space: str, external_id, name: str, birth_year: int):
        super().__init__(space, external_id, type=("sp_model_space", "Person"))
        self.name = name
        self.birth_year = birth_year
    def get_source(self):
        return ViewId("sp_model_space", "Person", "v1")
person = PersonApply("sp_date_space", "my_person", "John Doe", 1980)
res = client.data_modeling.instances.apply(nodes=person)
{
  "items": [
    {
      "instanceType": "node",
      "version": 123,
      "wasModified": true,
      "space": "<string>",
      "externalId": "<string>",
      "createdTime": 1730204346000,
      "lastUpdatedTime": 1730204346000
    }
  ],
  "deleted": [
    {
      "instanceType": "node",
      "externalId": "<string>",
      "space": "<string>"
    }
  ]
}

Authorizations

Authorization
string
header
required

Access token issued by the CDF project's configured identity provider. Access token must be an OpenID Connect token, and the project must be configured to accept OpenID Connect tokens. Use a header key of 'Authorization' with a value of 'Bearer $accesstoken'. The token can be obtained through any flow supported by the identity provider.

Body

application/json

Nodes/edges to add or update.

items
object[]
required

List of nodes and edges to create/update

Maximum array length: 1000

Node to create or update

delete
object[]

List of nodes and edges to delete

Maximum array length: 1000
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.

Response

Created, deleted, and updated instances

items
object[]
required

List of nodes and edges that were created or updated

Node

deleted
object[]
required

List of deleted instances

Required array length: 1 - 1000 elements
Last modified on April 23, 2026