Applying instances
This exampleapply request attempts to ingest a node with the external ID pump42 into the space equipment, and set the Pump/v1.producer view property to “Acme Inc.”.
Create, patch, and replace
When you apply instances, you can use three distinct modes depending on the existing state and the request parameters.- If the instance does not exist at the time of ingestion, it will be created. This means that all required properties must be set.
-
If the instance already exists, you have two updating methods:
patchandreplace. You choose the method by setting the value of thereplaceflag. The value can betrueorfalse, and the default value isfalse. Withpatch, only the properties that are provided in thesourcessection of the request will be updated, leaving all other properties unchanged.
replace, all properties will be updated, and omitted properties will be set to null. Consequently, all required properties must have a value specified in the request body when you update an instance with replace=true.
Autocreate nodes
When ingesting instances, you can autocreate the targets of direct relation properties and ingest a graph without worrying about the order in which you ingest the instances. Use these properties to control this behavior:autoCreateDirectRelations: automatically create all direct relations in the request if a relation is not previously created (default:true.)autoCreateStartNodes: when set totrue, automatically create any missing start nodes for the edge (default:false.) When the parameter is set tofalseand the indicated start node is not present, the request will fail with a HTTP status code of 409, indicating a conflict with the current state of the service.autoCreateEndNodes: when set totrue, automatically create any missing end nodes for the edge (default:false.) When the parameter is set tofalseand the indicated end node is not present, the request will fail with a HTTP status code of 409, indicating a conflict with the current state of the service.
Optimistic concurrency control
Every instance has a version number. It starts atversion: 1 and increments by 1 each time the instance is changed. The apply endpoint supports optimistic concurrency control and allows you to specify an expected existing version on the instance. If an actual version is greater than the expected version, the request fails with status code 409.
The following example creates a pump node with the external ID “pump42”. We set existingVersion to 0 to make sure the node does not exist, and that you will be creating the node.
If the node equipment.pump42 already exists, the request will fail. If it doesn’t exist, the node is created.
equipment.pump42 and set the Pump/v1.producer property to “Acme Inc.”, but only if the producer property is currently null, to prevent you from overwriting someone else’s changes.
First, read the node and verify that the producer property is null and then apply the update specifying existingVersion=$currentVersion. If the first read request returns version: 1, you can apply the instance:
producer property in the meantime, their request has bumped the node’s version to 2. Because you specified existingVersion: 1, but the actual value is version: 2, the request fails with status code 409. You can read the node again, check if the producer property is null, and repeat the process with existingVersion set to 2.
You can also not fail the entire request when there are version conflicts, and instead ignore updates to the instances that have version conflicts. You do this by setting skipOnVersionConflict to true in the request.
Sending an update request that will not update the instance’s properties will not bump the
version or lastUpdatedTime of the instance.Deleting instances
To delete nodes and edges from the graph, you send a list of fully qualified external IDs to the/delete endpoint. This example deletes a node and an edge:
equipment.pump42, since the equipment.i-dont-exist edge does not exist:
Soft deletion
To support syncing deletes to secondary stores, instances are always soft deleted at first. The soft-deleted instances will be returned by the /sync endpoint withdeletedTime set to a non-null value.
After a grace period (3 days by default), the instances are deleted by the system. Soft deleted instances count towards the total instance limits for you CDF project.
You can not restore soft deleted instances.