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

# Reorder Configuration Rating Fields

> Reorders the rating input fields for a single `(companyId, entityType)`
tuple by rewriting `application_fields.rank`. The array index of each
field id in the request becomes its new `rank` (lower renders first,
`null` renders last).

This endpoint updates the UI rendering order only — it does **not**
modify rating engine revisions (`rating_engine_revisions.config`).

**Semantics — full set required:**
The provided `fieldIds` must exactly match the set of rating fields
currently defined for this `entityType`. Partial reorders, duplicate
ids, unknown ids, and missing ids are all rejected.

**Required permission:** `company:update`




## OpenAPI

````yaml /openapi/generated-external-api.yaml put /api/external/companies/{companyId}/configuration/rating/fields/rank
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/external/companies/{companyId}/configuration/rating/fields/rank:
    put:
      tags:
        - Configuration Rating Fields
      summary: Reorder Configuration Rating Fields
      description: |
        Reorders the rating input fields for a single `(companyId, entityType)`
        tuple by rewriting `application_fields.rank`. The array index of each
        field id in the request becomes its new `rank` (lower renders first,
        `null` renders last).

        This endpoint updates the UI rendering order only — it does **not**
        modify rating engine revisions (`rating_engine_revisions.config`).

        **Semantics — full set required:**
        The provided `fieldIds` must exactly match the set of rating fields
        currently defined for this `entityType`. Partial reorders, duplicate
        ids, unknown ids, and missing ids are all rejected.

        **Required permission:** `company:update`
      operationId: updateConfigurationRatingFieldsRank
      parameters:
        - $ref: '#/components/parameters/companyId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateConfigurationRatingFieldsRankRequest'
            examples:
              reorder:
                summary: Reorder three fields under `policies`
                value:
                  entityType: policies
                  fieldIds:
                    - 550e8400-e29b-41d4-a716-446655440003
                    - 550e8400-e29b-41d4-a716-446655440001
                    - 550e8400-e29b-41d4-a716-446655440002
      responses:
        '200':
          description: Rating field ranks updated successfully
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/UpdateConfigurationRatingFieldsRankResponse
              examples:
                success:
                  summary: Ranks updated
                  value:
                    updated: true
        '400':
          description: Bad Request - Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                emptyArray:
                  summary: Empty fieldIds array
                  value:
                    error:
                      code: NoFieldIdsProvided
                      message: No field ids provided
                duplicates:
                  summary: Duplicate field ids in array
                  value:
                    error:
                      code: DuplicateFieldIds
                      message: Duplicate field ids provided
                incompleteSet:
                  summary: Field ids do not match the current set for this entity type
                  value:
                    error:
                      code: IncompleteFieldIdSet
                      message: >-
                        Provided field ids do not match the set of rating fields
                        for entityType 'policies'
                invalidUuid:
                  summary: Non-UUID value in fieldIds
                  value:
                    error:
                      code: InvalidProperties
                      message: 'fieldIds: Some elements were invalid'
                      details:
                        - field: fieldIds
                          message: Some elements were invalid
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  parameters:
    companyId:
      name: companyId
      in: path
      required: true
      schema:
        type: string
        format: uuid
      description: Company identifier
  schemas:
    UpdateConfigurationRatingFieldsRankRequest:
      type: object
      description: |
        Request to reorder the rating input fields for a single
        `(companyId, entityType)` tuple.

        The array index of each field id becomes its `rank` in
        `application_fields`. The provided `fieldIds` must exactly match
        the set of rating fields currently defined for this `entityType`
        — partial reorders and unknown ids are rejected.
      required:
        - entityType
        - fieldIds
      properties:
        entityType:
          type: string
          minLength: 1
          description: |
            The rating entity type whose fields are being reordered
            (e.g., `policies`, `dealership`, `company`).
          example: policies
        fieldIds:
          type: array
          description: |
            Ordered list of rating field ids. The array index becomes the
            field's `rank` (lower renders first). Must contain no duplicates
            and must include every rating field currently defined for this
            `(companyId, entityType)` tuple — partial reorders are rejected.
          minItems: 1
          items:
            type: string
            format: uuid
          example:
            - 550e8400-e29b-41d4-a716-446655440003
            - 550e8400-e29b-41d4-a716-446655440001
            - 550e8400-e29b-41d4-a716-446655440002
    UpdateConfigurationRatingFieldsRankResponse:
      type: object
      description: Response returned after rating field ranks are updated.
      required:
        - updated
      properties:
        updated:
          type: boolean
          description: Always `true` when the request succeeded.
          example: true
    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
  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.

````