{
  "id": "authz-4",
  "title": "KBAC: How do I parameterize an authorization decision with input params (max_price)?",
  "description": "Drive authZEN evaluation and resource-search decisions using runtime input_params. The policy condition compares a graph property against $max_price provided at execution time, so the same policy answers different shopping-budget questions per call.",
  "category": "KBAC",
  "tags": [
    "KBAC Policy",
    "authZEN",
    "Input Params",
    "Parameterized Policy",
    "Evaluation",
    "Resource Search",
    "Subject Search"
  ],
  "api": "KBAC",
  "language": "Python",
  "lastUpdated": "2026-07-14",
  "openApiEndpoints": [
    "/configs/v1/authorization-policies",
    "/access/v1/evaluation",
    "/access/v1/search/resource",
    "/access/v1/search/subject"
  ],
  "relatedGuides": [
    "/guides/guide-dynamic-authz",
    "/guides/guide-authzen"
  ],
  "commonErrors": [
    {
      "code": "400",
      "message": "missing input parameter: max_price",
      "solution": "Send context.input_params.max_price on every request. The partial filter cannot resolve without it."
    },
    {
      "code": "401",
      "message": "UNAUTHENTICATED",
      "solution": "Check X-IK-ClientKey contains valid AppAgent credentials."
    }
  ],
  "summary": "This example demonstrates input_params passed through context on authZEN requests.\n\nPolicy condition shape:\nMATCH (subject) MATCH (resource)-[:HAS]->(price:Property {type:'price'})\nWHERE price.value <= $max_price AND NOT (subject)-[:OWNS]->(resource)\n\nTwo things matter:\n1. $max_price is a partial filter - its value is supplied per request via context.input_params.\n2. The NOT clause excludes cars the subject already owns, which keeps the answer truthful for \"what can I buy?\" style questions.\n\nauthZEN endpoints exercised:\n- POST /access/v1/evaluation - \"Can Karel buy KITT under $150,000?\" -> true. Same question under $5,000 -> false.\n- POST /access/v1/search/resource - \"Which cars can Knight Rider buy under $5,000?\" -> [{skodaOctavia}].\n- POST /access/v1/search/subject - \"Who can buy the Skoda Octavia under $5,000?\" -> [knightrider, karel].\n\nPolicy version note: the policy in this example uses \"policy_version\": \"2.0-kbac\". The same policy JSON is also accepted with \"policy_version\": \"3.0-kbac\" (identical schema, raw-Cypher semantics; do not reference $subject_id or external properties). Only 3.0-kbac additionally accepts USE graph.byName() routing and CALL { } subqueries for composite / data-residency IKGs - see resources authz-7 and authz-8.",
  "usecase": "Scenario: A used-car marketplace asks IndyKite \"what can this shopper afford right now?\" with a moving budget cap.\n\nGraph data:\n- Cars carry a HAS -> Property{type:'price'} relationship with the listing price.\n- Subjects OWN the cars they already bought (excluded from CAN_BUY results).\n\nRun the same policy three ways:\n1. evaluation with max_price=150000 -> Karel can buy KITT.\n2. evaluation with max_price=5000 -> Karel cannot buy KITT.\n3. search/resource with max_price=5000 -> only cars under $5,000 come back.\n\nUse this pattern whenever the authorization rule depends on a numeric threshold supplied by the caller - discounts, credit limits, rate-limit budgets, etc.",
  "requirements": "Prerequisites:\n- ServiceAccount credentials: For creating the policy.\n- AppAgent credentials: For evaluations and searches (X-IK-ClientKey).\n- Graph data: Person, Car, and Property{type:'price'} nodes with HAS relationships from each Car to its price Property. OWNS relationships for any cars already owned.\n\nRequired API access:\n- POST /configs/v1/authorization-policies\n- POST /access/v1/evaluation\n- POST /access/v1/search/resource\n- POST /access/v1/search/subject",
  "steps": "Step 1: Capture Graph Data\n- Action: POST Person, Car, Property nodes; HAS and OWNS relationships.\n- Result: Cars priced, owners linked.\n\nStep 2: Create the Parameterized Policy\n- Action: POST a KBAC policy with $max_price in the condition cypher.\n- Result: Policy ID.\n\nStep 3: Evaluate with Different Budgets\n- Action: POST /access/v1/evaluation with context.input_params.max_price set.\n- Result: decision flips based on price vs. budget.\n\nStep 4: Search for Affordable Resources\n- Action: POST /access/v1/search/resource with max_price in context.\n- Result: All cars under the budget that the subject doesn't already own.\n\nStep 5: Reverse Search (Who Can Buy This?)\n- Action: POST /access/v1/search/subject with max_price in context.\n- Result: All Persons who could afford the resource and don't already own it.",
  "graph": {
    "caption": "The graph the example runs on: 5 nodes (2 Person, 3 Car) and 1 relationships (OWNS). Hover a node for its properties, click it to highlight its neighbourhood.",
    "nodes": [
      {
        "external_id": "knightrider",
        "type": "Person",
        "is_identity": true,
        "properties": [
          {
            "type": "email",
            "value": "knightrider@demo.com"
          }
        ]
      },
      {
        "external_id": "karel",
        "type": "Person",
        "is_identity": true,
        "properties": [
          {
            "type": "email",
            "value": "karel@demo.com"
          }
        ]
      },
      {
        "external_id": "kitt",
        "type": "Car",
        "is_identity": false,
        "properties": [
          {
            "type": "manufacturer",
            "value": "Pontiac"
          },
          {
            "type": "model",
            "value": "Firebird"
          },
          {
            "type": "price",
            "value": 100000
          }
        ]
      },
      {
        "external_id": "caddilacv16",
        "type": "Car",
        "is_identity": false,
        "properties": [
          {
            "type": "manufacturer",
            "value": "Cadillac"
          },
          {
            "type": "model",
            "value": "V-16"
          },
          {
            "type": "price",
            "value": 150000
          }
        ]
      },
      {
        "external_id": "skodaOctavia",
        "type": "Car",
        "is_identity": false,
        "properties": [
          {
            "type": "manufacturer",
            "value": "Skoda"
          },
          {
            "type": "model",
            "value": "Octavia"
          },
          {
            "type": "price",
            "value": 4000
          }
        ]
      }
    ],
    "relationships": [
      {
        "source": "knightrider",
        "target": "kitt",
        "type": "OWNS",
        "properties": []
      }
    ]
  },
  "code": [
    {
      "step": "Step 1",
      "description": "Capture Person and Car nodes. Each Car carries a price property (kitt 100000, caddilacv16 150000, skodaOctavia 4000) — captured as an integer so the policy can compare price.value <= $max_price.",
      "filename": "POST https://eu.api.indykite.com/capture/v1/nodes/",
      "language": "Json",
      "ingest": {
        "nodes": [
          {
            "external_id": "knightrider",
            "is_identity": true,
            "type": "Person",
            "properties": [
              {
                "type": "email",
                "value": "knightrider@demo.com"
              }
            ]
          },
          {
            "external_id": "karel",
            "is_identity": true,
            "type": "Person",
            "properties": [
              {
                "type": "email",
                "value": "karel@demo.com"
              }
            ]
          },
          {
            "external_id": "kitt",
            "type": "Car",
            "properties": [
              {
                "type": "manufacturer",
                "value": "Pontiac"
              },
              {
                "type": "model",
                "value": "Firebird"
              },
              {
                "type": "price",
                "value": 100000
              }
            ]
          },
          {
            "external_id": "caddilacv16",
            "type": "Car",
            "properties": [
              {
                "type": "manufacturer",
                "value": "Cadillac"
              },
              {
                "type": "model",
                "value": "V-16"
              },
              {
                "type": "price",
                "value": 150000
              }
            ]
          },
          {
            "external_id": "skodaOctavia",
            "type": "Car",
            "properties": [
              {
                "type": "manufacturer",
                "value": "Skoda"
              },
              {
                "type": "model",
                "value": "Octavia"
              },
              {
                "type": "price",
                "value": 4000
              }
            ]
          }
        ]
      }
    },
    {
      "description": "Capture relationships: knightrider OWNS kitt, which the policy's NOT (subject)-[:OWNS]->(resource) clause uses to exclude cars the subject already owns.",
      "filename": "POST https://eu.api.indykite.com/capture/v1/relationships/",
      "language": "Json",
      "ingest": {
        "relationships": [
          {
            "source": {
              "external_id": "knightrider",
              "type": "Person"
            },
            "target": {
              "external_id": "kitt",
              "type": "Car"
            },
            "type": "OWNS"
          }
        ]
      }
    },
    {
      "step": "Step 2",
      "description": "KBAC policy: CAN_BUY a Car if its price is <= $max_price and the subject does not already own it.",
      "filename": "policy.json",
      "language": "Json",
      "ingest": {
        "meta": {
          "policy_version": "2.0-kbac"
        },
        "subject": {
          "type": "Person"
        },
        "actions": [
          "CAN_BUY"
        ],
        "resource": {
          "type": "Car"
        },
        "condition": {
          "cypher": "MATCH (subject) MATCH (resource)-[:HAS]->(price:Property {type:'price'}) WHERE price.value <= $max_price AND NOT (subject)-[:OWNS]->(resource)"
        }
      }
    },
    {
      "description": "Request to create the policy.",
      "filename": "POST https://eu.api.indykite.com/configs/v1/authorization-policies",
      "language": "Json",
      "ingest": {
        "project_id": "your_project_gid",
        "description": "Authorize CAN_BUY on Car when its price <= input_params.max_price and the subject does not already own it.",
        "display_name": "policy - person can buy car under max_price",
        "name": "policy-person-can-buy-car-max-price",
        "policy": "{\"meta\":{\"policy_version\":\"2.0-kbac\"},\"subject\":{\"type\":\"Person\"},\"actions\":[\"CAN_BUY\"],\"resource\":{\"type\":\"Car\"},\"condition\":{\"cypher\":\"MATCH (subject) MATCH (resource)-[:HAS]->(price:Property {type:'price'}) WHERE price.value <= $max_price AND NOT (subject)-[:OWNS]->(resource)\"}}",
        "status": "ACTIVE",
        "tags": []
      }
    },
    {
      "step": "Step 3",
      "description": "Evaluation: Karel asks if he can buy KITT with budget 150,000. Decision: true.",
      "filename": "POST https://eu.api.indykite.com/access/v1/evaluation",
      "language": "Json",
      "ingest": {
        "subject": {
          "type": "Person",
          "id": "karel"
        },
        "resource": {
          "type": "Car",
          "id": "kitt"
        },
        "action": {
          "name": "CAN_BUY"
        },
        "context": {
          "input_params": {
            "max_price": 150000
          }
        }
      }
    },
    {
      "description": "Response - authorized.",
      "filename": "Response 200",
      "language": "Json",
      "ingest": {
        "decision": true
      }
    },
    {
      "description": "Same call, budget dropped to 5,000. Decision: false.",
      "filename": "POST https://eu.api.indykite.com/access/v1/evaluation",
      "language": "Json",
      "ingest": {
        "subject": {
          "type": "Person",
          "id": "karel"
        },
        "resource": {
          "type": "Car",
          "id": "kitt"
        },
        "action": {
          "name": "CAN_BUY"
        },
        "context": {
          "input_params": {
            "max_price": 5000
          }
        }
      }
    },
    {
      "description": "Response - denied because KITT's price exceeds 5,000.",
      "filename": "Response 200",
      "language": "Json",
      "ingest": {
        "decision": false
      }
    },
    {
      "step": "Step 4",
      "description": "Resource search: which cars can Knight Rider buy under 5,000?",
      "filename": "POST https://eu.api.indykite.com/access/v1/search/resource",
      "language": "Json",
      "ingest": {
        "subject": {
          "type": "Person",
          "id": "knightrider"
        },
        "resource": {
          "type": "Car"
        },
        "action": {
          "name": "CAN_BUY"
        },
        "context": {
          "input_params": {
            "max_price": 5000
          }
        }
      }
    },
    {
      "description": "Response - only the Skoda Octavia fits the budget.",
      "filename": "Response 200",
      "language": "Json",
      "ingest": {
        "results": [
          {
            "type": "Car",
            "id": "skodaOctavia"
          }
        ]
      }
    },
    {
      "description": "Same resource search in Python.",
      "filename": "search_resource.py",
      "language": "Python",
      "code": "\nimport http.client\nimport json\n\nconn = http.client.HTTPSConnection(\"eu.api.indykite.com\")\n\npayload = json.dumps({\n  \"subject\": {\"type\": \"Person\", \"id\": \"knightrider\"},\n  \"resource\": {\"type\": \"Car\"},\n  \"action\": {\"name\": \"CAN_BUY\"},\n  \"context\": {\"input_params\": {\"max_price\": 5000}}\n})\n\nheaders = {\n  'Content-Type': \"application/json\",\n  'X-IK-ClientKey': \"\"\n}\n\nconn.request(\"POST\", \"/access/v1/search/resource\", payload, headers)\n\nres = conn.getresponse()\ndata = res.read()\n"
    },
    {
      "step": "Step 5",
      "description": "Subject search: who can buy the Skoda Octavia under 5,000?",
      "filename": "POST https://eu.api.indykite.com/access/v1/search/subject",
      "language": "Json",
      "ingest": {
        "subject": {
          "type": "Person"
        },
        "resource": {
          "type": "Car",
          "id": "skodaOctavia"
        },
        "action": {
          "name": "CAN_BUY"
        },
        "context": {
          "input_params": {
            "max_price": 5000
          }
        }
      }
    },
    {
      "description": "Response - Persons who can afford it and don't already own it.",
      "filename": "Response 200",
      "language": "Json",
      "ingest": {
        "results": [
          {
            "type": "Person",
            "id": "knightrider"
          },
          {
            "type": "Person",
            "id": "karel"
          }
        ]
      }
    }
  ],
  "links": {
    "html": "/resources/authz-4",
    "markdown": "/resources/authz-4.md",
    "openApi": "https://openapi.indykite.com/"
  }
}