Skip to main content

Hi, I am trying to use the Data Modeling API (https://pr-ark-codegen-1646.specs.preview.cogniteapp.com/v1.json.html#tag/Instances-(New)/operation/applyNodeAndEdges) to create instances of Views I have defined, including a reference property from one view to another. The reference property in the view looks like this:

                "facility": {

                    "type": {

                        "space": "jca-domain",

                        "externalId": "EquipmentFacility"

                    },

                    "source": {

                        "type": "view",

                        "space": "jca-domain",

                        "externalId": "Facility",

                        "version": "0_1"

                    },

                    "direction": "outwards"

                }

I’m not including the whole definition as it is kind of lengthy, but basically there is a Facility view and an Equipment view, and the above property is on the Equipment so I can link it to a Facility. I am able to create an instance of the Facility, and an instance of Equipment (without the link), but I can’t figure out how to set the facility property. It seems I need to create an edge instance, but I can’t get that to work (more specifically I don’t know what to put in the “sources” property as it seems to be looking for a node view type?).

Thanks for the help!

Hi, thanks for a good question! 

As you have correctly identified, an edge can be used to represent the relationship between a Facility and Equipment. If you wish to attach additional information to the edge, the sources property can be used. However, in many cases, it is sufficient to simply create the edge without defining any additional properties. In these instances, the request payload would be as follows:

{
"items": "
{
"instanceType": "edge",
"space": "jca-domain",
"externalId": "edge-1",
"type": {
// The type should match the type of your relation property
"space": "jca-domain",
"externalId": "EquipmentFacility"
},
"startNode": {
"space": "jca-domain",
"externalId": "equipment-1"
},
"endNode": {
"space": "jca-domain",
"externalId": "facility-1"
}
}
],
"replace": true,
"autoCreateStartNodes": false,
"autoCreateEndNodes": false
}

We’ll soon have some documentation in place to help you getting started with these new concepts. In the mean time: thanks a lot for testing out, and please reach out if you hit more issues or confusion parts. 


Thanks @Kristian Aurlien , this works. A follow-up question, using the API to retrieve nodes and edges (https://pr-ark-codegen-1646.specs.preview.cogniteapp.com/v1.json.html#tag/Instances-(New)/operation/advancedListInstance), how do I retrieve the edges of a specific type (e.g. EquipmentFacility)? Or should I rather look into the query API (https://pr-ark-codegen-1646.specs.preview.cogniteapp.com/v1.json.html#tag/Instances-(New)/operation/queryContent)? Either way an example would be welcome.


For `/instances/list` a minimal query would look like this:

{
"instanceType": "edge",
"filter": {
"equals": {
"property": "edge", "type"],
"value": "jca-domain", "EquipmentFacility"]
}
}
}

 

while for `/instances/query` you would do:

{
"with": {
"myEdges": {
"edges": {
"filter": {
"equals": {
"property": :"edge", "type"],
"value": :"jca-domain", "EquipmentFacility"]
}
}
}
}
},
"select": {
"myEdges": {}
}
}

 


Reply