{
  "id": "authz-2",
  "title": "KBAC: Batch Authorization with Multiple Evaluations (Boxcarring)",
  "description": "Evaluate multiple authorization decisions in a single API call using the authZEN Access Evaluations endpoint. This pattern, known as 'boxcarring', reduces network overhead when checking many permissions at once.",
  "category": "KBAC",
  "tags": [
    "KBAC Policy",
    "authZEN",
    "Batch Evaluation",
    "Boxcarring",
    "Multi-Evaluation",
    "Performance Optimization"
  ],
  "api": "KBAC",
  "language": "Python",
  "lastUpdated": "2026-07-14",
  "openApiEndpoints": [
    "/capture/v1/nodes",
    "/capture/v1/relationships",
    "/configs/v1/authorization-policies",
    "/access/v1/evaluations"
  ],
  "relatedGuides": [
    "/guides/guide-authzen",
    "/guides/guide-dynamic-authz",
    "/guides/guide-sandbox"
  ],
  "commonErrors": [
    {
      "code": "401",
      "message": "UNAUTHENTICATED",
      "solution": "Check X-IK-ClientKey header contains valid AppAgent credentials"
    },
    {
      "code": "404",
      "message": "NOT_FOUND",
      "solution": "Verify the policy exists and the subject/resource nodes exist in the IKG"
    }
  ],
  "summary": "This example demonstrates batch authorization using the authZEN Access Evaluations API:\n\nWhat is boxcarring?\nMultiple authorization questions combined into a single API request, reducing network round-trips.\n\nExample batch request:\n- \"Can knightrider drive kitt?\"\n- \"Can knightrider drive cadillacv16?\"\n- \"Can karel ride harmonika?\"\n- \"Can karel drive harmonika?\"\nAll answered in ONE API call.\n\nAPI reference: https://openid.net/specs/authorization-api-1_0-03.html#name-access-evaluations-api\n\nRequest structure:\n- Default subject/action can be set at the top level\n- Each evaluation in the array can override defaults\n- Response contains decision for each evaluation in order\n\nPolicy version note: the policies in this example use \"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 transportation app needs to check multiple permissions when a user opens the app.\n\nGraph (same dataset as authz-1):\n- knightrider -[DRIVES]-> kitt, satchmo -[DRIVES]-> cadillacv16, alice -[DRIVES]-> cadillacv16\n- karel -[HAS]-> listek (Ticket) -[FOR]-> harmonika (Bus)\n\nPolicies defined:\n1. CAN_DRIVE policy: Person can drive a Car if a DRIVES relationship exists\n2. CAN_RIDE policy: Person can ride a Bus if the Person HAS a Ticket FOR that Bus\n\nSingle batch request checks (default subject karel, default action CAN_DRIVE):\n- Can knightrider drive kitt? (CAN_DRIVE policy)\n- Can knightrider drive cadillacv16? (CAN_DRIVE policy)\n- Can karel ride harmonika? (CAN_RIDE policy)\n- Can karel drive harmonika? (no policy grants CAN_DRIVE on a Bus)\n\nResponse (in order):\n- {decision: true}\n- {decision: false}\n- {decision: true}\n- {decision: false}\n\nPerformance benefit: 4 authorization decisions with 1 API call instead of 4.",
  "requirements": "Prerequisites:\n- ServiceAccount credentials: For creating policies (Bearer token)\n- AppAgent credentials: For data ingestion and authorization queries (X-IK-ClientKey)\n\nRequired API access:\n- POST /capture/v1/nodes/ and /capture/v1/relationships/ (graph data)\n- POST /configs/v1/authorization-policies (create policies - called twice)\n- POST /access/v1/evaluations (batch evaluation endpoint - note plural)",
  "steps": "Step 1: Ingest Graph Data\n- Authentication: AppAgent credential (X-IK-ClientKey header)\n- Action: POST nodes (Person: alice, knightrider, satchmo, karel; Car: kitt, cadillacv16; Bus: harmonika; Ticket: listek; Laptop: airbook-xyz) and relationships (DRIVES, OWNS, HAS, FOR)\n- Result: Graph ready for authorization queries\n\nStep 2: Create Multiple KBAC Policies\n- Authentication: ServiceAccount credential (Bearer token)\n- Action: POST CAN_DRIVE policy (Person -[DRIVES]-> Car)\n- Action: POST CAN_RIDE policy (Person -[HAS]-> Ticket -[FOR]-> Bus)\n- Result: Two policy IDs returned\n\nStep 3: Run Batch Evaluation\n- Authentication: AppAgent credential (X-IK-ClientKey header)\n- Action: POST to /access/v1/evaluations (plural) with an array of checks\n- Request: top-level subject Person karel and action CAN_DRIVE are the defaults; each entry overrides what it needs:\n  1. subject knightrider, resource Car kitt (default action CAN_DRIVE)\n  2. subject knightrider, resource Car cadillacv16 (default action CAN_DRIVE)\n  3. resource Bus harmonika, action CAN_RIDE (default subject karel)\n  4. resource Bus harmonika (default subject karel, default action CAN_DRIVE)\n- Result: Array of decisions in the same order\n\nStep 5: Cleanup\n- Action: DELETE both policy configurations",
  "graph": {
    "caption": "The graph the example runs on: 9 nodes (4 Person, 2 Car, 1 Bus, 1 Ticket, 1 Laptop) and 8 relationships (DRIVES, HAS, FOR, OWNS). 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": "knightrider",
        "type": "Person",
        "is_identity": true,
        "properties": [
          {
            "type": "email",
            "value": "knightrider@demo.com"
          },
          {
            "type": "name",
            "value": "Michael Knight"
          }
        ]
      },
      {
        "external_id": "satchmo",
        "type": "Person",
        "is_identity": true,
        "properties": [
          {
            "type": "email",
            "value": "satchmo@demo.com"
          },
          {
            "type": "name",
            "value": "Louis Armstrong"
          }
        ]
      },
      {
        "external_id": "karel",
        "type": "Person",
        "is_identity": true,
        "properties": [
          {
            "type": "email",
            "value": "karel@demo.com"
          },
          {
            "type": "name",
            "value": "Karel Plihal"
          }
        ]
      },
      {
        "external_id": "kitt",
        "type": "Car",
        "is_identity": false,
        "properties": [
          {
            "type": "manufacturer",
            "value": "pontiac"
          },
          {
            "type": "model",
            "value": "Firebird"
          }
        ]
      },
      {
        "external_id": "cadillacv16",
        "type": "Car",
        "is_identity": false,
        "properties": [
          {
            "type": "manufacturer",
            "value": "Cadillac"
          },
          {
            "type": "model",
            "value": "V-16"
          }
        ]
      },
      {
        "external_id": "harmonika",
        "type": "Bus",
        "is_identity": false,
        "properties": [
          {
            "type": "manufacturer",
            "value": "Ikarus"
          },
          {
            "type": "model",
            "value": "280"
          }
        ]
      },
      {
        "external_id": "listek",
        "type": "Ticket",
        "is_identity": false,
        "properties": []
      },
      {
        "external_id": "airbook-xyz",
        "type": "Laptop",
        "is_identity": false,
        "properties": []
      }
    ],
    "relationships": [
      {
        "source": "knightrider",
        "target": "kitt",
        "type": "DRIVES",
        "properties": []
      },
      {
        "source": "satchmo",
        "target": "cadillacv16",
        "type": "DRIVES",
        "properties": []
      },
      {
        "source": "karel",
        "target": "listek",
        "type": "HAS",
        "properties": []
      },
      {
        "source": "listek",
        "target": "harmonika",
        "type": "FOR",
        "properties": []
      },
      {
        "source": "karel",
        "target": "airbook-xyz",
        "type": "OWNS",
        "properties": []
      },
      {
        "source": "alice",
        "target": "airbook-xyz",
        "type": "OWNS",
        "properties": []
      },
      {
        "source": "knightrider",
        "target": "kitt",
        "type": "OWNS",
        "properties": []
      },
      {
        "source": "alice",
        "target": "cadillacv16",
        "type": "DRIVES",
        "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": "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": "knightrider",
            "type": "Person",
            "is_identity": true,
            "properties": [
              {
                "type": "email",
                "value": "knightrider@demo.com"
              },
              {
                "type": "name",
                "value": "Michael Knight"
              }
            ]
          },
          {
            "external_id": "satchmo",
            "type": "Person",
            "is_identity": true,
            "properties": [
              {
                "type": "email",
                "value": "satchmo@demo.com"
              },
              {
                "type": "name",
                "value": "Louis Armstrong"
              }
            ]
          },
          {
            "external_id": "karel",
            "type": "Person",
            "is_identity": true,
            "properties": [
              {
                "type": "email",
                "value": "karel@demo.com"
              },
              {
                "type": "name",
                "value": "Karel Plihal"
              }
            ]
          },
          {
            "external_id": "kitt",
            "type": "Car",
            "is_identity": false,
            "properties": [
              {
                "type": "manufacturer",
                "value": "pontiac"
              },
              {
                "type": "model",
                "value": "Firebird"
              }
            ]
          },
          {
            "external_id": "cadillacv16",
            "type": "Car",
            "is_identity": false,
            "properties": [
              {
                "type": "manufacturer",
                "value": "Cadillac"
              },
              {
                "type": "model",
                "value": "V-16"
              }
            ]
          },
          {
            "external_id": "harmonika",
            "type": "Bus",
            "is_identity": false,
            "properties": [
              {
                "type": "manufacturer",
                "value": "Ikarus"
              },
              {
                "type": "model",
                "value": "280"
              }
            ]
          },
          {
            "external_id": "listek",
            "type": "Ticket",
            "is_identity": false
          },
          {
            "external_id": "airbook-xyz",
            "type": "Laptop",
            "is_identity": false
          }
        ]
      }
    },
    {
      "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": "knightrider",
              "type": "Person"
            },
            "target": {
              "external_id": "kitt",
              "type": "Car"
            },
            "type": "DRIVES"
          },
          {
            "source": {
              "external_id": "satchmo",
              "type": "Person"
            },
            "target": {
              "external_id": "cadillacv16",
              "type": "Car"
            },
            "type": "DRIVES"
          },
          {
            "source": {
              "external_id": "karel",
              "type": "Person"
            },
            "target": {
              "external_id": "listek",
              "type": "Ticket"
            },
            "type": "HAS"
          },
          {
            "source": {
              "external_id": "listek",
              "type": "Ticket"
            },
            "target": {
              "external_id": "harmonika",
              "type": "Bus"
            },
            "type": "FOR"
          },
          {
            "source": {
              "external_id": "karel",
              "type": "Person"
            },
            "target": {
              "external_id": "airbook-xyz",
              "type": "Laptop"
            },
            "type": "OWNS"
          },
          {
            "source": {
              "external_id": "alice",
              "type": "Person"
            },
            "target": {
              "external_id": "airbook-xyz",
              "type": "Laptop"
            },
            "type": "OWNS"
          },
          {
            "source": {
              "external_id": "knightrider",
              "type": "Person"
            },
            "target": {
              "external_id": "kitt",
              "type": "Car"
            },
            "type": "OWNS"
          },
          {
            "source": {
              "external_id": "alice",
              "type": "Person"
            },
            "target": {
              "external_id": "cadillacv16",
              "type": "Car"
            },
            "type": "DRIVES"
          }
        ]
      }
    },
    {
      "step": "Step 2",
      "description": "KBAC Policy which rules that a Person node can drive a car if the Person node has a relation DRIVES with a car in json format.",
      "filename": "policy.json",
      "language": "Json",
      "ingest": {
        "meta": {
          "policy_version": "2.0-kbac"
        },
        "subject": {
          "type": "Person"
        },
        "actions": [
          "CAN_DRIVE"
        ],
        "resource": {
          "type": "Car"
        },
        "condition": {
          "cypher": "MATCH (subject:Person)-[:DRIVES]->(resource:Car)"
        }
      }
    },
    {
      "description": "Request to create the KBAC 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\":\"2.0-kbac\"},\"subject\":{\"type\":\"Person\"},\"actions\":[\"CAN_DRIVE\"],\"resource\":{\"type\":\"Car\"},\"condition\":{\"cypher\":\"MATCH (subject:Person)-[:DRIVES]->(resource:Car)\"}}",
        "status": "ACTIVE",
        "tags": []
      }
    },
    {
      "description": "Request to create the KBAC Policy configuration using Python.",
      "filename": "policy_request.py",
      "language": "Python",
      "code": "\nimport http.client\n\nconn = http.client.HTTPSConnection(\"eu.api.indykite.com\")\n\npayload = \"{\"description\": \"\",\n  \"display_name\": \"\",\n  \"name\": \"\",\n  \"policy\": \"\",\n  \"project_id\": \"\",\n  \"status\": \"ACTIVE\",\n  \"tags\": [\n    \"\"\n  ]}\"\nheaders = {\n    'Content-Type': \"application/json\",\n    'Authorization': \"YOUR_SECRET_TOKEN\"\n}\n\nconn.request(\"POST\", \"/configs/v1/authorization-policies\", payload, headers)\nres = conn.getresponse()\ndata = res.read()\n"
    },
    {
      "description": "Request to read the KBAC Policy configuration using REST",
      "filename": "GET https://eu.api.indykite.com/configs/v1/authorization-policies/{id}",
      "language": "Json",
      "ingest": {
        "id": "your_policy_configuration_gid"
      }
    },
    {
      "description": "Request to read the KBAC Policy configuration using Python.",
      "filename": "policy_request.py",
      "language": "Python",
      "code": "\nimport http.client\n\nconn = http.client.HTTPSConnection(\"eu.api.indykite.com\")\nheaders = { 'Authorization': \"YOUR_SECRET_TOKEN\" }\nconn.request(\"GET\", \"/configs/v1/authorization-policies/{{id}}\", headers=headers)\nres = conn.getresponse()\ndata = res.read()\n"
    },
    {
      "description": "KBAC Policy which rules that a Person node can ride a bus if the Person node has a ticket for the bus in json format.",
      "filename": "policy.json",
      "language": "Json",
      "ingest": {
        "meta": {
          "policy_version": "2.0-kbac"
        },
        "subject": {
          "type": "Person"
        },
        "actions": [
          "CAN_RIDE"
        ],
        "resource": {
          "type": "Bus"
        },
        "condition": {
          "cypher": "MATCH (subject)-[:HAS]->(ticket:Ticket)-[:FOR]->(resource)"
        }
      }
    },
    {
      "description": "Request to create the KBAC 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\":\"2.0-kbac\"},\"subject\":{\"type\":\"Person\"},\"actions\":[\"CAN_RIDE\"],\"resource\":{\"type\":\"Bus\"},\"condition\":{\"cypher\":\"MATCH (subject)-[:HAS]->(ticket:Ticket)-[:FOR]->(resource)\"}}",
        "status": "ACTIVE",
        "tags": []
      }
    },
    {
      "description": "Request to create the KBAC Policy configuration using Python.",
      "filename": "policy_request.py",
      "language": "Python",
      "code": "\nimport http.client\n\nconn = http.client.HTTPSConnection(\"eu.api.indykite.com\")\n\npayload = \"{\"description\": \"\",\n  \"display_name\": \"\",\n  \"name\": \"\",\n  \"policy\": \"\",\n  \"project_id\": \"\",\n  \"status\": \"ACTIVE\",\n  \"tags\": [\n    \"\"\n  ]}\"\nheaders = {\n    'Content-Type': \"application/json\",\n    'Authorization': \"YOUR_SECRET_TOKEN\"\n}\n\nconn.request(\"POST\", \"/configs/v1/authorization-policies\", payload, headers)\nres = conn.getresponse()\ndata = res.read()\n"
    },
    {
      "description": "Request to read the KBAC Policy configuration using REST.",
      "filename": "GET https://eu.api.indykite.com/configs/v1/authorization-policies/{id}",
      "language": "Json",
      "ingest": {
        "id": "your_policy_configuration_gid"
      }
    },
    {
      "description": "Request to read the KBAC Policy configuration using Python.",
      "filename": "policy_request.py",
      "language": "Python",
      "code": "\nimport http.client\n\nconn = http.client.HTTPSConnection(\"eu.api.indykite.com\")\nheaders = { 'Authorization': \"YOUR_SECRET_TOKEN\" }\nconn.request(\"GET\", \"/configs/v1/authorization-policies/{{id}}\", headers=headers)\nres = conn.getresponse()\ndata = res.read()\n"
    },
    {
      "step": "Step 3",
      "description": "Json to run KBAC access multi-evaluations.\n        The elements outside evaluations are the default values.\n        Here we have a default value for subject and for action.\n        If a top-level key is designated in the evaluations array then the value of that will take precedence over the default value.",
      "filename": "POST https://eu.api.indykite.com/access/v1/evaluations",
      "language": "Json",
      "ingest": {
        "subject": {
          "type": "Person",
          "id": "karel"
        },
        "action": {
          "name": "CAN_DRIVE"
        },
        "evaluations": [
          {
            "subject": {
              "type": "Person",
              "id": "knightrider"
            },
            "resource": {
              "type": "Car",
              "id": "kitt"
            }
          },
          {
            "subject": {
              "type": "Person",
              "id": "knightrider"
            },
            "resource": {
              "type": "Car",
              "id": "cadillacv16"
            }
          },
          {
            "resource": {
              "type": "Bus",
              "id": "harmonika"
            },
            "action": {
              "name": "CAN_RIDE"
            }
          },
          {
            "resource": {
              "type": "Bus",
              "id": "harmonika"
            }
          }
        ]
      }
    },
    {
      "description": "Response to the KBAC Evaluations endpoint request.",
      "filename": "Response 200",
      "language": "Json",
      "ingest": {
        "evaluations": [
          {
            "decision": true
          },
          {
            "decision": false
          },
          {
            "decision": true
          },
          {
            "decision": false
          }
        ]
      }
    },
    {
      "description": "Request to run the KBAC Evaluations endpoint.",
      "filename": "evaluations.py",
      "language": "Python",
      "code": "\nimport http.client\n\nconn = http.client.HTTPSConnection(\"eu.api.indykite.com\")\n\npayload = \"{\n    \"subject\": {\"type\": \"Person\",\n        \"id\": \"karel\"}, \n    \"action\": {\"name\": \"CAN_DRIVE\"},\n    \"evaluations\": [\n        {\n          \t\"subject\": {\"type\": \"Person\",\n                \"id\": \"knightrider\"}, \n            \"resource\": {\"type\": \"Car\",\n                \"id\": \"kitt\"}\n        },\n        {\n          \t\"subject\": {\"type\": \"Person\",\n                \"id\": \"knightrider\"}, \n            \"resource\": {\"type\": \"Car\",\n                \"id\": \"cadillacv16\"}\n        },\n        {\n          \t\"resource\": {\"type\": \"Bus\",\n                \"id\": \"harmonika\"},\n            \"action\": {\"name\": \"CAN_RIDE\"}\n        },\n        {\n          \t\"resource\": {\"type\": \"Bus\",\n                \"id\": \"harmonika\"}\n        }\n    ]\n}\"\n\nheaders = {\n    'Content-Type': \"application/json\",\n    'X-IK-ClientKey': \"\"\n}\n\nconn.request(\"POST\", \"/access/v1/evaluations\", payload, headers)\n\nres = conn.getresponse()\ndata = res.read()\n"
    },
    {
      "step": "Step 5",
      "description": "Delete the KBAC Policies.",
      "filename": "DELETE https://eu.api.indykite.com/configs/v1/authorization-policies/{id}",
      "language": "Json",
      "ingest": {
        "id": "your_policy_configuration_gid"
      }
    },
    {
      "description": "Request to delete the KBAC Policies.",
      "filename": "del.py",
      "language": "Python",
      "code": "\nimport http.client\n\nconn = http.client.HTTPSConnection(\"eu.api.indykite.com\")\n\nheaders = { 'Authorization': \"Bearer ...\", 'Content-Type': \"application/json\" }\n\nconn.request(\"DELETE\", \"/configs/v1/authorization-policies/{id}\", headers=headers)\n\nres = conn.getresponse()\ndata = res.read()\n"
    }
  ],
  "links": {
    "html": "/resources/authz-2",
    "markdown": "/resources/authz-2.md",
    "openApi": "https://openapi.indykite.com/"
  }
}