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

# Add Custom Object Relationship

> Links a custom object to a target entity via a relationship field. Use
the `fieldRefId` from the
[Get Configuration](/api-reference/field-model/custom-objects/get-custom-object-configuration)
endpoint.

**Cardinality behavior:**

- **one_to_one**: Replaces any existing link from this object *and* any
  existing link to the target. Each side can have at most one link.
- **one_to_many**: Replaces any existing link from this object (the "one"
  side), but the target (the "many" side) can have multiple links.
- **many_to_one**: Appends the link. The source (the "many" side) can
  have multiple links, but existing links to the target from other
  sources on the "one" side are replaced.
- **many_to_many**: Appends the link. Both sides can have multiple links.

If the exact same link already exists, the operation is idempotent and
returns `created: false`.

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




## OpenAPI

````yaml /openapi/generated-external-api.yaml put /api/v1/external/companies/{companyId}/custom-objects/{objectType}/{objectId}/relationships/{fieldRefId}/{targetId}
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}/custom-objects/{objectType}/{objectId}/relationships/{fieldRefId}/{targetId}:
    put:
      tags:
        - Field Model Custom Objects
      summary: Add Custom Object Relationship
      description: >
        Links a custom object to a target entity via a relationship field. Use

        the `fieldRefId` from the

        [Get
        Configuration](/api-reference/field-model/custom-objects/get-custom-object-configuration)

        endpoint.


        **Cardinality behavior:**


        - **one_to_one**: Replaces any existing link from this object *and* any
          existing link to the target. Each side can have at most one link.
        - **one_to_many**: Replaces any existing link from this object (the
        "one"
          side), but the target (the "many" side) can have multiple links.
        - **many_to_one**: Appends the link. The source (the "many" side) can
          have multiple links, but existing links to the target from other
          sources on the "one" side are replaced.
        - **many_to_many**: Appends the link. Both sides can have multiple
        links.


        If the exact same link already exists, the operation is idempotent and

        returns `created: false`.


        **Required permission:** `company.fmv1_custom_object:update`
      operationId: addCustomObjectRelationship
      parameters:
        - $ref: '#/components/parameters/companyId'
        - $ref: '#/components/parameters/objectType'
        - $ref: '#/components/parameters/objectId'
        - $ref: '#/components/parameters/fieldRefId'
        - $ref: '#/components/parameters/targetId'
      responses:
        '200':
          description: Relationship added (or already existed)
          content:
            application/json:
              schema:
                type: object
                properties:
                  objectId:
                    type: string
                    format: uuid
                    description: The source custom object ID
                  fieldRefId:
                    type: string
                    description: The relationship field reference ID
                  targetId:
                    type: string
                    format: uuid
                    description: The target entity ID
                  created:
                    type: boolean
                    description: |
                      `true` if a new link was created, `false` if the exact
                      link already existed.
              examples:
                created:
                  summary: New relationship created
                  value:
                    objectId: 550e8400-e29b-41d4-a716-446655440020
                    fieldRefId: ownerExposure
                    targetId: 550e8400-e29b-41d4-a716-446655440200
                    created: true
                alreadyExists:
                  summary: Relationship already existed
                  value:
                    objectId: 550e8400-e29b-41d4-a716-446655440020
                    fieldRefId: ownerExposure
                    targetId: 550e8400-e29b-41d4-a716-446655440200
                    created: false
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          description: Source or target entity not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                sourceNotFound:
                  summary: Source custom object not found
                  value:
                    error:
                      code: NOT_FOUND
                      message: Custom object not found
                targetNotFound:
                  summary: Target entity not found
                  value:
                    error:
                      code: NOT_FOUND
                      message: >-
                        Target entity '550e8400-e29b-41d4-a716-446655440999' of
                        type 'exposure' not found
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  parameters:
    companyId:
      name: companyId
      in: path
      required: true
      schema:
        type: string
        format: uuid
      description: Company identifier
    objectType:
      name: objectType
      in: path
      required: true
      schema:
        type: string
      description: >-
        Custom object type in snake_case format (e.g., `vehicle`,
        `building_info`)
    objectId:
      name: objectId
      in: path
      required: true
      schema:
        type: string
        format: uuid
      description: Custom object identifier
    fieldRefId:
      name: fieldRefId
      in: path
      required: true
      schema:
        type: string
      description: Relationship field reference ID from the configuration endpoint
    targetId:
      name: targetId
      in: path
      required: true
      schema:
        type: string
        format: uuid
      description: Target custom object identifier to link or unlink
  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.
  schemas:
    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
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        API key authentication. Include your API key in the Authorization
        header.

````