{
  "id": "ciq-19",
  "title": "ContX IQ: Which nodes are directly connected to a user?",
  "description": "Query all nodes that have a direct relationship with a specified User node, regardless of relationship type or direction. Useful for user profile views, data export, or understanding a user's complete data footprint.",
  "category": "ContX IQ",
  "tags": [
    "ContX IQ Policy",
    "ContX IQ Query",
    "Graph Traversal",
    "Related Nodes",
    "User Data",
    "Direct Relationships"
  ],
  "api": "ContX IQ",
  "language": "Json",
  "lastUpdated": "2026-03-20",
  "openApiEndpoints": [
    "/capture/v1/nodes",
    "/capture/v1/relationships",
    "/configs/v1/authorization-policies",
    "/configs/v1/knowledge-queries",
    "/contx-iq/v1/execute"
  ],
  "relatedGuides": [
    "/guides/guide-contx-iq",
    "/guides/guide-sandbox"
  ],
  "commonErrors": [
    {
      "code": "401",
      "message": "UNAUTHENTICATED",
      "solution": "Check credentials: ServiceAccount Bearer token for config APIs, X-IK-ClientKey for execution"
    },
    {
      "code": "404",
      "message": "NOT_FOUND",
      "solution": "Verify the query/policy ID exists and belongs to your project"
    }
  ],
  "summary": "This example retrieves all directly connected nodes for a user:\n\nPolicy pattern:\nMATCH (subject:_Application) MATCH (u:User)-[]-(n:Resource)\nwith filter u.external_id = $user_external_id (and subject.external_id = $_appId)\n\nReturns all nodes with ANY direct relationship to the user:\n- Incoming relationships: (other)-[r]->(u)\n- Outgoing relationships: (u)-[r]->(other)\n- Any relationship type (the pattern -[]- names no type and no direction)\n\nUse cases:\n- User profile aggregation\n- GDPR data export (all user-related data)\n- Impact analysis (what's connected to this user?)",
  "usecase": "Scenario: Build a user dashboard showing all related entities.\n\nUser graph:\nUser(nico)\n  -[PART_OF {weight: 1}]-> Company(tyrest)\n  -[WORKS_IN]-> Country(norway)\n  <-[ASSIGNED_TO]- Role(customer)\n  <-[BELONGS_TO]- Account(123456)\nUser(fred)\n  -[WORKS_IN]-> Country(sweden)\n  <-[ASSIGNED_TO]- Role(customer)\n  <-[BELONGS_TO]- Account(234567)\n\nQuery input: user_external_id = \"nico\"\n\nQuery result (one row per connected node: n.external_id, n.type, n.property.*):\n[\n  {type: \"Account\", id: \"123456\", properties: [location = CityHub]},\n  {type: \"Role\", id: \"customer\", properties: [source = Head]},\n  {type: \"Country\", id: \"norway\", properties: [name = Norway]},\n  {type: \"Company\", id: \"tyrest\", properties: [name = Tyrest]}\n]\n\nAll direct connections returned regardless of direction or type.",
  "requirements": "Prerequisites:\n- ServiceAccount credentials: For creating policies and queries (Bearer token)\n- AppAgent credentials: For data ingestion and query execution (X-IK-ClientKey)\n\nApplication as subject:\n- Uses $_appId filter (auto-populated)\n- No user token required for this pattern",
  "steps": "Step 1: Ingest Users and Related Nodes\n- Authentication: AppAgent credential (X-IK-ClientKey header)\n- Action: POST User (nico, fred), Role (customer), Country (norway, sweden), Account (123456, 234567) and Company (tyrest, blue) nodes, then the PART_OF (with a weight property), WORKS_IN, ASSIGNED_TO and BELONGS_TO relationships\n- Result: Rich user graph ready for traversal\n\nStep 2: Create Related Nodes Policy\n- Authentication: ServiceAccount credential (Bearer token)\n- Action: POST policy with subject type _Application and cypher MATCH (subject:_Application) MATCH (u:User)-[]-(n:Resource), filter subject.external_id = $_appId AND u.external_id = $user_external_id, allowing READ on u, u.*, n and n.*\n- Result: Policy ID returned\n\nStep 3: Create Related Nodes Query\n- Authentication: ServiceAccount credential (Bearer token)\n- Action: POST query that returns n.external_id, n.type and n.property.* for every node n connected to the user selected by the policy filter (any type, any direction)\n- Result: Query ID returned\n\nStep 4: Execute Query\n- Authentication: AppAgent credential (X-IK-ClientKey header)\n- Action: POST to /contx-iq/v1/execute with input_params user_external_id = nico\n- Result: four rows, one per directly connected node (Account 123456, Role customer, Country norway, Company tyrest)\n\nStep 5: Cleanup\n- Action: DELETE the query and policy configurations",
  "graph": {
    "caption": "The graph the example runs on: 9 nodes (2 User, 1 Role, 2 Country, 2 Account, 2 Company) and 7 relationships (PART_OF, WORKS_IN, ASSIGNED_TO, BELONGS_TO). Hover a node for its properties, click it to highlight its neighbourhood.",
    "nodes": [
      {
        "external_id": "nico",
        "type": "User",
        "is_identity": true,
        "properties": [
          {
            "type": "email",
            "value": "nico@email.com"
          }
        ]
      },
      {
        "external_id": "fred",
        "type": "User",
        "is_identity": true,
        "properties": [
          {
            "type": "email",
            "value": "fred@email.com"
          }
        ]
      },
      {
        "external_id": "customer",
        "type": "Role",
        "is_identity": false,
        "properties": [
          {
            "type": "source",
            "value": "Head"
          }
        ]
      },
      {
        "external_id": "norway",
        "type": "Country",
        "is_identity": false,
        "properties": [
          {
            "type": "name",
            "value": "Norway"
          }
        ]
      },
      {
        "external_id": "sweden",
        "type": "Country",
        "is_identity": false,
        "properties": [
          {
            "type": "name",
            "value": "Sweden"
          }
        ]
      },
      {
        "external_id": "123456",
        "type": "Account",
        "is_identity": false,
        "properties": [
          {
            "type": "location",
            "value": "CityHub"
          }
        ]
      },
      {
        "external_id": "234567",
        "type": "Account",
        "is_identity": false,
        "properties": [
          {
            "type": "location",
            "value": "Palace"
          }
        ]
      },
      {
        "external_id": "tyrest",
        "type": "Company",
        "is_identity": false,
        "properties": [
          {
            "type": "name",
            "value": "Tyrest"
          }
        ]
      },
      {
        "external_id": "blue",
        "type": "Company",
        "is_identity": false,
        "properties": [
          {
            "type": "name",
            "value": "Blue"
          }
        ]
      }
    ],
    "relationships": [
      {
        "source": "nico",
        "target": "tyrest",
        "type": "PART_OF",
        "properties": [
          {
            "type": "weight",
            "value": 1
          }
        ]
      },
      {
        "source": "nico",
        "target": "norway",
        "type": "WORKS_IN",
        "properties": []
      },
      {
        "source": "customer",
        "target": "nico",
        "type": "ASSIGNED_TO",
        "properties": []
      },
      {
        "source": "123456",
        "target": "nico",
        "type": "BELONGS_TO",
        "properties": []
      },
      {
        "source": "fred",
        "target": "sweden",
        "type": "WORKS_IN",
        "properties": []
      },
      {
        "source": "customer",
        "target": "fred",
        "type": "ASSIGNED_TO",
        "properties": []
      },
      {
        "source": "234567",
        "target": "fred",
        "type": "BELONGS_TO",
        "properties": []
      }
    ]
  },
  "code": [
    {
      "step": "Step 1",
      "description": "Capture the nodes needed for this use case.",
      "filename": "POST https://eu.api.indykite.com/capture/v1/nodes/",
      "language": "Json",
      "ingest": {
        "nodes": [
          {
            "external_id": "nico",
            "type": "User",
            "is_identity": true,
            "properties": [
              {
                "type": "email",
                "value": "nico@email.com"
              }
            ]
          },
          {
            "external_id": "fred",
            "type": "User",
            "is_identity": true,
            "properties": [
              {
                "type": "email",
                "value": "fred@email.com"
              }
            ]
          },
          {
            "external_id": "customer",
            "type": "Role",
            "properties": [
              {
                "type": "source",
                "value": "Head"
              }
            ]
          },
          {
            "external_id": "norway",
            "type": "Country",
            "properties": [
              {
                "type": "name",
                "value": "Norway"
              }
            ]
          },
          {
            "external_id": "sweden",
            "type": "Country",
            "properties": [
              {
                "type": "name",
                "value": "Sweden"
              }
            ]
          },
          {
            "external_id": "123456",
            "type": "Account",
            "properties": [
              {
                "type": "location",
                "value": "CityHub"
              }
            ]
          },
          {
            "external_id": "234567",
            "type": "Account",
            "properties": [
              {
                "type": "location",
                "value": "Palace"
              }
            ]
          },
          {
            "external_id": "tyrest",
            "type": "Company",
            "properties": [
              {
                "type": "name",
                "value": "Tyrest"
              }
            ]
          },
          {
            "external_id": "blue",
            "type": "Company",
            "properties": [
              {
                "type": "name",
                "value": "Blue"
              }
            ]
          }
        ]
      }
    },
    {
      "description": "Capture the relationships needed for this use case.",
      "filename": "POST https://eu.api.indykite.com/capture/v1/relationships/",
      "language": "Json",
      "ingest": {
        "relationships": [
          {
            "source": {
              "external_id": "nico",
              "type": "User"
            },
            "target": {
              "external_id": "tyrest",
              "type": "Company"
            },
            "type": "PART_OF",
            "properties": [
              {
                "type": "weight",
                "value": 1
              }
            ]
          },
          {
            "source": {
              "external_id": "nico",
              "type": "User"
            },
            "target": {
              "external_id": "norway",
              "type": "Country"
            },
            "type": "WORKS_IN"
          },
          {
            "source": {
              "external_id": "customer",
              "type": "Role"
            },
            "target": {
              "external_id": "nico",
              "type": "User"
            },
            "type": "ASSIGNED_TO"
          },
          {
            "source": {
              "external_id": "123456",
              "type": "Account"
            },
            "target": {
              "external_id": "nico",
              "type": "User"
            },
            "type": "BELONGS_TO"
          },
          {
            "source": {
              "external_id": "fred",
              "type": "User"
            },
            "target": {
              "external_id": "sweden",
              "type": "Country"
            },
            "type": "WORKS_IN"
          },
          {
            "source": {
              "external_id": "customer",
              "type": "Role"
            },
            "target": {
              "external_id": "fred",
              "type": "User"
            },
            "type": "ASSIGNED_TO"
          },
          {
            "source": {
              "external_id": "234567",
              "type": "Account"
            },
            "target": {
              "external_id": "fred",
              "type": "User"
            },
            "type": "BELONGS_TO"
          }
        ]
      }
    },
    {
      "step": "Step 2",
      "description": "Policy which designates the derived query can retrieve all nodes directly related to a User node.",
      "filename": "policy.json",
      "language": "Json",
      "ingest": {
        "meta": {
          "policy_version": "1.0-ciq"
        },
        "subject": {
          "type": "_Application"
        },
        "condition": {
          "cypher": "MATCH (subject:_Application) MATCH (u:User)-[]-(n:Resource)",
          "filter": [
            {
              "app": "app1",
              "operator": "AND",
              "operands": [
                {
                  "attribute": "subject.external_id",
                  "operator": "=",
                  "value": "$_appId"
                },
                {
                  "attribute": "u.external_id",
                  "operator": "=",
                  "value": "$user_external_id"
                }
              ]
            }
          ]
        },
        "allowed_reads": {
          "nodes": [
            "u",
            "u.*",
            "n",
            "n.*"
          ]
        }
      }
    },
    {
      "description": "Request to create a CIQ Policy configuration using REST.",
      "filename": "POST https://eu.api.indykite.com/configs/v1/authorization-policies",
      "language": "Json",
      "ingest": {
        "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 (u:User)-[]-(n:Resource)\",\"filter\":[{\"app\":\"app1\",\"operator\":\"AND\",\"operands\":[{\"attribute\":\"subject.external_id\",\"operator\":\"=\",\"value\":\"$_appId\"},{\"attribute\":\"u.external_id\",\"operator\":\"=\",\"value\":\"$user_external_id\"}]}]},\"allowed_reads\":{\"nodes\":[\"u\",\"u.*\",\"n\",\"n.*\"]}}",
        "status": "ACTIVE",
        "tags": []
      }
    },
    {
      "description": "Request to read the CIQ Policy configuration using REST.",
      "filename": "policy_request.json",
      "language": "Json",
      "ingest": {
        "id": "your_policy_configuration_gid"
      }
    },
    {
      "step": "Step 3",
      "description": "The CIQ Knowledge Query designates the information you want to retrieve. ",
      "filename": "knowledge_query.json",
      "language": "Json",
      "ingest": {
        "nodes": [
          "n.external_id",
          "n.type",
          "n.property.*"
        ]
      }
    },
    {
      "description": "Request to create a CIQ Knowledge Query configuration using REST.",
      "filename": "POST https://eu.api.indykite.com/configs/v1/knowledge-queries",
      "language": "Json",
      "ingest": {
        "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\":[\"n.external_id\",\"n.type\",\"n.property.*\"]}",
        "status": "ACTIVE"
      }
    },
    {
      "description": "Read the CIQ Query Configuration.",
      "filename": "GET https://eu.api.indykite.com/configs/v1/knowledge-queries/{id}",
      "language": "Json",
      "ingest": {
        "id": "your_knowledge_query_configuration_gid"
      }
    },
    {
      "step": "Step 4",
      "description": "CIQ Execution request in json format.",
      "filename": "POST https://eu.api.indykite.com/contx-iq/v1/execute",
      "language": "Json",
      "ingest": {
        "id": "knowledge_query_gid",
        "input_params": {
          "user_external_id": "nico"
        },
        "page_token": 1
      }
    },
    {
      "description": "CIQ Execution response in json format.",
      "filename": "response.json",
      "language": "Json",
      "ingest": {
        "data": [
          {
            "nodes": {
              "n.external_id": "123456",
              "n.property.*": [
                {
                  "type": "location",
                  "value": "CityHub"
                }
              ],
              "n.type": "Account"
            }
          },
          {
            "nodes": {
              "n.external_id": "customer",
              "n.property.*": [
                {
                  "type": "source",
                  "value": "Head"
                }
              ],
              "n.type": "Role"
            }
          },
          {
            "nodes": {
              "n.external_id": "norway",
              "n.property.*": [
                {
                  "type": "name",
                  "value": "Norway"
                }
              ],
              "n.type": "Country"
            }
          },
          {
            "nodes": {
              "n.external_id": "tyrest",
              "n.property.*": [
                {
                  "type": "name",
                  "value": "Tyrest"
                }
              ],
              "n.type": "Company"
            }
          }
        ]
      }
    },
    {
      "step": "Step 5",
      "description": "Delete the CIQ Query.",
      "filename": "DELETE https://eu.api.indykite.com/configs/v1/knowledge-queries/{id}",
      "language": "Json",
      "ingest": {
        "id": "your_knowledge_query_configuration_gid"
      }
    },
    {
      "description": "Delete the CIQ Policy.",
      "filename": "DELETE https://eu.api.indykite.com/configs/v1/authorization-policies/{id}",
      "language": "Json",
      "ingest": {
        "id": "your_policy_configuration_gid"
      }
    }
  ],
  "links": {
    "html": "/resources/ciq-19",
    "markdown": "/resources/ciq-19.md",
    "openApi": "https://openapi.indykite.com/"
  }
}