ContX IQ: allow creation nodes and relationships.
An Application node is allowed to create a Contract node and link it to existing Person and Vehicle nodes. where the Vehicle node is owned by a company with which the Application has an Agreement.
Use case
The query allows derived queries to create:
1. New nodes with the label Contract.
2. New relationships, of type COVERS, between Contract and Vehicle nodes.
3. New relationships, of type ACCEPTED, between Person and Contract nodes.

Requirements
- ServiceAccount credentials created in the IndyKite Hub for your organization.
- AppAgent credentials created in the IndyKite Hub, using the REST endpoints or using Terraform for your Project / Application.
Steps
1. Using the AppAgent credential as API Key (name: X-IK-ClientKey), ingest data in your IKG (IndyKite Knowledge Graph) using the script provided.
2. Using the ServiceAccount credential as Bearer token, create CIQ Policy, with _Application as subject.
When a new Application with new credentials is created, _Application and _AppAgent nodes are created in the IKG.
In order to create a relationship between these nodes and the ingest data, a CIQ write query can be used.
This will allow the use of the _Application as an authenticated subject.
We add a filter with attribute: subject.external_id and value: $_appId (reserved value).
When the subject is _Application, the $_appId input does not need to be provided in the CIQ Execution and is automatically assigned the subject.external_id value.
In this case, a HAS_AGREEMENT_WITH relationship is created between the _Application node and a company node.
3. Using the ServiceAccount credential as Bearer token, create a CIQ Query.
4. Using the AppAgent credential as API Key (name: X-IK-ClientKey), run a CIQ Execution to link the _Application node.
5. Using the ServiceAccount credential as Bearer token, create CIQ Policy, with _Application as subject.
6. Using the ServiceAccount credential as Bearer token, create a CIQ Query in the context of the policy to upsert the data.
7. Using the AppAgent credential as API Key (name: X-IK-ClientKey), run a CIQ Execution.
8. Delete your configuration.
Step 1
Ingest the nodes needed for this use case.
{
"nodes": [
{
"external_id": "alice",
"is_identity": true,
"type": "Person",
"properties": [
{
"type": "email",
"value": "alice@email.com"
},
{
"type": "given_name",
"value": "Alice"
},
{
"type": "last_name",
"value": "Smith"
}
]
},
{
"external_id": "ryan",
"is_identity": true,
"type": "Person",
"properties": [
{
"type": "email",
"value": "ryan@yahoo.co.uk"
},
{
"type": "given_name",
"value": "ryan"
},
{
"type": "last_name",
"value": "mushu"
}
]
},
{
"external_id": "tilda",
"is_identity": true,
"type": "Person",
"properties": [
{
"type": "email",
"value": "tilda@yahoo.co.uk"
},
{
"type": "given_name",
"value": "tilda"
},
{
"type": "last_name",
"value": "mushu"
}
]
},
{
"external_id": "cb123",
"type": "PaymentMethod",
"properties": [
{
"type": "payment_name",
"value": "Credit Card"
}
]
},
{
"external_id": "kl123",
"type": "PaymentMethod",
"properties": [
{
"type": "payment_name",
"value": "Klarna"
}
]
},
{
"external_id": "ct123",
"type": "Contract",
"properties": [
{
"type": "category",
"value": "Insurance"
},
{
"type": "status",
"value": "Active"
},
{
"type": "number",
"value": "hfgrten123",
"metadata": {
"assurance_level": 3,
"source": "BRREG"
}
}
]
},
{
"external_id": "ct234",
"type": "Contract",
"properties": [
{
"type": "category",
"value": "Insurance"
},
{
"type": "status",
"value": "Active"
},
{
"type": "number",
"value": "hfgrten234",
"metadata": {
"assurance_level": 3,
"source": "BRREG"
}
}
]
},
{
"external_id": "ct985",
"type": "Contract",
"properties": [
{
"type": "category",
"value": "Insurance"
},
{
"type": "status",
"value": "Active"
},
{
"type": "number",
"value": "hfgrten985",
"metadata": {
"assurance_level": 3,
"source": "BRREG"
}
}
]
},
{
"external_id": "car1",
"type": "Vehicle",
"properties": [
{
"type": "category",
"value": "Car"
},
{
"type": "is_active",
"value": true
},
{
"type": "vin",
"value": "rtfhcnvjt471"
}
]
},
{
"external_id": "car2",
"type": "Vehicle",
"properties": [
{
"type": "category",
"value": "Car"
},
{
"type": "is_active",
"value": true
},
{
"type": "vin",
"value": "kdcbfrt178"
}
]
},
{
"external_id": "truck1",
"type": "Vehicle",
"properties": [
{
"type": "category",
"value": "Truck"
},
{
"type": "is_active",
"value": true
},
{
"type": "vin",
"value": "sncnrkcldp"
}
]
},
{
"external_id": "license1",
"type": "LicenseNumber",
"properties": [
{
"type": "status",
"value": "Active"
},
{
"type": "number",
"value": "AX123456",
"metadata": {
"assurance_level": 3,
"source": "BRREG"
}
}
]
},
{
"external_id": "license2",
"type": "LicenseNumber",
"properties": [
{
"type": "status",
"value": "Active"
},
{
"type": "number",
"value": "OL123456",
"metadata": {
"assurance_level": 3,
"source": "BRREG"
}
}
]
},
{
"external_id": "license3",
"type": "LicenseNumber",
"properties": [
{
"type": "status",
"value": "Active"
},
{
"type": "number",
"value": "VN123456",
"metadata": {
"assurance_level": 3,
"source": "BRREG"
}
}
]
},
{
"external_id": "company1",
"type": "Company",
"properties": [
{
"type": "name",
"value": "Company1"
},
{
"type": "registration",
"value": "256314523"
}
]
},
{
"external_id": "company2",
"type": "Company",
"properties": [
{
"type": "name",
"value": "Company2"
},
{
"type": "registration",
"value": "942365123"
}
]
},
{
"external_id": "application1",
"type": "Application",
"properties": [
{
"type": "name",
"value": "Application"
}
]
},
{
"external_id": "application2",
"type": "Application",
"properties": [
{
"type": "name",
"value": "Application2"
}
]
}
]
}Ingest the relationships needed for this use case.
{
"relationships": [
{
"source": {
"external_id": "ryan",
"type": "Person"
},
"target": {
"external_id": "cb123",
"type": "PaymentMethod"
},
"type": "HAS"
},
{
"source": {
"external_id": "tilda",
"type": "Person"
},
"target": {
"external_id": "kl123",
"type": "PaymentMethod"
},
"type": "HAS"
},
{
"source": {
"external_id": "alice",
"type": "Person"
},
"target": {
"external_id": "cb123",
"type": "PaymentMethod"
},
"type": "HAS"
},
{
"source": {
"external_id": "ryan",
"type": "Person"
},
"target": {
"external_id": "ct123",
"type": "Contract"
},
"type": "ACCEPTED"
},
{
"source": {
"external_id": "tilda",
"type": "Person"
},
"target": {
"external_id": "ct234",
"type": "Contract"
},
"type": "ACCEPTED"
},
{
"source": {
"external_id": "alice",
"type": "Person"
},
"target": {
"external_id": "ct985",
"type": "Contract"
},
"type": "ACCEPTED"
},
{
"source": {
"external_id": "ct123",
"type": "Contract"
},
"target": {
"external_id": "car1",
"type": "Vehicle"
},
"type": "COVERS"
},
{
"source": {
"external_id": "ct985",
"type": "Contract"
},
"target": {
"external_id": "car1",
"type": "Vehicle"
},
"type": "COVERS"
},
{
"source": {
"external_id": "ct234",
"type": "Contract"
},
"target": {
"external_id": "truck1",
"type": "Vehicle"
},
"type": "COVERS"
},
{
"source": {
"external_id": "car1",
"type": "Vehicle"
},
"target": {
"external_id": "license1",
"type": "LicenseNumber"
},
"type": "HAS"
},
{
"source": {
"external_id": "truck1",
"type": "Vehicle"
},
"target": {
"external_id": "license2",
"type": "LicenseNumber"
},
"type": "HAS"
},
{
"source": {
"external_id": "car2",
"type": "Vehicle"
},
"target": {
"external_id": "license3",
"type": "LicenseNumber"
},
"type": "HAS"
},
{
"source": {
"external_id": "company1",
"type": "Company"
},
"target": {
"external_id": "car1",
"type": "Vehicle"
},
"type": "OWNS"
},
{
"source": {
"external_id": "company1",
"type": "Company"
},
"target": {
"external_id": "car2",
"type": "Vehicle"
},
"type": "OWNS"
},
{
"source": {
"external_id": "company1",
"type": "Company"
},
"target": {
"external_id": "truck1",
"type": "Vehicle"
},
"type": "OWNS"
},
{
"source": {
"external_id": "application1",
"type": "Application"
},
"target": {
"external_id": "company1",
"type": "Company"
},
"type": "HAS_AGREEMENT_WITH"
},
{
"source": {
"external_id": "application2",
"type": "Application"
},
"target": {
"external_id": "company1",
"type": "Company"
},
"type": "HAS_AGREEMENT_WITH"
}
]
}Step 2
Policy which designates the derived query can create the HAS_AGREEMENT_WITH relationship.
{
"meta": {
"policy_version": "1.0-ciq"
},
"subject": {
"type": "_Application"
},
"condition": {
"cypher": "MATCH (subject:_Application) MATCH (company:Company)-[r2:OWNS]->(vehicle:Vehicle)",
"filter": [
{
"operator": "AND",
"operands": [
{
"attribute": "subject.external_id",
"operator": "=",
"value": "$_appId"
},
{
"attribute": "company.external_id",
"operator": "=",
"value": "$companyID"
}
]
}
]
},
"allowed_upserts": {
"relationships": {
"relationship_types": [
{
"type": "HAS_AGREEMENT_WITH",
"source_node_label": "_Application",
"target_node_label": "Company"
}
]
}
},
"allowed_reads": {
"nodes": [
"company.*",
"subject.*"
]
}
}Request to create a CIQ Policy configuration using REST.
{
"project_id": "your_project_gid",
"description": "description of policy",
"display_name": "policy name",
"name": "policy-name",
"policy": "{\"meta\":{\"policy_version\":\"1.0-ciq\"},\"subject\":{\"type\":\"_Application\"},\"condition\":{\"cypher\":\"MATCH (subject:_Application) MATCH (company:Company)-[r2:OWNS]->(vehicle:Vehicle)\",\"filter\":[{\"operator\":\"AND\",\"operands\":[{\"attribute\":\"subject.external_id\",\"operator\":\"=\",\"value\":\"$_appId\"},{\"attribute\":\"company.external_id\",\"operator\":\"=\",\"value\":\"$companyID\"}]}]},\"allowed_upserts\":{\"relationships\":{\"relationship_types\":[{\"type\":\"HAS_AGREEMENT_WITH\",\"source_node_label\":\"_Application\",\"target_node_label\":\"Company\"}]}},\"allowed_reads\":{\"nodes\":[\"company.*\",\"subject.*\"]}}",
"status": "ACTIVE",
"tags": []
}Request to read the CIQ Policy configuration using REST.
{
"id": "your_policy_configuration_gid"
}Step 3
The CIQ Query designates the relationship to upsert.
{
"nodes": [
"subject.external_id"
],
"relationships": [
"r1"
],
"upsert_relationships": [
{
"name": "r1",
"source": "subject",
"target": "company",
"type": "HAS_AGREEMENT_WITH"
}
]
}Request to create a CIQ Query configuration using REST.
{
"project_id": "your_project_gid",
"description": "description of knowledge query",
"display_name": "knowledge query name",
"name": "knowledge-query-name",
"policy_id": "your_policy_gid",
"query": "{\"nodes\":[\"subject.external_id\"],\"relationships\":[\"r1\"],\"upsert_relationships\":[{\"name\":\"r1\",\"source\":\"subject\",\"target\":\"company\",\"type\":\"HAS_AGREEMENT_WITH\"}]}",
"status": "ACTIVE"
}Read the CIQ Query Configuration.
{
"id": "your_knowledge_query_configuration_gid"
}Step 4
CIQ Execution request in json format.
{
"id": "ciq_query_gid",
"input_params": {
"companyID": "company1"
}
}CIQ Execution response in json format.
{
"data": [
{
"nodes": {
"subject.external_id": "application_external_id"
},
"relationships": {
"r1": {
"Id": 1152932499723124700,
"ElementId": "5:3a2b09d5-2923-45d7-8453-8b1c698427b0:1152932499723124736",
"StartId": 0,
"StartElementId": "4:3a2b09d5-2923-45d7-8453-8b1c698427b0:0",
"EndId": 15,
"EndElementId": "4:3a2b09d5-2923-45d7-8453-8b1c698427b0:15",
"Type": "HAS_AGREEMENT_WITH",
"Props": {
"create_time": "2025-06-09T15:12:46.374Z",
"id": "48BJHS2CTFKcVpD4cUF8IA",
"update_time": "2025-06-09T15:12:46.374Z"
}
}
}
},
{
"nodes": {
"subject.external_id": "application_external_id"
},
"relationships": {
"r1": {
"Id": 1152932499723124700,
"ElementId": "5:3a2b09d5-2923-45d7-8453-8b1c698427b0:1152932499723124736",
"StartId": 0,
"StartElementId": "4:3a2b09d5-2923-45d7-8453-8b1c698427b0:0",
"EndId": 15,
"EndElementId": "4:3a2b09d5-2923-45d7-8453-8b1c698427b0:15",
"Type": "HAS_AGREEMENT_WITH",
"Props": {
"create_time": "2025-06-09T15:12:46.374Z",
"id": "48BJHS2CTFKcVpD4cUF8IA",
"update_time": "2025-06-09T15:12:46.374Z"
}
}
}
},
{
"nodes": {
"subject.external_id": "application_external_id"
},
"relationships": {
"r1": {
"Id": 1152932499723124700,
"ElementId": "5:3a2b09d5-2923-45d7-8453-8b1c698427b0:1152932499723124736",
"StartId": 0,
"StartElementId": "4:3a2b09d5-2923-45d7-8453-8b1c698427b0:0",
"EndId": 15,
"EndElementId": "4:3a2b09d5-2923-45d7-8453-8b1c698427b0:15",
"Type": "HAS_AGREEMENT_WITH",
"Props": {
"create_time": "2025-06-09T15:12:46.374Z",
"id": "48BJHS2CTFKcVpD4cUF8IA",
"update_time": "2025-06-09T15:12:46.374Z"
}
}
}
}
]
}Step 5
CIQ Policy which allows an Application to create a Contract node and link it to existing Person and Vehicle nodes
{
"meta": {
"policy_version": "1.0-ciq"
},
"subject": {
"type": "_Application"
},
"condition": {
"cypher": "MATCH (subject:_Application)-[r1:HAS_AGREEMENT_WITH]->(company:Company)-[r2:OWNS]->(vehicle:Vehicle) MATCH (person:Person)",
"filter": [
{
"operator": "AND",
"operands": [
{
"attribute": "subject.external_id",
"operator": "=",
"value": "$_appId"
},
{
"attribute": "vehicle.external_id",
"operator": "=",
"value": "$vehicleID"
},
{
"attribute": "person.external_id",
"operator": "=",
"value": "$personID"
}
]
}
]
},
"allowed_upserts": {
"nodes": {
"node_types": [
"Contract"
]
},
"relationships": {
"relationship_types": [
{
"type": "COVERS",
"source_node_label": "Contract",
"target_node_label": "Vehicle"
},
{
"type": "ACCEPTED",
"source_node_label": "Person",
"target_node_label": "Contract"
}
]
}
},
"allowed_reads": {
"nodes": [
"vehicle.property.*",
"person.property.*"
],
"relationships": []
}
}Request to create a CIQ Policy configuration using REST.
{
"project_id": "your_project_gid",
"description": "description of policy",
"display_name": "policy name",
"name": "policy-name",
"policy": "{\"meta\":{\"policy_version\":\"1.0-ciq\"},\"subject\":{\"type\":\"_Application\"},\"condition\":{\"cypher\":\"MATCH (subject:_Application)-[r1:HAS_AGREEMENT_WITH]->(company:Company)-[r2:OWNS]->(vehicle:Vehicle) MATCH (person:Person)\",\"filter\":[{\"operator\":\"AND\",\"operands\":[{\"attribute\":\"subject.external_id\",\"operator\":\"=\",\"value\":\"$_appId\"},{\"attribute\":\"vehicle.external_id\",\"operator\":\"=\",\"value\":\"$vehicleID\"},{\"attribute\":\"person.external_id\",\"operator\":\"=\",\"value\":\"$personID\"}]}]},\"allowed_upserts\":{\"nodes\":{\"node_types\":[\"Contract\"]},\"relationships\":{\"relationship_types\":[{\"type\":\"COVERS\",\"source_node_label\":\"Contract\",\"target_node_label\":\"Vehicle\"},{\"type\":\"ACCEPTED\",\"source_node_label\":\"Person\",\"target_node_label\":\"Contract\"}]}},\"allowed_reads\":{\"nodes\":[\"vehicle.property.*\",\"person.property.*\"],\"relationships\":[]}}",
"status": "ACTIVE",
"tags": []
}Request to read the CIQ Policy configuration using REST.
{
"id": "your_policy_configuration_gid"
}Step 6
The query creates the Contract node and the COVERS and ACCEPTED relationships.
Note that the external_id and number for the Contract node are parameterized (variable names starting with $),
and their actual values are provided at execution time.
{
"nodes": [
"contract.external_id",
"contract.property.number"
],
"relationships": [],
"upsert_nodes": [
{
"name": "contract",
"type": "Contract",
"external_id": "$contract_external_id",
"properties": [
{
"type": "number",
"value": "$contractNumber"
},
{
"type": "status",
"value": "Active"
}
]
}
],
"upsert_relationships": [
{
"name": "r3",
"source": "contract",
"target": "vehicle",
"type": "COVERS"
},
{
"name": "r4",
"source": "person",
"target": "contract",
"type": "ACCEPTED"
}
]
}Request to create a CIQ Query configuration using REST.
{
"project_id": "your_project_gid",
"description": "description of knowledge query",
"display_name": "knowledge query name",
"name": "knowledge-query-name",
"policy_id": "your_policy_gid",
"query": "{\"nodes\":[\"contract.external_id\",\"contract.property.number\"],\"relationships\":[],\"upsert_nodes\":[{\"name\":\"contract\",\"type\":\"Contract\",\"external_id\":\"$contract_external_id\",\"properties\":[{\"type\":\"number\",\"value\":\"$contractNumber\"},{\"type\":\"status\",\"value\":\"Active\"}]}],\"upsert_relationships\":[{\"name\":\"r3\",\"source\":\"contract\",\"target\":\"vehicle\",\"type\":\"COVERS\"},{\"name\":\"r4\",\"source\":\"person\",\"target\":\"contract\",\"type\":\"ACCEPTED\"}]}",
"status": "ACTIVE"
}Read the CIQ Query Configuration.
{
"id": "your_knowledge_query_configuration_gid"
}Step 7
CIQ Execution request.
{
"id": "knowledge_query_gid",
"input_params": {
"vehicleID": "car2",
"personID": "ryan",
"contract_external_id": "ct853",
"contractNumber": "rbjh853"
}
}CIQ Execution response.
{
"data": [
{
"nodes": {
"contract.external_id": "ct853",
"contract.property.number": "rbjh853"
}
}
]
}Step 8
Delete the CIQ Queries.
{
"id": "your_knowledge_query_configuration_gid"
}Delete the CIQ Policies.
{
"id": "your_policy_configuration_gid"
}