{
  "id": "ciq-14",
  "title": "ContX IQ: How do I query external data sources via Data Resolver?",
  "description": "Demonstrates fetching data from external systems (APIs, databases) during ContX IQ query execution. The External Data Resolver retrieves information not stored in the IKG, combining graph data with real-time external lookups.",
  "category": "ContX IQ",
  "tags": [
    "ContX IQ Policy",
    "ContX IQ Query",
    "External Data",
    "Data Resolver",
    "API Integration",
    "VIN Lookup",
    "Hybrid Data"
  ],
  "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 demonstrates External Data Resolver integration:\n\nWhat is an External Data Resolver?\nA configuration that fetches data from external systems (APIs, databases) during query execution.\n\nUse case: one vehicle's VIN is served by an external system, not stored in the IKG.\n\nFlow:\n1. The vin property of Vehicle car1 is captured with external_value naming the resolver (externalDataResolverForCIQName) instead of a value\n2. The query requests vehicle.property.vin\n3. When the read reaches car1, the External Data Resolver calls the configured URL and applies the response_selector\n4. The query returns the IKG data together with the resolved VIN\n\nBenefits:\n- Keep sensitive data in external systems\n- Real-time data lookups\n- Reduce data duplication\n- Maintain single source of truth",
  "usecase": "Scenario: A car rental app needs to display vehicle VIN numbers, but VINs are stored in a separate vehicle registry system.\n\nGraph in IKG:\nCompany(companyParking) -[OFFERS]-> Contract(ct123) <-[ACCEPTED]- Person(alice) -[HAS]-> PaymentMethod(cb123); Contract(ct123) -[COVERS]-> Vehicle(car1) -[HAS]-> LicenseNumber(license1)\nCompany(companyParking) -[OFFERS]-> Contract(ct234) <-[ACCEPTED]- Person(bob) -[HAS]-> PaymentMethod(kl123); Contract(ct234) -[COVERS]-> Vehicle(car2) -[HAS]-> LicenseNumber(license2)\nVehicle(car1) has: category = \"Car\", vin = external_value \"externalDataResolverForCIQName\" (a data reference to the resolver)\nVehicle(car2) has: category = \"Car\", vin = \"rtfhcnvjt471\" (plain value)\n\nExternal Data Resolver:\nGET https://whateverUrlWithExternalValue/magic?data=vinmagic, response_selector \".echo\" -> \"vinmagic\"\n\nQuery execution:\n1. The user requests vehicle details with their token\n2. The policy walks Company -[OFFERS]-> Contract <-[ACCEPTED]- subject -[HAS]-> PaymentMethod and Contract -[COVERS]-> Vehicle -[HAS]-> LicenseNumber, bound to the token's sub claim\n3. The query reads vehicle, vehicle.property.category and vehicle.property.vin\n4. For car1 the vin is a data reference, so the resolver is called and the selected field is returned\n5. Recorded response (alice's token; her contract ct123 covers car1): vehicle car1, category \"Car\", vin \"vinmagic\"\n\nThe VIN never needs to be stored in the IKG - it's fetched at read time.",
  "requirements": "Prerequisites:\n- ServiceAccount credentials: For configuration and policy creation (Bearer token)\n- AppAgent credentials: For data ingestion and query execution (X-IK-ClientKey)\n- User access token: for the Person executing the query (alice in the recorded response; her contract ct123 covers car1)\n- External API access: The resolver endpoint must be accessible\n\nExternal Data Resolver setup:\n- Configured via POST /configs/v1/external-data-resolvers\n- Defines the url, method, headers, request/response content types and the response_selector\n- In this example, returns mock data: vin=\"vinmagic\"",
  "steps": "Step 1: Create External Data Resolver Configuration\n- Authentication: ServiceAccount credential (Bearer token)\n- Action: POST to /configs/v1/external-data-resolvers\n- Configuration includes:\n  - url: https://whateverUrlWithExternalValue/magic?data=vinmagic, method GET, no headers\n  - request_content_type and response_content_type JSON\n  - response_selector \".echo\" (how to extract the VIN from the response)\n- Result: Resolver ID returned\n\nStep 2: Ingest Nodes with Data References\n- Authentication: AppAgent credential (X-IK-ClientKey header)\n- Action: POST Person, PaymentMethod, Contract, Vehicle, LicenseNumber and Company nodes, then the HAS, ACCEPTED, COVERS and OFFERS relationships\n- Key detail: the vin property of Vehicle car1 is captured with external_value instead of value\n- Format: {\"type\": \"vin\", \"external_value\": \"externalDataResolverForCIQName\"} (the resolver's name)\n- Result: Graph ready with an external data reference on car1\n\nStep 3: Create Policy for External Data Access\n- Authentication: ServiceAccount credential (Bearer token)\n- Action: POST policy with subject type Person, filter subject.external_id = $token.sub, cypher Company -[OFFERS]-> Contract <-[ACCEPTED]- subject -[HAS]-> PaymentMethod, Contract -[COVERS]-> Vehicle -[HAS]-> LicenseNumber, allowing:\n  - READ on vehicle, ln, vehicle.* and ln.*\n- Result: Policy ID returned\n\nStep 4: Create Query Returning External Data\n- Authentication: ServiceAccount credential (Bearer token)\n- Action: POST query that returns vehicle, vehicle.property.category (IKG) and vehicle.property.vin (resolved for car1)\n- The query engine resolves external_value properties when they are read\n- Result: Query ID returned\n\nStep 5: Execute Query as Authorized User\n- Authentication: AppAgent credential + User token (Bearer header)\n- Action: POST to /contx-iq/v1/execute with empty input_params, as alice\n- Result: the vehicle covered by the caller's contract (car1), its category and its VIN \"vinmagic\" from the resolver",
  "graph": {
    "caption": "The graph the example runs on: 11 nodes (2 Person, 2 PaymentMethod, 2 Contract, 2 Vehicle, 2 LicenseNumber, 1 Company) and 10 relationships (HAS, ACCEPTED, COVERS, OFFERS). Hover a node for its properties, click it to highlight its neighbourhood.",
    "nodes": [
      {
        "external_id": "alice",
        "type": "Person",
        "is_identity": true,
        "properties": [
          {
            "type": "email",
            "value": "alice@email.com"
          },
          {
            "type": "given_name",
            "value": "Alice"
          },
          {
            "type": "last_name",
            "value": "Smith"
          }
        ]
      },
      {
        "external_id": "bob",
        "type": "Person",
        "is_identity": true,
        "properties": [
          {
            "type": "email",
            "value": "bob@email.com"
          },
          {
            "type": "given_name",
            "value": "Bob"
          }
        ]
      },
      {
        "external_id": "cb123",
        "type": "PaymentMethod",
        "is_identity": false,
        "properties": [
          {
            "type": "payment_name",
            "value": "Credit Card"
          }
        ]
      },
      {
        "external_id": "kl123",
        "type": "PaymentMethod",
        "is_identity": false,
        "properties": [
          {
            "type": "payment_name",
            "value": "Klarna"
          }
        ]
      },
      {
        "external_id": "ct123",
        "type": "Contract",
        "is_identity": false,
        "properties": [
          {
            "type": "category",
            "value": "Parking"
          },
          {
            "type": "status",
            "value": "Active"
          }
        ]
      },
      {
        "external_id": "ct234",
        "type": "Contract",
        "is_identity": false,
        "properties": [
          {
            "type": "category",
            "value": "Parking"
          },
          {
            "type": "status",
            "value": "Active"
          }
        ]
      },
      {
        "external_id": "car1",
        "type": "Vehicle",
        "is_identity": false,
        "properties": [
          {
            "type": "category",
            "value": "Car"
          },
          {
            "type": "is_active",
            "value": true
          },
          {
            "type": "vin",
            "value": "resolver: externalDataResolverForCIQName"
          }
        ]
      },
      {
        "external_id": "car2",
        "type": "Vehicle",
        "is_identity": false,
        "properties": [
          {
            "type": "category",
            "value": "Car"
          },
          {
            "type": "is_active",
            "value": true
          },
          {
            "type": "vin",
            "value": "rtfhcnvjt471"
          }
        ]
      },
      {
        "external_id": "license1",
        "type": "LicenseNumber",
        "is_identity": false,
        "properties": [
          {
            "type": "status",
            "value": "Active"
          },
          {
            "type": "number",
            "value": "AX123456"
          }
        ]
      },
      {
        "external_id": "license2",
        "type": "LicenseNumber",
        "is_identity": false,
        "properties": [
          {
            "type": "status",
            "value": "Active"
          },
          {
            "type": "number",
            "value": "OL123456"
          }
        ]
      },
      {
        "external_id": "companyParking",
        "type": "Company",
        "is_identity": false,
        "properties": [
          {
            "type": "name",
            "value": "City Parking Inc"
          }
        ]
      }
    ],
    "relationships": [
      {
        "source": "bob",
        "target": "kl123",
        "type": "HAS",
        "properties": []
      },
      {
        "source": "alice",
        "target": "cb123",
        "type": "HAS",
        "properties": []
      },
      {
        "source": "alice",
        "target": "ct123",
        "type": "ACCEPTED",
        "properties": []
      },
      {
        "source": "bob",
        "target": "ct234",
        "type": "ACCEPTED",
        "properties": []
      },
      {
        "source": "ct123",
        "target": "car1",
        "type": "COVERS",
        "properties": []
      },
      {
        "source": "ct234",
        "target": "car2",
        "type": "COVERS",
        "properties": []
      },
      {
        "source": "car1",
        "target": "license1",
        "type": "HAS",
        "properties": []
      },
      {
        "source": "car2",
        "target": "license2",
        "type": "HAS",
        "properties": []
      },
      {
        "source": "companyParking",
        "target": "ct234",
        "type": "OFFERS",
        "properties": []
      },
      {
        "source": "companyParking",
        "target": "ct123",
        "type": "OFFERS",
        "properties": []
      }
    ]
  },
  "code": [
    {
      "step": "Step 1",
      "description": "Create an External Data Resolver which configures the data to retrieve. In this use case, the configuration always returns \"vinmagic\" as a vin value. ",
      "filename": "POST https://eu.api.indykite.com/configs/v1/external-data-resolvers",
      "language": "Json",
      "ingest": {
        "project_id": "your_project_gid",
        "description": "description of external data reference",
        "display_name": "external data name",
        "name": "externalDataResolverForCIQName",
        "headers": {},
        "method": "GET",
        "request_content_type": "JSON",
        "request_payload": "",
        "response_content_type": "JSON",
        "response_selector": ".echo",
        "url": "https://whateverUrlWithExternalValue/magic?data=vinmagic"
      }
    },
    {
      "step": "Step 2",
      "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": "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": "bob",
            "type": "Person",
            "is_identity": true,
            "properties": [
              {
                "type": "email",
                "value": "bob@email.com"
              },
              {
                "type": "given_name",
                "value": "Bob"
              }
            ]
          },
          {
            "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": "Parking"
              },
              {
                "type": "status",
                "value": "Active"
              }
            ]
          },
          {
            "external_id": "ct234",
            "type": "Contract",
            "properties": [
              {
                "type": "category",
                "value": "Parking"
              },
              {
                "type": "status",
                "value": "Active"
              }
            ]
          },
          {
            "external_id": "car1",
            "type": "Vehicle",
            "properties": [
              {
                "type": "category",
                "value": "Car"
              },
              {
                "type": "is_active",
                "value": true
              },
              {
                "type": "vin",
                "external_value": "externalDataResolverForCIQName"
              }
            ]
          },
          {
            "external_id": "car2",
            "type": "Vehicle",
            "properties": [
              {
                "type": "category",
                "value": "Car"
              },
              {
                "type": "is_active",
                "value": true
              },
              {
                "type": "vin",
                "value": "rtfhcnvjt471"
              }
            ]
          },
          {
            "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": "companyParking",
            "type": "Company",
            "properties": [
              {
                "type": "name",
                "value": "City Parking Inc"
              }
            ]
          }
        ]
      }
    },
    {
      "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": "bob",
              "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": "alice",
              "type": "Person"
            },
            "target": {
              "external_id": "ct123",
              "type": "Contract"
            },
            "type": "ACCEPTED"
          },
          {
            "source": {
              "external_id": "bob",
              "type": "Person"
            },
            "target": {
              "external_id": "ct234",
              "type": "Contract"
            },
            "type": "ACCEPTED"
          },
          {
            "source": {
              "external_id": "ct123",
              "type": "Contract"
            },
            "target": {
              "external_id": "car1",
              "type": "Vehicle"
            },
            "type": "COVERS"
          },
          {
            "source": {
              "external_id": "ct234",
              "type": "Contract"
            },
            "target": {
              "external_id": "car2",
              "type": "Vehicle"
            },
            "type": "COVERS"
          },
          {
            "source": {
              "external_id": "car1",
              "type": "Vehicle"
            },
            "target": {
              "external_id": "license1",
              "type": "LicenseNumber"
            },
            "type": "HAS"
          },
          {
            "source": {
              "external_id": "car2",
              "type": "Vehicle"
            },
            "target": {
              "external_id": "license2",
              "type": "LicenseNumber"
            },
            "type": "HAS"
          },
          {
            "source": {
              "external_id": "companyParking",
              "type": "Company"
            },
            "target": {
              "external_id": "ct234",
              "type": "Contract"
            },
            "type": "OFFERS"
          },
          {
            "source": {
              "external_id": "companyParking",
              "type": "Company"
            },
            "target": {
              "external_id": "ct123",
              "type": "Contract"
            },
            "type": "OFFERS"
          }
        ]
      }
    },
    {
      "step": "Step 3",
      "description": "Create a CIQ Policy which designates the data to retrieve. ",
      "filename": "policy.json",
      "language": "Json",
      "ingest": {
        "meta": {
          "policy_version": "1.0-ciq"
        },
        "subject": {
          "type": "Person"
        },
        "condition": {
          "cypher": "MATCH (company:Company)-[:OFFERS]->(contract:Contract)<-[:ACCEPTED]-(subject:Person)-[:HAS]->(payment:PaymentMethod), (contract)-[:COVERS]->(vehicle:Vehicle)-[:HAS]->(ln:LicenseNumber)",
          "filter": [
            {
              "attribute": "subject.external_id",
              "operator": "=",
              "value": "$token.sub"
            }
          ]
        },
        "allowed_reads": {
          "nodes": [
            "vehicle",
            "ln",
            "vehicle.*",
            "ln.*"
          ]
        }
      }
    },
    {
      "description": "Request to create the 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\":\"Person\"},\"condition\":{\"cypher\":\"MATCH (company:Company)-[:OFFERS]->(contract:Contract)<-[:ACCEPTED]-(subject:Person)-[:HAS]->(payment:PaymentMethod), (contract)-[:COVERS]->(vehicle:Vehicle)-[:HAS]->(ln:LicenseNumber)\",\"filter\":[{\"attribute\":\"subject.external_id\",\"operator\":\"=\",\"value\":\"$token.sub\"}]},\"allowed_reads\":{\"nodes\":[\"vehicle\",\"ln\",\"vehicle.*\",\"ln.*\"]}}",
        "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 4",
      "description": "Create a CIQ Query in the context of the policy to retrieve the vehicle category and the vehicle vin. ",
      "filename": "knowledge_query.json",
      "language": "Json",
      "ingest": {
        "nodes": [
          "vehicle",
          "vehicle.property.category",
          "vehicle.property.vin"
        ]
      }
    },
    {
      "description": "Request to create a CIQ 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\":[\"vehicle\",\"vehicle.property.category\",\"vehicle.property.vin\"]}",
        "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 5",
      "description": "Run a CIQ Execution  to actually retrieve the data, from the Person access token.  ",
      "filename": "POST https://eu.api.indykite.com/contx-iq/v1/execute",
      "language": "Json",
      "ingest": {
        "id": "knowledge_query_gid",
        "input_params": {},
        "page_token": 1
      }
    },
    {
      "description": "CIQ Execution response.",
      "filename": "response.json",
      "language": "Json",
      "ingest": {
        "data": [
          {
            "nodes": {
              "vehicle": {
                "Id": 9,
                "ElementId": "4:a5c213aa-aa4b-4be5-a17a-a677a80ee634:9",
                "Labels": [
                  "Unique",
                  "Resource",
                  "Vehicle"
                ],
                "Props": {
                  "_service": "capture-api",
                  "create_time": "2025-07-28T13:47:58.062Z",
                  "external_id": "car1",
                  "id": "sF_yDttqSKi_oUwiv7OSww",
                  "type": "Vehicle",
                  "update_time": "2025-07-28T13:47:58.062Z"
                }
              },
              "vehicle.property.category": "Car",
              "vehicle.property.vin": "vinmagic"
            }
          }
        ]
      }
    }
  ],
  "links": {
    "html": "/resources/ciq-14",
    "markdown": "/resources/ciq-14.md",
    "openApi": "https://openapi.indykite.com/"
  }
}