{
  "id": "ciq-4",
  "title": "ContX IQ: How do I create nodes and relationships with an authorized write query?",
  "description": "Demonstrates how to create new Contract nodes and relationships (COVERS, ACCEPTED) through an authorized ContX IQ write query. The Application can only create contracts for vehicles owned by companies it has agreements with.",
  "category": "ContX IQ",
  "tags": [
    "ContX IQ Policy",
    "ContX IQ Query",
    "ContX IQ Execution",
    "Write Operations",
    "Node Creation",
    "Relationship Creation"
  ],
  "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 authorized WRITE operations in ContX IQ:\n\nPhase 1 - Link Application to Company:\n1. Create policy allowing _Application to create HAS_AGREEMENT_WITH relationships\n2. Execute query to link Application to Company1\n\nPhase 2 - Create Contract with Relationships:\n3. Create policy allowing Contract node creation and COVERS/ACCEPTED relationships\n4. Execute write query with parameters to create:\n   - New Contract node (with parameterized external_id and number)\n   - COVERS relationship: Contract -> Vehicle\n   - ACCEPTED relationship: Person -> Contract\n\nAuthorization constraint: The Application can only create contracts for vehicles owned by companies it has an agreement with.",
  "usecase": "Scenario: Your application needs to create new rental contracts programmatically.\n\nBusiness rule: Contracts can only be created for vehicles owned by companies your application has agreements with.\n\nWrite operations performed:\n1. CREATE Contract node (with properties: external_id, number)\n2. CREATE COVERS relationship (Contract -> Vehicle)\n3. CREATE ACCEPTED relationship (Person -> Contract)\n\nGraph change:\nBefore: Person(ryan) and Vehicle(car2) exist; Company(company1) -[OWNS]-> Vehicle(car2); the Application -[HAS_AGREEMENT_WITH]-> Company(company1)\nAfter: Person(ryan) -[ACCEPTED]-> Contract(ct853) -[COVERS]-> Vehicle(car2)\n\nKey feature: The external_id and number for the Contract are passed as input parameters at execution time ($contract_external_id, $contractNumber); the vehicle and the person are selected by the policy filter ($vehicleID, $personID).",
  "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\nRequired API access:\n- POST /capture/v1/nodes/ and /capture/v1/relationships/ (initial data)\n- POST /configs/v1/authorization-policies (create policies)\n- POST /configs/v1/knowledge-queries (create queries)\n- POST /contx-iq/v1/execute (run queries)",
  "steps": "Step 1: Ingest Initial Graph Data\n- Authentication: AppAgent credential (X-IK-ClientKey header)\n- Action: POST nodes (Person, Vehicle, Company) and relationships\n- Result: Base graph structure ready for contract creation\n\nStep 2: Create Application Linking Policy\n- Authentication: ServiceAccount credential (Bearer token)\n- Action: POST policy with subject type _Application, filter subject.external_id = $_appId AND company.external_id = $companyID, allowing _Application to upsert HAS_AGREEMENT_WITH relationships to Company\n- Result: Policy ID returned\n\nStep 3: Create Application Linking Query\n- Authentication: ServiceAccount credential (Bearer token)\n- Action: POST write query that upserts the subject -[HAS_AGREEMENT_WITH]-> company relationship\n- Result: Query ID returned\n\nStep 4: Execute Application Linking\n- Authentication: AppAgent credential (X-IK-ClientKey header)\n- Action: Execute the linking query with input_params companyID = company1\n- Result: _Application -[HAS_AGREEMENT_WITH]-> Company(company1) created\n\nStep 5: Create Contract Write Policy\n- Authentication: ServiceAccount credential (Bearer token)\n- Action: POST policy whose cypher walks subject -[HAS_AGREEMENT_WITH]-> company -[OWNS]-> vehicle and matches a person, with filter $_appId AND vehicle.external_id = $vehicleID AND person.external_id = $personID, and allowed_upserts defining:\n  - allowed_upserts.nodes: Can create Contract nodes\n  - allowed_upserts.relationships: Can create COVERS (Contract -> Vehicle) and ACCEPTED (Person -> Contract) relationships\n- Result: Policy ID returned\n\nStep 6: Create Contract Write Query\n- Authentication: ServiceAccount credential (Bearer token)\n- Action: POST parameterized query that upserts the Contract node (properties number = $contractNumber and status = \"Active\") and the COVERS and ACCEPTED relationships\n- Parameters: $contract_external_id, $contractNumber (query), $vehicleID, $personID (policy filter)\n- Result: Query ID returned\n\nStep 7: Execute Contract Creation\n- Authentication: AppAgent credential (X-IK-ClientKey header)\n- Action: Execute with input_params vehicleID = car2, personID = ryan, contract_external_id = ct853, contractNumber = rbjh853\n- Result: Contract(ct853) created, with Contract(ct853) -[COVERS]-> Vehicle(car2) and Person(ryan) -[ACCEPTED]-> Contract(ct853); the response returns contract.external_id and contract.property.number\n\nStep 8: Cleanup\n- Action: DELETE queries and policies",
  "graph": {
    "caption": "The graph the example runs on: 18 nodes (3 Person, 2 PaymentMethod, 3 Contract, 3 Vehicle, 3 LicenseNumber, 2 Company, 2 Application) and 17 relationships (HAS, ACCEPTED, COVERS, OWNS, HAS_AGREEMENT_WITH). 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": "ryan",
        "type": "Person",
        "is_identity": true,
        "properties": [
          {
            "type": "email",
            "value": "ryan@yahoo.co.uk"
          },
          {
            "type": "given_name",
            "value": "ryan"
          },
          {
            "type": "last_name",
            "value": "mushu"
          }
        ]
      },
      {
        "external_id": "tilda",
        "type": "Person",
        "is_identity": true,
        "properties": [
          {
            "type": "email",
            "value": "tilda@yahoo.co.uk"
          },
          {
            "type": "given_name",
            "value": "tilda"
          },
          {
            "type": "last_name",
            "value": "mushu"
          }
        ]
      },
      {
        "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": "Insurance"
          },
          {
            "type": "status",
            "value": "Active"
          },
          {
            "type": "number",
            "value": "hfgrten123"
          }
        ]
      },
      {
        "external_id": "ct234",
        "type": "Contract",
        "is_identity": false,
        "properties": [
          {
            "type": "category",
            "value": "Insurance"
          },
          {
            "type": "status",
            "value": "Active"
          },
          {
            "type": "number",
            "value": "hfgrten234"
          }
        ]
      },
      {
        "external_id": "ct985",
        "type": "Contract",
        "is_identity": false,
        "properties": [
          {
            "type": "category",
            "value": "Insurance"
          },
          {
            "type": "status",
            "value": "Active"
          },
          {
            "type": "number",
            "value": "hfgrten985"
          }
        ]
      },
      {
        "external_id": "car1",
        "type": "Vehicle",
        "is_identity": false,
        "properties": [
          {
            "type": "category",
            "value": "Car"
          },
          {
            "type": "is_active",
            "value": true
          },
          {
            "type": "vin",
            "value": "rtfhcnvjt471"
          }
        ]
      },
      {
        "external_id": "car2",
        "type": "Vehicle",
        "is_identity": false,
        "properties": [
          {
            "type": "category",
            "value": "Car"
          },
          {
            "type": "is_active",
            "value": true
          },
          {
            "type": "vin",
            "value": "kdcbfrt178"
          }
        ]
      },
      {
        "external_id": "truck1",
        "type": "Vehicle",
        "is_identity": false,
        "properties": [
          {
            "type": "category",
            "value": "Truck"
          },
          {
            "type": "is_active",
            "value": true
          },
          {
            "type": "vin",
            "value": "sncnrkcldp"
          }
        ]
      },
      {
        "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": "license3",
        "type": "LicenseNumber",
        "is_identity": false,
        "properties": [
          {
            "type": "status",
            "value": "Active"
          },
          {
            "type": "number",
            "value": "VN123456"
          }
        ]
      },
      {
        "external_id": "company1",
        "type": "Company",
        "is_identity": false,
        "properties": [
          {
            "type": "name",
            "value": "Company1"
          },
          {
            "type": "registration",
            "value": "256314523"
          }
        ]
      },
      {
        "external_id": "company2",
        "type": "Company",
        "is_identity": false,
        "properties": [
          {
            "type": "name",
            "value": "Company2"
          },
          {
            "type": "registration",
            "value": "942365123"
          }
        ]
      },
      {
        "external_id": "application1",
        "type": "Application",
        "is_identity": false,
        "properties": [
          {
            "type": "name",
            "value": "Application"
          }
        ]
      },
      {
        "external_id": "application2",
        "type": "Application",
        "is_identity": false,
        "properties": [
          {
            "type": "name",
            "value": "Application2"
          }
        ]
      }
    ],
    "relationships": [
      {
        "source": "ryan",
        "target": "cb123",
        "type": "HAS",
        "properties": []
      },
      {
        "source": "tilda",
        "target": "kl123",
        "type": "HAS",
        "properties": []
      },
      {
        "source": "alice",
        "target": "cb123",
        "type": "HAS",
        "properties": []
      },
      {
        "source": "ryan",
        "target": "ct123",
        "type": "ACCEPTED",
        "properties": []
      },
      {
        "source": "tilda",
        "target": "ct234",
        "type": "ACCEPTED",
        "properties": []
      },
      {
        "source": "alice",
        "target": "ct985",
        "type": "ACCEPTED",
        "properties": []
      },
      {
        "source": "ct123",
        "target": "car1",
        "type": "COVERS",
        "properties": []
      },
      {
        "source": "ct985",
        "target": "car1",
        "type": "COVERS",
        "properties": []
      },
      {
        "source": "ct234",
        "target": "truck1",
        "type": "COVERS",
        "properties": []
      },
      {
        "source": "car1",
        "target": "license1",
        "type": "HAS",
        "properties": []
      },
      {
        "source": "truck1",
        "target": "license2",
        "type": "HAS",
        "properties": []
      },
      {
        "source": "car2",
        "target": "license3",
        "type": "HAS",
        "properties": []
      },
      {
        "source": "company1",
        "target": "car1",
        "type": "OWNS",
        "properties": []
      },
      {
        "source": "company1",
        "target": "car2",
        "type": "OWNS",
        "properties": []
      },
      {
        "source": "company1",
        "target": "truck1",
        "type": "OWNS",
        "properties": []
      },
      {
        "source": "application1",
        "target": "company1",
        "type": "HAS_AGREEMENT_WITH",
        "properties": []
      },
      {
        "source": "application2",
        "target": "company1",
        "type": "HAS_AGREEMENT_WITH",
        "properties": []
      }
    ]
  },
  "code": [
    {
      "step": "Step 1a",
      "description": "Capture base nodes: Person, Company, Vehicle, LicenseNumber. These will be linked by the contract created later.",
      "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": "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"
              }
            ]
          }
        ]
      }
    },
    {
      "step": "Step 1b",
      "description": "Capture initial relationships (Company OWNS Vehicle, Vehicle HAS LicenseNumber).",
      "filename": "POST https://eu.api.indykite.com/capture/v1/relationships/",
      "language": "Json",
      "ingest": {
        "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": "Step 2a",
      "description": "Policy JSON allowing _Application to CREATE HAS_AGREEMENT_WITH relationships to Company nodes.",
      "filename": "policy.json",
      "language": "Json",
      "ingest": {
        "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.*"
          ]
        }
      }
    },
    {
      "step": "Step 2b",
      "description": "POST request to create the application linking policy.",
      "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 (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": []
      }
    },
    {
      "step": "Step 2c",
      "description": "GET request to verify the policy was created.",
      "filename": "GET https://eu.api.indykite.com/configs/v1/authorization-policies/{policy_id}",
      "language": "Json",
      "ingest": {
        "id": "your_policy_configuration_gid"
      }
    },
    {
      "step": "Step 3a",
      "description": "Write query JSON that creates _Application -[HAS_AGREEMENT_WITH]-> Company relationship.",
      "filename": "knowledge_query.json",
      "language": "Json",
      "ingest": {
        "nodes": [
          "subject.external_id"
        ],
        "relationships": [
          "r1"
        ],
        "upsert_relationships": [
          {
            "name": "r1",
            "source": "subject",
            "target": "company",
            "type": "HAS_AGREEMENT_WITH"
          }
        ]
      }
    },
    {
      "step": "Step 3b",
      "description": "POST request to create the application linking query.",
      "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\":[\"subject.external_id\"],\"relationships\":[\"r1\"],\"upsert_relationships\":[{\"name\":\"r1\",\"source\":\"subject\",\"target\":\"company\",\"type\":\"HAS_AGREEMENT_WITH\"}]}",
        "status": "ACTIVE"
      }
    },
    {
      "step": "Step 3c",
      "description": "GET request to verify the query was created.",
      "filename": "GET https://eu.api.indykite.com/configs/v1/knowledge-queries/{query_id}",
      "language": "Json",
      "ingest": {
        "id": "your_knowledge_query_configuration_gid"
      }
    },
    {
      "step": "Step 4a",
      "description": "Execute the linking query. Creates the relationship in the graph.",
      "filename": "POST https://eu.api.indykite.com/contx-iq/v1/execute",
      "language": "Json",
      "ingest": {
        "id": "ciq_query_gid",
        "input_params": {
          "companyID": "company1"
        }
      }
    },
    {
      "step": "Step 4b",
      "description": "Response confirming the HAS_AGREEMENT_WITH relationship was created.",
      "filename": "response.json",
      "language": "Json",
      "ingest": {
        "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": "Step 5a",
      "description": "Policy JSON with allowed_upserts section defining: (1) Can CREATE Contract nodes, (2) Can CREATE COVERS relationships between Contract and Vehicle, (3) Can CREATE ACCEPTED relationships between Person and Contract.",
      "filename": "policy.json",
      "language": "Json",
      "ingest": {
        "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": []
        }
      }
    },
    {
      "step": "Step 5b",
      "description": "POST request to create the contract write policy.",
      "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)-[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": []
      }
    },
    {
      "step": "Step 5c",
      "description": "GET request to verify the policy was created.",
      "filename": "GET https://eu.api.indykite.com/configs/v1/authorization-policies/{policy_id}",
      "language": "Json",
      "ingest": {
        "id": "your_policy_configuration_gid"
      }
    },
    {
      "step": "Step 6a",
      "description": "Parameterized write query JSON. Uses $contract_external_id and $contractNumber variables for the Contract node. At execution time, actual values replace these placeholders.",
      "filename": "knowledge_query.json",
      "language": "Json",
      "ingest": {
        "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"
          }
        ]
      }
    },
    {
      "step": "Step 6b",
      "description": "POST request to create the contract write query.",
      "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\":[\"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"
      }
    },
    {
      "step": "Step 6c",
      "description": "GET request to verify the query was created.",
      "filename": "GET https://eu.api.indykite.com/configs/v1/knowledge-queries/{query_id}",
      "language": "Json",
      "ingest": {
        "id": "your_knowledge_query_configuration_gid"
      }
    },
    {
      "step": "Step 7a",
      "description": "Execute the write query with parameter values. Creates: (1) Contract node with specified ID and number, (2) COVERS relationship to Vehicle, (3) ACCEPTED relationship from Person.",
      "filename": "POST https://eu.api.indykite.com/contx-iq/v1/execute",
      "language": "Json",
      "ingest": {
        "id": "knowledge_query_gid",
        "input_params": {
          "vehicleID": "car2",
          "personID": "ryan",
          "contract_external_id": "ct853",
          "contractNumber": "rbjh853"
        }
      }
    },
    {
      "step": "Step 7b",
      "description": "Response confirming the Contract node and relationships were created.",
      "filename": "response.json",
      "language": "Json",
      "ingest": {
        "data": [
          {
            "nodes": {
              "contract.external_id": "ct853",
              "contract.property.number": "rbjh853"
            }
          }
        ]
      }
    },
    {
      "step": "Step 8a",
      "description": "DELETE request to remove the queries.",
      "filename": "DELETE https://eu.api.indykite.com/configs/v1/knowledge-queries/{query_id}",
      "language": "Json",
      "ingest": {
        "id": "your_knowledge_query_configuration_gid"
      }
    },
    {
      "step": "Step 8b",
      "description": "DELETE request to remove the policies. Note: The created Contract node and relationships remain in the graph.",
      "filename": "DELETE https://eu.api.indykite.com/configs/v1/authorization-policies/{policy_id}",
      "language": "Json",
      "ingest": {
        "id": "your_policy_configuration_gid"
      }
    }
  ],
  "links": {
    "html": "/resources/ciq-4",
    "markdown": "/resources/ciq-4.md",
    "openApi": "https://openapi.indykite.com/"
  }
}