> ## Documentation Index
> Fetch the complete documentation index at: https://docs.draftt.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Query Kubernetes resources evaluated by a policy

> Queries policy_k8s_resource rows for one policy. Pass k8sResourceData to filter or select from the joined, scoped Kubernetes resource.



## OpenAPI

````yaml https://api.draftt.io/swagger post /policy/{policyId}/k8sResource/query
openapi: 3.1.0
info:
  title: Draftt API
  version: 0.2.1
servers:
  - url: https://api.draftt.io/v1
security:
  - BearerAuth: []
paths:
  /policy/{policyId}/k8sResource/query:
    post:
      tags:
        - Policy K8s Resource
      summary: Query Kubernetes resources evaluated by a policy
      description: >-
        Queries policy_k8s_resource rows for one policy. Pass k8sResourceData to
        filter or select from the joined, scoped Kubernetes resource.
      operationId: queryPolicyK8sResources
      parameters:
        - name: policyId
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PolicyK8sResourceQuery'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PolicyK8sResourceResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  schemas:
    PolicyK8sResourceQuery:
      type: object
      properties:
        filter:
          type: object
          additionalProperties: true
        select:
          type: array
          items:
            type: string
        sort:
          type: object
          additionalProperties:
            type: string
            enum:
              - asc
              - desc
        pageToken:
          type: string
        pageSize:
          type: integer
          minimum: 1
          maximum: 1000
          default: 100
        k8sResourceData:
          type: object
          description: >-
            When present, joins the scoped K8s resource and returns it as
            k8sResourceData.
          properties:
            filter:
              type: object
              additionalProperties: true
            select:
              type: array
              items:
                type: string
                enum:
                  - id
                  - clusterComponentId
                  - clusterComponentName
                  - uniqueIdentifier
                  - name
                  - kind
                  - namespace
                  - apiVersion
                  - apiGroup
                  - collectionMode
                  - knownCrd
                  - labels
                  - details
                  - ownershipClass
                  - managedBy
                  - managedByName
                  - managedByNamespace
                  - helmChartName
                  - helmChartVersion
                  - createdAt
                  - updatedAt
      example:
        filter:
          status:
            $eq: Non-Compliant
        k8sResourceData:
          select:
            - id
            - name
            - kind
            - namespace
            - apiVersion
            - managedBy
        sort:
          status: desc
        pageSize: 50
    PolicyK8sResourceResponse:
      type: object
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/PolicyK8sResource'
        nextPageToken:
          type: string
      required:
        - items
    PolicyK8sResource:
      type: object
      properties:
        id:
          type: string
          format: int64
        policyId:
          type: string
          format: int64
        k8sResourceId:
          type: string
          format: uuid
        clusterComponentId:
          type: string
          format: int64
        name:
          type: string
        status:
          type: string
          enum:
            - Compliant
            - Non-Compliant
            - Unknown
        ticketId:
          type: string
        ticketStatus:
          type: string
        details:
          type: object
          additionalProperties: true
        k8sResourceData:
          $ref: '#/components/schemas/K8sResource'
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
          required:
            - message
      required:
        - error
    K8sResource:
      type: object
      properties:
        id:
          type: string
          format: uuid
        clusterComponentId:
          type: string
          format: int64
        clusterComponentName:
          type: string
        uniqueIdentifier:
          type: string
        name:
          type: string
        kind:
          type: string
        namespace:
          type:
            - string
            - 'null'
        apiVersion:
          type: string
        apiGroup:
          type: string
        collectionMode:
          type: string
          enum:
            - full
            - metadata-only
        knownCrd:
          type:
            - boolean
            - 'null'
          description: >-
            `true` identifies a known CRD with its full spec available; `false`
            identifies an unknown CRD; `null` identifies a native Kubernetes API
            resource, whose full spec is always available.
        labels:
          type: object
          additionalProperties:
            type: string
        details:
          oneOf:
            - $ref: '#/components/schemas/K8sResourceDetails'
            - type: 'null'
        enrichment:
          type: object
          additionalProperties: true
          description: >-
            Analyzer enrichment promoted from the internal persisted details
            block.
        ownershipClass:
          type:
            - string
            - 'null'
          enum:
            - system-managed
            - user-managed
            - null
        managedBy:
          type:
            - string
            - 'null'
          enum:
            - Helm
            - ArgoCD
            - Flux
            - HelmAndArgoCD
            - HelmAndFlux
            - ArgoCDAndFlux
            - HelmAndArgoCDAndFlux
            - null
        managedByName:
          type:
            - string
            - 'null'
        managedByNamespace:
          type:
            - string
            - 'null'
        helmChartName:
          type:
            - string
            - 'null'
        helmChartVersion:
          type:
            - string
            - 'null'
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
      required:
        - clusterComponentId
        - uniqueIdentifier
        - name
        - kind
        - apiVersion
        - apiGroup
        - collectionMode
        - labels
    K8sResourceDetails:
      type: object
      description: >-
        Collected manifest context. Internal persisted data is removed from API
        responses.
      additionalProperties: true
      properties:
        labels:
          type: object
          additionalProperties:
            type: string
        annotations:
          type: object
          additionalProperties:
            type: string
        annotationKeys:
          type: array
          items:
            type: string
        ownerRefs:
          type: array
          items:
            type: object
            additionalProperties: true
        management:
          $ref: '#/components/schemas/K8sResourceManagement'
        nodeInfo:
          type: object
          additionalProperties: true
        spec:
          type: object
          additionalProperties: true
    K8sResourceManagement:
      type: object
      additionalProperties: true
      properties:
        managedBy:
          type: string
          enum:
            - Helm
            - ArgoCD
            - Flux
            - HelmAndArgoCD
            - HelmAndFlux
            - ArgoCDAndFlux
            - HelmAndArgoCDAndFlux
        helm:
          type: object
          additionalProperties: true
        argocd:
          type: object
          additionalProperties: true
        flux:
          type: object
          additionalProperties: true
  responses:
    BadRequest:
      description: Bad Request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Forbidden:
      description: Forbidden
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: Not Found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    TooManyRequests:
      description: Too Many Requests
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    InternalServerError:
      description: Internal Server Error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer

````