ContX IQ v2: Write Values Read from the Graph with @ References
A CIQ v2 policy ("policy_version": "2.0-ciq") lets a Knowledge Query take its upsert values from the graph itself. A property value written as "@<var>.property.<name>" is read, for each row the policy's condition matches, from a variable of the policy's Cypher, then written: the client sends no value and cannot send a wrong one.
What the example shows:
- An upsert whose two values are @ references: "@subject.property.email" and "@ln.property.value".
- The 2.0-ciq filter form: the attribute carries the @ prefix ("@subject.external_id"); the token reference ($token.sub) is unchanged.
- Reading the written values back in the same execute, through the query's nodes.
Rules for @ references (checked when the Knowledge Query is saved):
- Only on 2.0-ciq policies, and only in property values of upsert_nodes and upsert_relationships.
- The reference points at a variable of the policy's Cypher, not at a node the query creates: values are read before anything is written.
- A node needs a path: an attribute, property, metadata or trust score. A bare variable is allowed only for an aggregate alias.
- A token claim is written $token.<claim>, without an @ in front.
- A literal that starts with @ is escaped as \@...
Use case
Scenario: a fleet application lets each person stamp the buses they own with their contact email and the bus's licence number, so that the bus record carries them directly. The values already live in the graph, on the person and on the licence number node; the application should not read them first and send them back, and must not be able to write someone else's email.
Graph:
- Person(karel), an identity node with the email karel@demo.com
- Bus(harmonika)
- LicenseNumber(ln-yyy) with the value ln-yyy-value
- karel -[OWNS]-> harmonika -[HAS]-> ln-yyy
Walk:
1. Capture the three nodes and two relationships.
2. Save the 2.0-ciq policy: a Person may update the buses they own, bound to the caller through $token.sub.
3. Save the Knowledge Query: upsert owner_email = @subject.property.email and licence = @ln.property.value on bus, and return both.
4. Execute as karel, with no input parameters: one record with the two values, now stored on harmonika.
The graph before
- Bus
- LicenseNumber
- Person
Requirements
Prerequisites:
- ServiceAccount credentials: For creating the policy and the Knowledge Query.
- AppAgent credentials: For the Capture calls and the execute (X-IK-ClientKey). The agent must hold Capture and ContXIQ.
- A user access token whose sub is "karel", validated by a Token Introspect configuration of the project (the policy binds the subject through $token.sub).
Required API access:
- POST /capture/v1/nodes, POST /capture/v1/relationships
- POST /configs/v1/authorization-policies
- POST /configs/v1/knowledge-queries
- POST /contx-iq/v1/execute
Steps
Step 1: Capture the graph
- Authentication: AppAgent credential.
- Action: POST the three nodes, then the OWNS and HAS relationships (the same graph as resource ciq-25).
Step 2: Create the 2.0-ciq policy
- Authentication: ServiceAccount credential.
- Action: POST the policy. Its condition matches the buses the caller owns and their licence numbers; the filter binds @subject.external_id to $token.sub; allowed_upserts lists bus as an existing node; allowed_reads covers bus.*.
- Result: the policy ID.
Step 3: Create the Knowledge Query
- Action: POST the query with policy_id set to the policy from step 2. upsert_nodes updates bus with two properties whose values are @ references; nodes reads them back.
- Result: the query ID. A reference that breaks a rule is refused here, before anything runs.
Step 4: Execute as the owner
- Authentication: AppAgent credential plus Authorization: Bearer with karel's token.
- Action: POST /contx-iq/v1/execute with the query name and empty input_params.
- Result: 200 with one record: bus.property.owner_email "karel@demo.com" and bus.property.licence "ln-yyy-value", both now stored on harmonika.
Step 1
Capture the owner, the bus and its licence number.
{
"nodes": [
{
"external_id": "karel",
"type": "Person",
"is_identity": true,
"properties": [
{
"type": "email",
"value": "karel@demo.com"
},
{
"type": "name",
"value": "Karel Plihal"
}
]
},
{
"external_id": "harmonika",
"type": "Bus",
"properties": [
{
"type": "manufacturer",
"value": "Ikarus"
},
{
"type": "model",
"value": "280"
}
]
},
{
"external_id": "ln-yyy",
"type": "LicenseNumber",
"properties": [
{
"type": "value",
"value": "ln-yyy-value"
}
]
}
]
}karel OWNS harmonika; harmonika HAS ln-yyy.
{
"relationships": [
{
"source": {
"external_id": "karel",
"type": "Person"
},
"target": {
"external_id": "harmonika",
"type": "Bus"
},
"type": "OWNS"
},
{
"source": {
"external_id": "harmonika",
"type": "Bus"
},
"target": {
"external_id": "ln-yyy",
"type": "LicenseNumber"
},
"type": "HAS"
}
]
}Step 2
The 2.0-ciq policy. The filter attribute carries the @ prefix that CIQ v2 requires; bus is the existing node a query may update.
{
"meta": {
"policy_version": "2.0-ciq"
},
"subject": {
"type": "Person"
},
"condition": {
"cypher": "MATCH (subject:Person)-[owns:OWNS]->(bus:Bus)-[:HAS]->(ln:LicenseNumber)",
"filter": [
{
"attribute": "@subject.external_id",
"operator": "=",
"value": "$token.sub"
}
]
},
"allowed_reads": {
"nodes": [
"bus.*"
]
},
"allowed_upserts": {
"nodes": {
"existing_nodes": [
"bus"
]
}
}
}Request to create the policy; the document is sent as a string in the policy field.
{
"project_id": "your_project_gid",
"name": "ciq-v2-policy-stamp-own-buses",
"display_name": "CIQ v2 policy - stamp the buses the caller owns",
"description": "Update the buses the caller owns, with values read from the caller and from each bus's licence number.",
"policy": "{\"meta\":{\"policy_version\":\"2.0-ciq\"},\"subject\":{\"type\":\"Person\"},\"condition\":{\"cypher\":\"MATCH (subject:Person)-[owns:OWNS]->(bus:Bus)-[:HAS]->(ln:LicenseNumber)\",\"filter\":[{\"attribute\":\"@subject.external_id\",\"operator\":\"=\",\"value\":\"$token.sub\"}]},\"allowed_reads\":{\"nodes\":[\"bus.*\"]},\"allowed_upserts\":{\"nodes\":{\"existing_nodes\":[\"bus\"]}}}",
"status": "ACTIVE",
"tags": []
}Step 3
The Knowledge Query. Both upsert values are @ references to variables of the policy's Cypher: subject's email property and the licence number's value. nodes returns the two written properties.
{
"nodes": [
"bus.property.owner_email",
"bus.property.licence"
],
"upsert_nodes": [
{
"name": "bus",
"properties": [
{
"type": "owner_email",
"value": "@subject.property.email"
},
{
"type": "licence",
"value": "@ln.property.value"
}
]
}
]
}Request to create the Knowledge Query.
{
"project_id": "your_project_gid",
"name": "kq-stamp-own-buses",
"display_name": "Knowledge Query - stamp the buses the caller owns",
"description": "Writes onto each bus the caller owns the caller's email and the bus's licence number value, both read from the graph, and returns them.",
"policy_id": "your_policy_gid",
"query": "{\"nodes\":[\"bus.property.owner_email\",\"bus.property.licence\"],\"upsert_nodes\":[{\"name\":\"bus\",\"properties\":[{\"type\":\"owner_email\",\"value\":\"@subject.property.email\"},{\"type\":\"licence\",\"value\":\"@ln.property.value\"}]}]}",
"status": "ACTIVE"
}Step 4
Execute as karel: X-IK-ClientKey plus Authorization: Bearer <karel's token>. No input parameters: every written value comes from the graph.
{
"id": "kq-stamp-own-buses",
"input_params": {}
}One record: the two values, read from karel and from ln-yyy, written onto harmonika and read back.
{
"data": [
{
"nodes": {
"bus.property.owner_email": "karel@demo.com",
"bus.property.licence": "ln-yyy-value"
}
}
]
}The graph after
- Bus
- LicenseNumber
- Person
API Endpoints
/capture/v1/nodes/capture/v1/relationships/configs/v1/authorization-policies/configs/v1/knowledge-queries/contx-iq/v1/execute