{
  "id": "ciq-17",
  "title": "ContX IQ: Application as Service - How do I create a Person linked to multiple nodes?",
  "description": "Demonstrates service-to-service data creation where an Application (not a user) creates new Person nodes and links them to existing Country and Company nodes. Common pattern for system integrations and automated data pipelines.",
  "category": "ContX IQ",
  "tags": [
    "ContX IQ Policy",
    "ContX IQ Query",
    "Service Account",
    "_Application Subject",
    "Node Creation",
    "Multi-Relationship"
  ],
  "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 shows Application-as-subject creating nodes with multiple relationships:\n\nService-to-service pattern:\n- No user token involved\n- Application authenticates with its API key\n- Application creates data on behalf of the system\n\nOperation:\nCreate Person node with properties and metadata, and link it to two existing nodes:\n- Person -[BELONGS_TO]-> Country\n- Person -[BELONGS_TO]-> Company\n\nUse cases:\n- Data import pipelines\n- System integrations\n- Automated onboarding workflows",
  "usecase": "Scenario: An HR integration system automatically creates employee records.\n\nExisting data:\n- Country(Norway)\n- Company(Forsenty)\n\nIntegration operation:\n1. HR system triggers employee creation\n2. Application creates: Person(456985) with VerificationMethod, Email, PhoneNumber, FirstName and LastName properties, each carrying assurance_level and source metadata\n3. Links: Person -[BELONGS_TO]-> Country(Norway)\n4. Links: Person -[BELONGS_TO]-> Company(Forsenty)\n\nFinal graph:\nCountry(Norway) <-[BELONGS_TO]- Person(456985) -[BELONGS_TO]-> Company(Forsenty)\n\nKey difference from user-based creation:\n- Uses $_appId filter (auto-populated)\n- No user token required\n- Application is the authorized subject\n- The Country and Company to link are selected by input parameters ($country_external_id, $company_external_id) in the policy filter",
  "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\nNo user token needed:\n- Application acts as its own subject\n- $_appId automatically identifies the calling application",
  "steps": "Step 1: Ingest Reference Data\n- Authentication: AppAgent credential (X-IK-ClientKey header)\n- Action: POST Country(Norway) and Company(Forsenty) nodes\n- Result: Reference nodes ready for linking\n\nStep 2: Create Node Creation Policy\n- Authentication: ServiceAccount credential (Bearer token)\n- Action: POST policy with subject type _Application, filter subject.external_id = $_appId AND country.external_id = $country_external_id AND company.external_id = $company_external_id, allowing:\n  - READ country and company nodes\n  - UPSERT Person nodes\n  - UPSERT BELONGS_TO relationships (Person -> Country)\n  - UPSERT BELONGS_TO relationships (Person -> Company)\n- Result: Policy ID returned\n\nStep 3: Create Node Creation Query\n- Authentication: ServiceAccount credential (Bearer token)\n- Action: POST query that upserts the Person node and two BELONGS_TO relationships, with parameters:\n  - $person_external_id (for the Person node)\n  - $verification_method, $email, $phone_number, $first_name, $last_name (property values)\n  - $assurance_level, $source (metadata on every property)\n  - $country_external_id, $company_external_id (policy filter, select the nodes to link)\n- Result: Query ID returned\n\nStep 4: Execute Creation\n- Authentication: AppAgent credential (X-IK-ClientKey header)\n- Action: POST to /contx-iq/v1/execute with:\n  - person_external_id: \"456985\"\n  - verification_method: \"BREGG\", assurance_level: 3, source: \"NAV\"\n  - email: \"elias@email.com\", phone_number: \"4725639685\", first_name: \"Elias\", last_name: \"Boomy\"\n  - country_external_id: \"Norway\", company_external_id: \"Forsenty\"\n- Result: Person 456985 created with both BELONGS_TO relationships; the response returns the person node and its external_id\n\nStep 5: Cleanup\n- Action: DELETE query and policy configurations",
  "graph": {
    "caption": "The graph the example runs on: 2 nodes (1 Country, 1 Company), no relationships. Hover a node for its properties.",
    "nodes": [
      {
        "external_id": "Norway",
        "type": "Country",
        "is_identity": false,
        "properties": []
      },
      {
        "external_id": "Forsenty",
        "type": "Company",
        "is_identity": false,
        "properties": []
      }
    ],
    "relationships": []
  },
  "graphEnd": {
    "caption": "After step 4: the Person created from the input parameters, with BELONGS_TO relationships to Norway and to Forsenty.",
    "nodes": [
      {
        "external_id": "Norway",
        "type": "Country",
        "is_identity": false,
        "properties": []
      },
      {
        "external_id": "Forsenty",
        "type": "Company",
        "is_identity": false,
        "properties": []
      },
      {
        "external_id": "456985",
        "type": "Person",
        "is_identity": true,
        "properties": [
          {
            "type": "VerificationMethod",
            "value": "BREGG"
          },
          {
            "type": "Email",
            "value": "elias@email.com"
          },
          {
            "type": "PhoneNumber",
            "value": "4725639685"
          },
          {
            "type": "FirstName",
            "value": "Elias"
          },
          {
            "type": "LastName",
            "value": "Boomy"
          }
        ]
      }
    ],
    "relationships": [
      {
        "source": "456985",
        "target": "Norway",
        "type": "BELONGS_TO"
      },
      {
        "source": "456985",
        "target": "Forsenty",
        "type": "BELONGS_TO"
      }
    ]
  },
  "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": "Norway",
            "type": "Country"
          },
          {
            "external_id": "Forsenty",
            "type": "Company"
          }
        ]
      }
    },
    {
      "step": "Step 2",
      "description": "Policy which designates the derived query can create a Person node, a relationship with a Country node, and a relationship with a Company node.",
      "filename": "policy.json",
      "language": "Json",
      "ingest": {
        "meta": {
          "policy_version": "1.0-ciq"
        },
        "subject": {
          "type": "_Application"
        },
        "condition": {
          "cypher": "MATCH (subject:_Application) MATCH (country:Country) MATCH (company:Company)",
          "filter": [
            {
              "app": "app1",
              "operator": "AND",
              "operands": [
                {
                  "attribute": "subject.external_id",
                  "operator": "=",
                  "value": "$_appId"
                },
                {
                  "attribute": "country.external_id",
                  "operator": "=",
                  "value": "$country_external_id"
                },
                {
                  "attribute": "company.external_id",
                  "operator": "=",
                  "value": "$company_external_id"
                }
              ]
            }
          ]
        },
        "allowed_reads": {
          "nodes": [
            "country",
            "country.*",
            "company",
            "company.*"
          ]
        },
        "allowed_upserts": {
          "nodes": {
            "node_types": [
              "Person"
            ]
          },
          "relationships": {
            "relationship_types": [
              {
                "type": "BELONGS_TO",
                "source_node_label": "Person",
                "target_node_label": "Country"
              },
              {
                "type": "BELONGS_TO",
                "source_node_label": "Person",
                "target_node_label": "Company"
              }
            ]
          }
        }
      }
    },
    {
      "description": "Request to create a 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\":\"_Application\"},\"condition\":{\"cypher\":\"MATCH (subject:_Application) MATCH (country:Country) MATCH (company:Company)\",\"filter\":[{\"app\":\"app1\",\"operator\":\"AND\",\"operands\":[{\"attribute\":\"subject.external_id\",\"operator\":\"=\",\"value\":\"$_appId\"},{\"attribute\":\"country.external_id\",\"operator\":\"=\",\"value\":\"$country_external_id\"},{\"attribute\":\"company.external_id\",\"operator\":\"=\",\"value\":\"$company_external_id\"}]}]},\"allowed_reads\":{\"nodes\":[\"country\",\"country.*\",\"company\",\"company.*\"]},\"allowed_upserts\":{\"nodes\":{\"node_types\":[\"Person\"]},\"relationships\":{\"relationship_types\":[{\"type\":\"BELONGS_TO\",\"source_node_label\":\"Person\",\"target_node_label\":\"Country\"},{\"type\":\"BELONGS_TO\",\"source_node_label\":\"Person\",\"target_node_label\":\"Company\"}]}}}",
        "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": "The CIQ Knowledge Query designates the node to create and the relationships to upsert. ",
      "filename": "knowledge_query.json",
      "language": "Json",
      "ingest": {
        "nodes": [
          "person",
          "person.external_id"
        ],
        "relationships": [],
        "upsert_nodes": [
          {
            "name": "person",
            "type": "Person",
            "external_id": "$person_external_id",
            "is_identity": true,
            "properties": [
              {
                "type": "VerificationMethod",
                "value": "$verification_method",
                "metadata": [
                  {
                    "type": "Assurance_level",
                    "value": "$assurance_level"
                  },
                  {
                    "type": "source",
                    "value": "$source"
                  }
                ]
              },
              {
                "type": "Email",
                "value": "$email",
                "metadata": [
                  {
                    "type": "Assurance_level",
                    "value": "$assurance_level"
                  },
                  {
                    "type": "source",
                    "value": "$source"
                  }
                ]
              },
              {
                "type": "PhoneNumber",
                "value": "$phone_number",
                "metadata": [
                  {
                    "type": "assurance_level",
                    "value": "$assurance_level"
                  },
                  {
                    "type": "source",
                    "value": "$source"
                  }
                ]
              },
              {
                "type": "FirstName",
                "value": "$first_name",
                "metadata": [
                  {
                    "type": "assurance_level",
                    "value": "$assurance_level"
                  },
                  {
                    "type": "source",
                    "value": "$source"
                  }
                ]
              },
              {
                "type": "LastName",
                "value": "$last_name",
                "metadata": [
                  {
                    "type": "assurance_level",
                    "value": "$assurance_level"
                  },
                  {
                    "type": "source",
                    "value": "$source"
                  }
                ]
              }
            ]
          }
        ],
        "upsert_relationships": [
          {
            "name": "rel1",
            "source": "person",
            "target": "country",
            "type": "BELONGS_TO",
            "properties": []
          },
          {
            "name": "rel2",
            "source": "person",
            "target": "company",
            "type": "BELONGS_TO",
            "properties": []
          }
        ]
      }
    },
    {
      "description": "Request to create a CIQ Knowledge 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\":[\"person\",\"person.external_id\"],\"relationships\":[],\"upsert_nodes\":[{\"name\":\"person\",\"type\":\"Person\",\"external_id\":\"$person_external_id\",\"is_identity\":true,\"properties\":[{\"type\":\"VerificationMethod\",\"value\":\"$verification_method\",\"metadata\":[{\"type\":\"Assurance_level\",\"value\":\"$assurance_level\"},{\"type\":\"source\",\"value\":\"$source\"}]},{\"type\":\"Email\",\"value\":\"$email\",\"metadata\":[{\"type\":\"Assurance_level\",\"value\":\"$assurance_level\"},{\"type\":\"source\",\"value\":\"$source\"}]},{\"type\":\"PhoneNumber\",\"value\":\"$phone_number\",\"metadata\":[{\"type\":\"assurance_level\",\"value\":\"$assurance_level\"},{\"type\":\"source\",\"value\":\"$source\"}]},{\"type\":\"FirstName\",\"value\":\"$first_name\",\"metadata\":[{\"type\":\"assurance_level\",\"value\":\"$assurance_level\"},{\"type\":\"source\",\"value\":\"$source\"}]},{\"type\":\"LastName\",\"value\":\"$last_name\",\"metadata\":[{\"type\":\"assurance_level\",\"value\":\"$assurance_level\"},{\"type\":\"source\",\"value\":\"$source\"}]}]}],\"upsert_relationships\":[{\"name\":\"rel1\",\"source\":\"person\",\"target\":\"country\",\"type\":\"BELONGS_TO\",\"properties\":[]},{\"name\":\"rel2\",\"source\":\"person\",\"target\":\"company\",\"type\":\"BELONGS_TO\",\"properties\":[]}]}",
        "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": "CIQ Execution request in json format.",
      "filename": "POST https://eu.api.indykite.com/contx-iq/v1/execute",
      "language": "Json",
      "ingest": {
        "id": "knowledge_query_gid",
        "input_params": {
          "person_external_id": "456985",
          "verification_method": "BREGG",
          "assurance_level": 3,
          "source": "NAV",
          "email": "elias@email.com",
          "phone_number": "4725639685",
          "first_name": "Elias",
          "last_name": "Boomy",
          "country_external_id": "Norway",
          "company_external_id": "Forsenty"
        },
        "page_token": 1
      }
    },
    {
      "description": "CIQ Execution response in json format.",
      "filename": "response.json",
      "language": "Json",
      "ingest": {
        "data": [
          {
            "nodes": {
              "person": {
                "Id": 5,
                "ElementId": "4:a5c213aa-aa4b-4be5-a17a-a677a80ee634:5",
                "Labels": [
                  "Unique",
                  "Resource",
                  "DigitalTwin",
                  "Person"
                ],
                "Props": {
                  "create_time": "2025-09-26T11:29:25.43Z",
                  "external_id": "456985",
                  "id": "I2kGlVoQQHmj_gfNvH4b-A",
                  "type": "Person",
                  "update_time": "2025-09-26T11:29:25.43Z"
                }
              },
              "person.external_id": "456985"
            }
          }
        ]
      }
    },
    {
      "step": "Step 5",
      "description": "Delete the CIQ Query.",
      "filename": "DELETE https://eu.api.indykite.com/configs/v1/knowledge-queries/{id}",
      "language": "Json",
      "ingest": {
        "id": "your_knowledge_query_configuration_gid"
      }
    },
    {
      "description": "Delete the CIQ Policy.",
      "filename": "DELETE https://eu.api.indykite.com/configs/v1/authorization-policies/{id}",
      "language": "Json",
      "ingest": {
        "id": "your_policy_configuration_gid"
      }
    }
  ],
  "links": {
    "html": "/resources/ciq-17",
    "markdown": "/resources/ciq-17.md",
    "openApi": "https://openapi.indykite.com/"
  }
}