ContX IQ v2: Read a Whole Relationship with Its Endpoints
When a Knowledge Query on a 2.0-ciq policy asks for a whole relationship (its variable alone, such as "owns"), the relationship comes back by its endpoints:
- _startNode_external_id and _startNode_type: the node the relationship starts from.
- _endNode_external_id and _endNode_type: the node it points to.
- Props: the relationship's id (a GID), its timestamps and its own properties.
So a client reads who is linked to what straight from the answer, in the same identifiers it uses everywhere else (external_id and type), without asking for the endpoint nodes separately. A variable-length relationship comes back as a list of these objects, one per hop.
Other ways to read a relationship:
- "owns.since" returns the one property, and "owns.*" all of them.
- A filter attribute on a 2.0-ciq policy carries the @ prefix, as in "@subject.external_id".
Use case
Scenario: a fleet dashboard lists, for the signed-in person, the buses they own and since when. It needs the ownership itself, not only the buses: who owns, what is owned, and the since property of OWNS.
Graph:
- Person(karel), an identity node
- Bus(harmonika)
- LicenseNumber(ln-yyy)
- karel -[OWNS {since: 2024-05-01}]-> harmonika -[HAS]-> ln-yyy
Walk:
1. Capture the three nodes, and the relationships with since on OWNS.
2. Save the 2.0-ciq policy: a Person reads the buses they own and the OWNS relationship, bound to the caller through $token.sub.
3. Save the Knowledge Query: bus.external_id and the whole owns relationship.
4. Execute as karel: one record, with owns as karel (Person) to harmonika (Bus) and its properties.
The graph
- 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 relationship with its since property and the HAS relationship.
Step 2: Create the 2.0-ciq policy
- Authentication: ServiceAccount credential.
- Action: POST the policy. Its condition matches the buses the caller owns; the filter binds @subject.external_id to $token.sub; allowed_reads covers bus.external_id and the owns relationship.
- Result: the policy ID.
Step 3: Create the Knowledge Query
- Action: POST the query with policy_id set to the policy from step 2: nodes bus.external_id, relationships owns.
- Result: the query ID.
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.external_id "harmonika", and owns as {_startNode_external_id "karel", _startNode_type "Person", _endNode_external_id "harmonika", _endNode_type "Bus", Props with id, timestamps and since}.
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 since 2024-05-01; harmonika HAS ln-yyy.
{
"relationships": [
{
"source": {
"external_id": "karel",
"type": "Person"
},
"target": {
"external_id": "harmonika",
"type": "Bus"
},
"type": "OWNS",
"properties": [
{
"type": "since",
"value": "2024-05-01"
}
]
},
{
"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; owns is listed whole in allowed_reads.relationships.
{
"meta": {
"policy_version": "2.0-ciq"
},
"subject": {
"type": "Person"
},
"condition": {
"cypher": "MATCH (subject:Person)-[owns:OWNS]->(bus:Bus)",
"filter": [
{
"attribute": "@subject.external_id",
"operator": "=",
"value": "$token.sub"
}
]
},
"allowed_reads": {
"nodes": [
"bus.external_id"
],
"relationships": [
"owns"
]
}
}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-own-buses-ownership",
"display_name": "CIQ v2 policy - own buses with the ownership relationship",
"description": "Read the buses the caller owns and the OWNS relationship that links the caller to each.",
"policy": "{\"meta\":{\"policy_version\":\"2.0-ciq\"},\"subject\":{\"type\":\"Person\"},\"condition\":{\"cypher\":\"MATCH (subject:Person)-[owns:OWNS]->(bus:Bus)\",\"filter\":[{\"attribute\":\"@subject.external_id\",\"operator\":\"=\",\"value\":\"$token.sub\"}]},\"allowed_reads\":{\"nodes\":[\"bus.external_id\"],\"relationships\":[\"owns\"]}}",
"status": "ACTIVE",
"tags": []
}Step 3
The Knowledge Query: the bus's external_id and the whole owns relationship.
{
"nodes": [
"bus.external_id"
],
"relationships": [
"owns"
]
}Request to create the Knowledge Query.
{
"project_id": "your_project_gid",
"name": "kq-own-buses-with-ownership",
"display_name": "Knowledge Query - own buses with the ownership relationship",
"description": "Returns the buses the caller owns, each with the whole OWNS relationship: its two endpoints and its properties.",
"policy_id": "your_policy_gid",
"query": "{\"nodes\":[\"bus.external_id\"],\"relationships\":[\"owns\"]}",
"status": "ACTIVE"
}Step 4
Execute as karel: X-IK-ClientKey plus Authorization: Bearer <karel's token>. No input parameters; the subject comes from the token.
{
"id": "kq-own-buses-with-ownership",
"input_params": {}
}One record: owns named by its endpoints, karel (Person) to harmonika (Bus), with its id as a GID, its timestamps and since in Props.
{
"data": [
{
"nodes": {
"bus.external_id": "harmonika"
},
"relationships": {
"owns": {
"_startNode_external_id": "karel",
"_startNode_type": "Person",
"_endNode_external_id": "harmonika",
"_endNode_type": "Bus",
"Props": {
"id": "gid:AAAAF...",
"create_time": "2026-11-11T09:12:04.731Z",
"update_time": "2026-11-11T09:12:04.731Z",
"since": "2024-05-01"
}
}
}
}
]
}API Endpoints
/capture/v1/nodes/capture/v1/relationships/configs/v1/authorization-policies/configs/v1/knowledge-queries/contx-iq/v1/execute