{
  "id": "ciq-20",
  "title": "ContX IQ: How do I filter data with the IN array operator and a user subject?",
  "description": "Query Contract nodes using the IN operator to filter by array values in policy conditions. Demonstrates how to check if a value exists within an array property during authorization.",
  "category": "ContX IQ",
  "tags": [
    "ContX IQ Policy",
    "ContX IQ Query",
    "ContX IQ Execution",
    "IN Operator",
    "Array Filter",
    "User Subject"
  ],
  "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 using the IN operator for array-based filtering:\n\nWhat is the IN operator?\nThe IN operator checks if a value exists within an array. Useful when authorization depends on membership in a list.\n\nPolicy pattern (two IN operands combined with AND):\n- subject.external_id IN $idList (an array passed as input parameter)\n- subject.external_id IN @contract.property.signers (an array property of the matched Contract node, referenced with the @ prefix)\n\nOperations demonstrated:\n1. Authenticate the user via token introspection (the policy subject is a Person, so a bearer token is required)\n2. Policy checks the subject's external_id against an input array and against an array stored on the resource\n3. Query returns the Contract nodes matching both filters\n\nUse cases:\n- Allow-list of subjects (check if the subject is in a list passed at execute time)\n- Membership stored on the resource (check if the subject is one of the contract's signers)\n- Multi-value attribute matching",
  "usecase": "Scenario: Retrieve the contracts a person accepted, but only when that person is on an allow-list and is recorded as a signer of the contract.\n\nGraph structure:\nPerson(alice_sub_value) -[ACCEPTED]-> Contract(ct985) {signers: [alice_sub_value, ryan, tilda]}\nPerson(alice_sub_value) -[ACCEPTED]-> Contract(ct234) {signers: [alice_sub_value, ryan]}\nPerson(ryan) -[ACCEPTED]-> Contract(ct985), Contract(ct234)\nPerson(tilda) -[ACCEPTED]-> Contract(ct985), Contract(ct123) {signers: [tilda]}\n\nPolicy logic:\n- The user authenticates with an access token (Person subject)\n- Policy cypher: MATCH (subject:Person)-[r1:ACCEPTED]->(contract:Contract)\n- Filter: subject.external_id IN $idList AND subject.external_id IN @contract.property.signers\n- Only the contracts matching both array filters are returned\n\nQuery flow:\n1. Execute with input_params idList = [\"alice_sub_value\", \"ryan\"]\n2. Subjects alice_sub_value and ryan pass the first IN; tilda does not\n3. For each of their contracts, the subject must also appear in contract.property.signers\n4. Result: ct234 and ct985 are returned (ct985 once per matching subject); ct123 is not, because neither subject is among its signers",
  "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- User access token: JWT for the Person node to be authenticated\n\nHow to pass user token:\n- Header: Authorization: Bearer {user_access_token}\n- Token is introspected to identify the user and their attributes",
  "steps": "Step 1: Ingest Graph Data\n- Authentication: AppAgent credential (X-IK-ClientKey header)\n- Action: POST Person nodes (alice_sub_value, ryan, tilda) and Contract nodes (ct123, ct234, ct985) whose signers property is an array, then the ACCEPTED relationships\n- Result: Graph ready for array-filtered queries\n\nStep 2: Create Policy with IN Array Filter\n- Authentication: ServiceAccount credential (Bearer token)\n- Action: POST policy with subject type Person, cypher MATCH (subject:Person)-[r1:ACCEPTED]->(contract:Contract), and an AND filter of:\n  - subject.external_id IN $idList (input parameter array)\n  - subject.external_id IN @contract.property.signers (array property of the contract)\n- Allowed reads: contract.*, r1.*\n- Result: Policy ID returned\n\nStep 3: Create Query for Contract Properties\n- Authentication: ServiceAccount credential (Bearer token)\n- Action: POST query that retrieves contract.external_id, contract.property.signers and contract.property.category\n- Query respects the IN array filters from the policy\n- Result: Query ID returned\n\nStep 4: Execute Query as Authenticated User\n- Authentication: AppAgent credential + User token (Bearer header)\n- Action: POST to /contx-iq/v1/execute with input_params idList = [\"alice_sub_value\", \"ryan\"]\n- Result: ct234 and ct985 returned with their signers and category",
  "graph": {
    "caption": "The graph the example runs on: 6 nodes (3 Person, 3 Contract) and 6 relationships (ACCEPTED). Hover a node for its properties, click it to highlight its neighbourhood.",
    "nodes": [
      {
        "external_id": "alice_sub_value",
        "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": "ct123",
        "type": "Contract",
        "is_identity": false,
        "properties": [
          {
            "type": "category",
            "value": "Insurance"
          },
          {
            "type": "status",
            "value": "Active"
          },
          {
            "type": "signers",
            "value": "[\"tilda\"]"
          }
        ]
      },
      {
        "external_id": "ct234",
        "type": "Contract",
        "is_identity": false,
        "properties": [
          {
            "type": "category",
            "value": "Insurance"
          },
          {
            "type": "status",
            "value": "Active"
          },
          {
            "type": "signers",
            "value": "[\"alice_sub_value\",\"ryan\"]"
          }
        ]
      },
      {
        "external_id": "ct985",
        "type": "Contract",
        "is_identity": false,
        "properties": [
          {
            "type": "category",
            "value": "Insurance"
          },
          {
            "type": "status",
            "value": "Active"
          },
          {
            "type": "signers",
            "value": "[\"alice_sub_value\",\"ryan\",\"tilda\"]"
          }
        ]
      }
    ],
    "relationships": [
      {
        "source": "alice_sub_value",
        "target": "ct985",
        "type": "ACCEPTED",
        "properties": []
      },
      {
        "source": "alice_sub_value",
        "target": "ct234",
        "type": "ACCEPTED",
        "properties": []
      },
      {
        "source": "ryan",
        "target": "ct985",
        "type": "ACCEPTED",
        "properties": []
      },
      {
        "source": "ryan",
        "target": "ct234",
        "type": "ACCEPTED",
        "properties": []
      },
      {
        "source": "tilda",
        "target": "ct985",
        "type": "ACCEPTED",
        "properties": []
      },
      {
        "source": "tilda",
        "target": "ct123",
        "type": "ACCEPTED",
        "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_sub_value",
            "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": "ct123",
            "type": "Contract",
            "properties": [
              {
                "type": "category",
                "value": "Insurance"
              },
              {
                "type": "status",
                "value": "Active"
              },
              {
                "type": "signers",
                "value": [
                  "tilda"
                ]
              }
            ]
          },
          {
            "external_id": "ct234",
            "type": "Contract",
            "properties": [
              {
                "type": "category",
                "value": "Insurance"
              },
              {
                "type": "status",
                "value": "Active"
              },
              {
                "type": "signers",
                "value": [
                  "alice_sub_value",
                  "ryan"
                ]
              }
            ]
          },
          {
            "external_id": "ct985",
            "type": "Contract",
            "properties": [
              {
                "type": "category",
                "value": "Insurance"
              },
              {
                "type": "status",
                "value": "Active"
              },
              {
                "type": "signers",
                "value": [
                  "alice_sub_value",
                  "ryan",
                  "tilda"
                ]
              }
            ]
          }
        ]
      }
    },
    {
      "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": "alice_sub_value",
              "type": "Person"
            },
            "target": {
              "external_id": "ct985",
              "type": "Contract"
            },
            "type": "ACCEPTED"
          },
          {
            "source": {
              "external_id": "alice_sub_value",
              "type": "Person"
            },
            "target": {
              "external_id": "ct234",
              "type": "Contract"
            },
            "type": "ACCEPTED"
          },
          {
            "source": {
              "external_id": "ryan",
              "type": "Person"
            },
            "target": {
              "external_id": "ct985",
              "type": "Contract"
            },
            "type": "ACCEPTED"
          },
          {
            "source": {
              "external_id": "ryan",
              "type": "Person"
            },
            "target": {
              "external_id": "ct234",
              "type": "Contract"
            },
            "type": "ACCEPTED"
          },
          {
            "source": {
              "external_id": "tilda",
              "type": "Person"
            },
            "target": {
              "external_id": "ct985",
              "type": "Contract"
            },
            "type": "ACCEPTED"
          },
          {
            "source": {
              "external_id": "tilda",
              "type": "Person"
            },
            "target": {
              "external_id": "ct123",
              "type": "Contract"
            },
            "type": "ACCEPTED"
          }
        ]
      }
    },
    {
      "step": "Step 2",
      "description": "Create a CIQ Policy which designates the Subject node, the cypher, the nodes allowed to be upserted and the nodes allowed to be read. ",
      "filename": "policy.json",
      "language": "Json",
      "ingest": {
        "meta": {
          "policy_version": "1.0-ciq"
        },
        "subject": {
          "type": "Person"
        },
        "condition": {
          "cypher": "MATCH (subject:Person)-[r1:ACCEPTED]->(contract:Contract)",
          "filter": [
            {
              "app": "app1",
              "operator": "AND",
              "operands": [
                {
                  "attribute": "subject.external_id",
                  "operator": "IN",
                  "value": "$idList"
                },
                {
                  "attribute": "subject.external_id",
                  "operator": "IN",
                  "value": "@contract.property.signers"
                }
              ]
            }
          ]
        },
        "allowed_reads": {
          "nodes": [
            "contract.*"
          ],
          "relationships": [
            "r1.*"
          ]
        }
      }
    },
    {
      "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 (subject:Person)-[r1:ACCEPTED]->(contract:Contract)\",\"filter\":[{\"app\":\"app1\",\"operator\":\"AND\",\"operands\":[{\"attribute\":\"subject.external_id\",\"operator\":\"IN\",\"value\":\"$idList\"},{\"attribute\":\"subject.external_id\",\"operator\":\"IN\",\"value\":\"@contract.property.signers\"}]}]},\"allowed_reads\":{\"nodes\":[\"contract.*\"],\"relationships\":[\"r1.*\"]}}",
        "status": "ACTIVE",
        "tags": []
      }
    },
    {
      "description": "Request to read the CIQ Policy configuration using REST.",
      "filename": "policy_request.json",
      "language": "Json",
      "ingest": {
        "id": "your_policy_configuration_gid"
      }
    },
    {
      "step": "Step 3",
      "description": "Create a CIQ Query in the context of the policy to retrieve the designated properties. ",
      "filename": "knowledge_query.json",
      "language": "Json",
      "ingest": {
        "nodes": [
          "contract.external_id",
          "contract.property.signers",
          "contract.property.category"
        ]
      }
    },
    {
      "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\":[\"contract.external_id\",\"contract.property.signers\",\"contract.property.category\"]}",
        "status": "ACTIVE"
      }
    },
    {
      "description": "Read the CIQ Query Configuration.",
      "filename": "GET https://eu.api.indykite.com/configs/v1/knowledge-queries/{id}",
      "language": "Json",
      "ingest": {
        "id": "your_knowledge_query_configuration_gid"
      }
    },
    {
      "step": "Step 4",
      "description": "Run a CIQ Execution to get the designated information. ",
      "filename": "POST https://eu.api.indykite.com/contx-iq/v1/execute",
      "language": "Json",
      "ingest": {
        "id": "knowledge_query_gid",
        "input_params": {
          "idList": [
            "alice_sub_value",
            "ryan"
          ]
        },
        "page_token": 1
      }
    },
    {
      "description": "CIQ Execution response.",
      "filename": "response.json",
      "language": "Json",
      "ingest": {
        "data": [
          {
            "nodes": {
              "contract.external_id": "ct234",
              "contract.property.category": "Insurance",
              "contract.property.signers": [
                "alice_sub_value",
                "ryan"
              ]
            }
          },
          {
            "nodes": {
              "contract.external_id": "ct985",
              "contract.property.category": "Insurance",
              "contract.property.signers": [
                "alice_sub_value",
                "ryan",
                "tilda"
              ]
            }
          },
          {
            "nodes": {
              "contract.external_id": "ct985",
              "contract.property.category": "Insurance",
              "contract.property.signers": [
                "alice_sub_value",
                "ryan",
                "tilda"
              ]
            }
          }
        ]
      }
    }
  ],
  "links": {
    "html": "/resources/ciq-20",
    "markdown": "/resources/ciq-20.md",
    "openApi": "https://openapi.indykite.com/"
  }
}