> ## 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.

# Create a new policy



## OpenAPI

````yaml https://api.draftt.io/swagger post /policy
openapi: 3.1.0
info:
  title: Draftt API
  version: 0.2.1
servers:
  - url: https://api.draftt.io/v1
security:
  - BearerAuth: []
paths:
  /policy:
    post:
      tags:
        - Policy
      summary: Create a new policy
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                policy:
                  $ref: '#/components/schemas/PolicyCreateInput'
              required:
                - policy
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  policy:
                    type: object
                    properties:
                      id:
                        type: string
                    required:
                      - id
                required:
                  - policy
        '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:
    PolicyCreateInput:
      type: object
      properties:
        name:
          type: string
        type:
          type: string
          enum:
            - governance
            - lifecycle
        isActive:
          type: boolean
          default: true
        resource:
          type: string
          enum:
            - component
            - certificate
        statusDefinitions:
          type: object
          description: >-
            Status definitions mapping status names to their configuration.
            Rules can filter on base fields plus dynamic details$ fields
            (format: details$.<key>$.<field>). Query GET
            /v1/schema/component/fields?key={technology} to discover available
            fields.
          additionalProperties:
            $ref: '#/components/schemas/PolicyStatusDefinition'
        description:
          type: string
        query:
          description: >-
            Query filter to pre-select which resources this policy evaluates.
            For component details$ fields (format: details$.<key>$.<field>),
            query GET /v1/schema/component/fields?key={technology} to discover
            available fields per technology.
          oneOf:
            - title: Component Query
              description: >-
                Available when resource = "component". Base fields shown;
                details$ fields are dynamic per technology.
              type: object
              properties:
                filter:
                  $ref: '#/components/schemas/ComponentPolicyQueryFilter'
            - title: Certificate Query
              description: Available when resource = "certificate"
              type: object
              properties:
                filter:
                  $ref: '#/components/schemas/CertificatePolicyQueryFilter'
      required:
        - name
        - type
        - resource
        - statusDefinitions
        - query
      examples:
        - name: Certificate not in use
          type: governance
          isActive: true
          resource: certificate
          statusDefinitions:
            Compliant:
              isDefault: true
              criticality: 10
            Non-Compliant:
              rules:
                - conditions:
                    - type: filter
                      condition:
                        filter:
                          inUse:
                            $eq: false
              criticality: 20
          description: Marks certificates that are not in use as Non-Compliant
          query: {}
        - name: Inactive Database Components
          type: governance
          isActive: true
          resource: component
          statusDefinitions:
            Active:
              isDefault: true
              criticality: 10
            Inactive:
              rules:
                - conditions:
                    - type: filter
                      condition:
                        filter:
                          technology:
                            $like: rds*
                          details$.database$.activeConnectionCount:
                            $eq: 0
              criticality: 20
          description: >-
            Identifies RDS databases with no active connections. Available
            details$ fields vary by technology - query GET
            /v1/schema/component/fields?key={technology} to discover fields.
          query:
            filter:
              technology:
                $like: rds*
    PolicyStatusDefinition:
      oneOf:
        - title: Default Status
          description: Default status definition (no rules)
          type: object
          properties:
            isDefault:
              type: boolean
              const: true
            criticality:
              type: number
              description: Status criticality level
            color:
              type: string
              description: Optional status color
          required:
            - isDefault
            - criticality
        - title: Rule-based Status
          description: Status definition with evaluation rules
          type: object
          properties:
            isDefault:
              type: boolean
              const: false
            criticality:
              type: number
              description: Status criticality level
            color:
              type: string
              description: Optional status color
            rules:
              type: array
              description: Rules to evaluate for this status
              items:
                $ref: '#/components/schemas/PolicyRule'
          required:
            - criticality
            - rules
    ComponentPolicyQueryFilter:
      type: object
      description: Component query filter - available fields for top-level query filtering
      properties:
        $and:
          type: array
          items:
            $ref: '#/components/schemas/ComponentPolicyQueryFilter'
        $or:
          type: array
          items:
            $ref: '#/components/schemas/ComponentPolicyQueryFilter'
        integrationId:
          $ref: '#/components/schemas/NumberOperatorBlock'
          description: Integration identifier
        uniqueIdentifier:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Unique resource identifier
        region:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Resource region
        vendor:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Vendor name
        vendorScopeIdentifier:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: >-
            Resource hierarchical identifier (account/project/subscription,
            etc.)
        technology:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Resource technology (e.g. AWS RDS, PostgreSQL)
        type:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Resource technology type (e.g. AWS RDS PostgreSQL)
        version:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Resource version
        name:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Resource name
        vendorCreationTime:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: The creation time of the resource
    CertificatePolicyQueryFilter:
      type: object
      description: >-
        Certificate query filter - available fields for top-level query
        filtering
      properties:
        $and:
          type: array
          items:
            $ref: '#/components/schemas/CertificatePolicyQueryFilter'
        $or:
          type: array
          items:
            $ref: '#/components/schemas/CertificatePolicyQueryFilter'
        integrationId:
          $ref: '#/components/schemas/NumberOperatorBlock'
          description: Integration identifier
        uniqueIdentifier:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Unique certificate identifier
        vendorScopeIdentifier:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Resource hierarchical identifier (account/project/subscription)
        provider:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Cloud provider
        type:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Certificate type
        status:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Certificate status
        issuer:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Certificate issuer
        keyAlgorithm:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Cryptographic key algorithm
        renewalEligibility:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Certificate renewal eligibility status
        autoRenewal:
          $ref: '#/components/schemas/BooleanOperatorBlock'
          description: >-
            Automatically renew the certificate when it is approaching
            expiration
        domainName:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Primary domain name
        domains:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: All domains covered by the certificate
        inUseBy:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Resources using this certificate
        inUse:
          $ref: '#/components/schemas/BooleanOperatorBlock'
          description: Whether the certificate is currently in use
        created:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Certificate creation date
        issuedAt:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Certificate issuance date
        validityStartDate:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Certificate validity start date
        expirationDate:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Certificate expiration date
        privateCa:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Private certificate authority
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
          required:
            - message
      required:
        - error
    PolicyRule:
      type: object
      properties:
        conditions:
          type: array
          description: Array of filter conditions for this rule
          items:
            $ref: '#/components/schemas/PolicyRuleCondition'
        prerequisites:
          type: array
          description: >-
            Optional prerequisite filters that must match before evaluating
            conditions
          items:
            type: object
            properties:
              filter:
                type: object
                description: Prerequisite filter condition
      required:
        - conditions
    NumberOperatorBlock:
      type: object
      properties:
        $eq:
          type: number
          description: Equals operator
        $ne:
          type: number
          description: Not equals operator
        $gt:
          type: number
          description: Greater than operator
        $gte:
          type: number
          description: Greater than or equal operator
        $lt:
          type: number
          description: Less than operator
        $lte:
          type: number
          description: Less than or equal operator
        $in:
          type: array
          items:
            type: number
          description: In operator
        $nin:
          type: array
          items:
            type: number
          description: Not in operator
        $exists:
          type: boolean
          description: Exists operator
      minProperties: 1
      maxProperties: 1
    StringOperatorBlock:
      type: object
      properties:
        $eq:
          type: string
          description: Equals operator
        $ne:
          type: string
          description: Not equals operator
        $gt:
          type: string
          description: Greater than operator
        $gte:
          type: string
          description: Greater than or equal operator
        $lt:
          type: string
          description: Less than operator
        $lte:
          type: string
          description: Less than or equal operator
        $like:
          type: string
          description: >-
            Like operator, wildrards are defind as `*`, for example - `{$like:
            'abc*'}` - starts with abc
        $in:
          type: array
          items:
            type: string
          description: In operator
        $nin:
          type: array
          items:
            type: string
          description: Not in operator
        $exists:
          type: boolean
          description: Exists operator
      minProperties: 1
      maxProperties: 1
    BooleanOperatorBlock:
      type: object
      properties:
        $eq:
          type: boolean
          description: Equals operator
        $ne:
          type: boolean
          description: Not equals operator
        $exists:
          type: boolean
          description: Exists operator
      minProperties: 1
      maxProperties: 1
    PolicyRuleCondition:
      type: object
      properties:
        type:
          type: string
          enum:
            - filter
          description: Condition type
        condition:
          type: object
          properties:
            filter:
              oneOf:
                - $ref: '#/components/schemas/ComponentPolicyRuleFilter'
                  title: Component Rule Filter
                  description: >-
                    Use when policy resource = "component" - includes details$
                    fields
                - $ref: '#/components/schemas/CertificatePolicyRuleFilter'
                  title: Certificate Rule Filter
                  description: Use when policy resource = "certificate"
          required:
            - filter
      required:
        - type
        - condition
    ComponentPolicyRuleFilter:
      type: object
      description: >-
        Component rule filter - includes base fields plus dynamic details$
        fields. For available details$ fields per technology/group, query: GET
        /v1/schema/component/fields?key={technology}
      properties:
        $and:
          type: array
          items:
            $ref: '#/components/schemas/ComponentPolicyRuleFilter'
        $or:
          type: array
          items:
            $ref: '#/components/schemas/ComponentPolicyRuleFilter'
        integrationId:
          $ref: '#/components/schemas/NumberOperatorBlock'
          description: Integration identifier
        uniqueIdentifier:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Unique resource identifier
        region:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Resource region
        vendor:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Vendor name
        vendorScopeIdentifier:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: >-
            Resource hierarchical identifier (account/project/subscription,
            etc.)
        technology:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Resource technology (e.g. AWS RDS, PostgreSQL)
        type:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Resource technology type (e.g. AWS RDS PostgreSQL)
        version:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Resource version
        name:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Resource name
        vendorCreationTime:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: The creation time of the resource
      additionalProperties:
        description: >-
          Dynamic details$ fields (format: details$.<key>$.<field>). Schema
          varies by component technology. Query GET
          /v1/schema/component/fields?key={technology} to discover available
          fields.
        type: object
    CertificatePolicyRuleFilter:
      type: object
      description: Certificate rule filter - available fields for status rule conditions
      properties:
        $and:
          type: array
          items:
            $ref: '#/components/schemas/CertificatePolicyRuleFilter'
        $or:
          type: array
          items:
            $ref: '#/components/schemas/CertificatePolicyRuleFilter'
        integrationId:
          $ref: '#/components/schemas/NumberOperatorBlock'
          description: Integration identifier
        uniqueIdentifier:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Unique certificate identifier
        vendorScopeIdentifier:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Resource hierarchical identifier (account/project/subscription)
        provider:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Cloud provider
        type:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Certificate type
        status:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Certificate status
        issuer:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Certificate issuer
        keyAlgorithm:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Cryptographic key algorithm
        renewalEligibility:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Certificate renewal eligibility status
        autoRenewal:
          $ref: '#/components/schemas/BooleanOperatorBlock'
          description: >-
            Automatically renew the certificate when it is approaching
            expiration
        domainName:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Primary domain name
        domains:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: All domains covered by the certificate
        inUseBy:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Resources using this certificate
        inUse:
          $ref: '#/components/schemas/BooleanOperatorBlock'
          description: Whether the certificate is currently in use
        created:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Certificate creation date
        issuedAt:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Certificate issuance date
        validityStartDate:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Certificate validity start date
        expirationDate:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Certificate expiration date
        privateCa:
          $ref: '#/components/schemas/StringOperatorBlock'
          description: Private certificate authority
  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

````