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

# Endorse Policy Transaction

> Applies an ENDORSE transaction to an existing policy. Endorsements modify
policy state over specified date ranges using per-field deltas. Each delta
targets a specific path within the policy data (e.g. `policy.annualPremium`,
`policy.exposures`) and can Add, Remove, or Overwrite values.

Deltas come in two flavors:

- **`deltas`** — segmented deltas for per-segment fields. Each delta
  specifies a `startDate` / `endDate` within the policy term.
- **`fullTermDeltas`** — deltas for cross-segment invariant fields
  (`fullTermPolicyBilling`, `fullTermPolicyInfo`, `fullTermPolicyRatingResponse`,
  `fullTermExposureRatingResponse`). These are applied uniformly across
  the entire policy term, so no dates are accepted — the server injects
  `policyStartDate` → `policyEndDate` automatically.

Mixing the two is a validation error: `fullTerm*` paths in `deltas` are
rejected, and non-`fullTerm*` paths in `fullTermDeltas` are rejected. At
least one of the two arrays must be non-empty.

The engine recomputes segments after applying all deltas — adjacent
segments with identical data are automatically merged. The response
includes the full set of resulting segments.

**Required permission:** `company.policy:update`




## OpenAPI

````yaml /openapi/generated-external-api.yaml post /api/v1/external/companies/{companyId}/policies/{policyId}/transaction/endorse
openapi: 3.0.3
info:
  title: AI Insurance External API
  description: External API for AI Insurance platform
  version: 1.0.0
  contact:
    email: support@aiinsurance.io
servers:
  - url: https://app.aiinsurance.io
    description: Production
security:
  - ApiKeyAuth: []
paths:
  /api/v1/external/companies/{companyId}/policies/{policyId}/transaction/endorse:
    post:
      tags:
        - Field Model Policy Transactions
      summary: Endorse Policy Transaction
      description: >
        Applies an ENDORSE transaction to an existing policy. Endorsements
        modify

        policy state over specified date ranges using per-field deltas. Each
        delta

        targets a specific path within the policy data (e.g.
        `policy.annualPremium`,

        `policy.exposures`) and can Add, Remove, or Overwrite values.


        Deltas come in two flavors:


        - **`deltas`** — segmented deltas for per-segment fields. Each delta
          specifies a `startDate` / `endDate` within the policy term.
        - **`fullTermDeltas`** — deltas for cross-segment invariant fields
          (`fullTermPolicyBilling`, `fullTermPolicyInfo`, `fullTermPolicyRatingResponse`,
          `fullTermExposureRatingResponse`). These are applied uniformly across
          the entire policy term, so no dates are accepted — the server injects
          `policyStartDate` → `policyEndDate` automatically.

        Mixing the two is a validation error: `fullTerm*` paths in `deltas` are

        rejected, and non-`fullTerm*` paths in `fullTermDeltas` are rejected. At

        least one of the two arrays must be non-empty.


        The engine recomputes segments after applying all deltas — adjacent

        segments with identical data are automatically merged. The response

        includes the full set of resulting segments.


        **Required permission:** `company.policy:update`
      operationId: endorsePolicyTransaction
      parameters:
        - $ref: '#/components/parameters/companyId'
        - $ref: '#/components/parameters/policyIdPath'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - effectiveDate
              properties:
                effectiveDate:
                  type: string
                  format: date
                  description: |
                    The effective date of the endorsement in ISO 8601 format.
                transactionTimestamp:
                  type: string
                  format: date-time
                  description: >
                    When the business decision was made. Defaults to the current
                    time if omitted.

                    Set explicitly for imports (e.g., aligning to a bordereau
                    booking date).
                deltas:
                  type: array
                  description: >
                    Per-segment deltas. Each delta specifies a date range
                    (`startDate`

                    / `endDate`) within the policy term, a path within the
                    policy data,

                    an action (Add, Remove, or Overwrite), and the new value.
                    Paths

                    targeting `fullTerm*` fields must be sent via
                    `fullTermDeltas`

                    instead.
                  items:
                    type: object
                    required:
                      - startDate
                      - endDate
                      - path
                      - action
                      - value
                    properties:
                      startDate:
                        type: string
                        format: date
                        description: >-
                          Start of the date range this delta applies to. Must be
                          `<=` endDate.
                      endDate:
                        type: string
                        format: date
                        description: End of the date range this delta applies to.
                      path:
                        type: string
                        description: >
                          Dot-delimited path into the policy data (e.g.
                          `policy.annualPremium`,

                          `policy.exposures`,
                          `policy.exposures[<uuid>].bedCount`). Must not

                          target a `fullTerm*` field — use `fullTermDeltas` for
                          those.
                      action:
                        type: string
                        enum:
                          - Add
                          - Remove
                          - Overwrite
                        description: >
                          Delta action. `Overwrite` overwrites the value at the
                          path. `Add` appends

                          to an array with set semantics (e.g. adding an
                          exposure; no-op if already present).

                          `Remove` removes matching values from a collection —
                          objects are matched by `id`,

                          primitives by equality. If the value is not present,
                          the delta is a no-op.
                      value:
                        description: >-
                          The new value to set at the path. Type depends on the
                          field.
                fullTermDeltas:
                  type: array
                  description: >
                    Cross-segment invariant deltas. Each delta targets a
                    `fullTerm*` path

                    (`policy.fullTermPolicyBilling`,
                    `policy.fullTermPolicyInfo`,

                    `policy.fullTermPolicyRatingResponse`,

                    `policy.fullTermExposureRatingResponse`). The server applies
                    each

                    delta across the entire policy term — no `startDate` /
                    `endDate` is

                    accepted. Paths not matching a `fullTerm*` prefix are
                    rejected.
                  items:
                    type: object
                    required:
                      - path
                      - action
                      - value
                    properties:
                      path:
                        type: string
                        description: |
                          Dot-delimited path into a `fullTerm*` field (e.g.
                          `policy.fullTermPolicyBilling`,
                          `policy.fullTermPolicyBilling.policyPremium`).
                      action:
                        type: string
                        enum:
                          - Add
                          - Remove
                          - Overwrite
                        description: >
                          Delta action. Same semantics as segmented deltas.
                          `Overwrite` is

                          the typical choice; `Add` / `Remove` work against list
                          fields

                          inside a `fullTerm*` object.
                      value:
                        description: The new value at the path.
            examples:
              midTermPremiumChange:
                summary: Mid-term premium adjustment
                value:
                  effectiveDate: '2025-04-01'
                  deltas:
                    - startDate: '2025-04-01'
                      endDate: '2025-12-31'
                      path: policy.annualPremium
                      action: Overwrite
                      value: 102000
                  fullTermDeltas:
                    - path: policy.fullTermPolicyBilling
                      action: Overwrite
                      value:
                        policyPremium: 102000
                        policyTaxes: 0
                        policyFees: 500
                        policyGrandTotal: 102500
              addExposure:
                summary: Add exposure mid-term
                value:
                  effectiveDate: '2025-06-01'
                  deltas:
                    - startDate: '2025-06-01'
                      endDate: '2025-12-31'
                      path: policy.exposures
                      action: Add
                      value:
                        id: 550e8400-e29b-41d4-a716-446655440020
                        exposureType: MedicalFacility
                        bedCount: 80
                  fullTermDeltas:
                    - path: policy.fullTermPolicyBilling
                      action: Overwrite
                      value:
                        policyPremium: 120000
                        policyTaxes: 0
                        policyFees: 500
                        policyGrandTotal: 120500
              withTimestamp:
                summary: Endorsement with explicit transaction timestamp
                value:
                  effectiveDate: '2025-04-01'
                  transactionTimestamp: '2025-03-28T14:30:00Z'
                  deltas:
                    - startDate: '2025-04-01'
                      endDate: '2025-12-31'
                      path: policy.customPolicyText
                      action: Overwrite
                      value: updated value
              fullTermOnly:
                summary: Billing-only endorsement (no per-segment changes)
                value:
                  effectiveDate: '2025-04-01'
                  fullTermDeltas:
                    - path: policy.fullTermPolicyBilling.policyPremium
                      action: Overwrite
                      value: 98000
                    - path: policy.fullTermPolicyBilling.policyGrandTotal
                      action: Overwrite
                      value: 98500
      responses:
        '201':
          description: Endorsement applied successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PolicyTransactionVersionResponse'
              examples:
                success:
                  summary: Endorsement transaction response
                  value:
                    policyId: 550e8400-e29b-41d4-a716-446655440001
                    policyVersion: 2
                    transactionId: 550e8400-e29b-41d4-a716-446655440030
                    startDate: '2025-01-01'
                    endDate: '2025-12-31'
                    createdAt: '2025-04-01T10:30:00.000Z'
                    fullTermPolicyInfo:
                      policyStatus: active
                      policyStartDate:
                        year: 2025
                        month: 1
                        day: 1
                        timezone: America/New_York
                      policyEndDate:
                        year: 2025
                        month: 12
                        day: 31
                        timezone: America/New_York
                      primaryInsuredId: 550e8400-e29b-41d4-a716-446655440010
                    fullTermPolicyBilling:
                      policyPremium: 102000
                      policyTaxes: 0
                      policyFees: 500
                      policyGrandTotal: 102500
                    segments:
                      - startDate: '2025-01-01'
                        endDate: '2025-03-31'
                        fieldModelV1Data:
                          policy:
                            annualPremium: 85000
                            fullTermPolicyInfo:
                              policyStatus: active
                              policyStartDate:
                                year: 2025
                                month: 1
                                day: 1
                                timezone: America/New_York
                              policyEndDate:
                                year: 2025
                                month: 12
                                day: 31
                                timezone: America/New_York
                              primaryInsuredId: 550e8400-e29b-41d4-a716-446655440010
                            fullTermPolicyBilling:
                              policyPremium: 102000
                              policyTaxes: 0
                              policyFees: 500
                              policyGrandTotal: 102500
                      - startDate: '2025-04-01'
                        endDate: '2025-12-31'
                        fieldModelV1Data:
                          policy:
                            annualPremium: 102000
                            fullTermPolicyInfo:
                              policyStatus: active
                              policyStartDate:
                                year: 2025
                                month: 1
                                day: 1
                                timezone: America/New_York
                              policyEndDate:
                                year: 2025
                                month: 12
                                day: 31
                                timezone: America/New_York
                              primaryInsuredId: 550e8400-e29b-41d4-a716-446655440010
                            fullTermPolicyBilling:
                              policyPremium: 102000
                              policyTaxes: 0
                              policyFees: 500
                              policyGrandTotal: 102500
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                emptyDeltas:
                  summary: No deltas provided
                  value:
                    error:
                      code: InvalidRequest
                      message: At least one delta is required
                noExistingVersion:
                  summary: Policy has no NEW_BUSINESS transaction
                  value:
                    error:
                      code: InvalidRequest
                      message: >-
                        Policy has no existing version — NEW_BUSINESS must be
                        created first
                deltaOutsidePolicyPeriod:
                  summary: Delta date range outside policy term
                  value:
                    error:
                      code: InvalidDelta
                      message: >-
                        Delta date range [2026-06-01, 2026-12-31] falls outside
                        policy period [2025-01-01, 2025-12-31]
                deltaStartAfterEnd:
                  summary: Delta startDate after endDate
                  value:
                    error:
                      code: InvalidDelta
                      message: >-
                        Delta startDate (2025-12-31) must be <= endDate
                        (2025-01-01)
                fullTermPathInDeltas:
                  summary: fullTerm path sent via deltas
                  value:
                    error:
                      code: InvalidDelta
                      message: >-
                        Invalid deltas path
                        "policy.fullTermPolicyBilling.policyPremium" — fullTerm
                        paths must be sent via fullTermDeltas, not deltas
                nonFullTermPathInFullTermDeltas:
                  summary: Non-fullTerm path sent via fullTermDeltas
                  value:
                    error:
                      code: InvalidDelta
                      message: >-
                        Invalid fullTermDeltas path "policy.customPolicyText" —
                        must target one of: policy.fullTermPolicyBilling,
                        policy.fullTermPolicyInfo,
                        policy.fullTermPolicyRatingResponse,
                        policy.fullTermExposureRatingResponse
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          description: Policy not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                policyNotFound:
                  summary: Policy does not exist
                  value:
                    error:
                      code: NOT_FOUND
                      message: Policy 550e8400-e29b-41d4-a716-446655440099 not found
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  parameters:
    companyId:
      name: companyId
      in: path
      required: true
      schema:
        type: string
        format: uuid
      description: Company identifier
    policyIdPath:
      name: policyId
      in: path
      required: true
      schema:
        type: string
        format: uuid
      description: Policy identifier
  schemas:
    PolicyTransactionVersionResponse:
      type: object
      description: >
        Response returned by policy transaction endpoints. Contains the policy
        version

        produced by the transaction, including all derived segments.
      required:
        - policyId
        - policyVersion
        - transactionId
        - startDate
        - endDate
        - createdAt
        - segments
      properties:
        policyId:
          type: string
          format: uuid
          description: Policy identifier
        policyVersion:
          type: integer
          description: Sequential version number produced by this transaction
        transactionId:
          type: string
          format: uuid
          description: Identifier of the transaction that produced this version
        startDate:
          type: string
          format: date
          description: Policy term start date (ISO 8601)
        endDate:
          type: string
          format: date
          description: Policy term end date (ISO 8601)
        createdAt:
          type: string
          format: date-time
          description: When the transaction was created (ISO 8601)
        fullTermPolicyInfo:
          type: object
          nullable: true
          description: >
            Full-term policy information. Contains policy status, term dates,
            and primary insured reference.
          additionalProperties: true
        fullTermPolicyBilling:
          type: object
          nullable: true
          description: >
            Full-term billing aggregates. Contains premium, taxes, fees, and
            grand total for the full policy term.
          additionalProperties: true
        segments:
          type: array
          description: >
            Derived segments for this policy version. Each segment represents a
            maximal contiguous

            date range where policy state is identical. Adjacent segments with
            identical data are

            automatically merged.
          items:
            $ref: '#/components/schemas/PolicyTransactionSegmentResponse'
    ErrorResponse:
      type: object
      description: Standard error response for all external API endpoints
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              description: Machine-readable error code
              example: VALIDATION_ERROR
            message:
              type: string
              description: Human-readable error message
              example: 'submissionId: Required field is missing'
            details:
              type: array
              description: Additional details for validation errors (field-level errors)
              items:
                type: object
                properties:
                  field:
                    type: string
                    description: The field that caused the error
                    example: submissionId
                  message:
                    type: string
                    description: Description of the field error
                    example: Required field is missing
    PolicyTransactionSegmentResponse:
      type: object
      description: >
        A derived policy segment representing a date range where policy state is
        identical.

        Contains the full policy data (policy-level fields and nested exposures)
        for this period.
      required:
        - startDate
        - endDate
        - fieldModelV1Data
      properties:
        startDate:
          type: string
          format: date
          description: Segment start date (ISO 8601)
        endDate:
          type: string
          format: date
          description: Segment end date (ISO 8601)
        fieldModelV1Data:
          type: object
          description: >
            Policy state for this segment. Contains a `policy` key with
            policy-level fields

            and a nested `exposures` array.
          properties:
            policy:
              type: object
              description: Policy-level fields and nested exposures for this segment.
              additionalProperties: true
          additionalProperties: true
  responses:
    Unauthorized:
      description: Unauthorized - Invalid or missing API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            missingApiKey:
              summary: Missing API key
              value:
                error:
                  code: UNAUTHORIZED
                  message: Authorization header is required
            bearerTokenNotAllowed:
              summary: Bearer token used instead of API key
              value:
                error:
                  code: UNAUTHORIZED
                  message: External API endpoints require API key authentication
    Forbidden:
      description: Forbidden - Insufficient permissions
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            insufficientPermissions:
              summary: Insufficient permissions
              value:
                error:
                  code: FORBIDDEN
                  message: Insufficient permissions to perform this action
    InternalServerError:
      description: Internal Server Error - Unexpected error occurred
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            internalError:
              summary: Unexpected server error
              value:
                error:
                  code: INTERNAL_ERROR
                  message: An unexpected error occurred. Please try again later.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        API key authentication. Include your API key in the Authorization
        header.

````