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

# Create a relation definition

> Creates a relation definition between two `Active` card definitions. The links between cards are built in the background: `status` is `Initializing` until that finishes, so read the relation definition until it is `Active`. 400: an unknown card definition or card property. 409: the id is taken.



## OpenAPI

````yaml /api-reference/openapi/configuration.json post /v1/relation-definitions
openapi: 3.2.0
info:
  title: Configuration API
  description: >-
    Manages applications, sources, source properties, source folders, managed
    tags and their values, card definitions, their segments and relation
    definitions; manages destinations, their versions and endpoints, and
    publishes versions; and authors, previews and activates card lifecycles.
    Card property changes are saved as pending changes and take effect when the
    card definition is activated. Source property changes and source deletion
    can finish asynchronously. The tenant comes from the access token.
    Successful responses return the resource itself; lists return a page with
    `items`, the `after` cursor for the next page and, when asked for,
    `totalCount` (`limit` default 50, max 200; lifecycle lists default 25, max
    100). Application updates replace the settings and need the latest `etag`;
    secrets are returned only when created. Errors are problem details
    (`application/problem+json`). Values are PascalCase in REST and UPPER_CASE
    in GraphQL.
  version: 1.0.0
servers:
  - url: https://api.occtoo.com
security: []
tags:
  - name: Applications
  - name: Card definitions
  - name: Card exports
  - name: Destination endpoints
  - name: Destination versions
  - name: Destinations
  - name: Languages
  - name: Lifecycles
  - name: Managed tag values
  - name: Managed tags
  - name: Relation definitions
  - name: Segments
  - name: Sources
paths:
  /v1/relation-definitions:
    post:
      tags:
        - Relation definitions
      summary: Create a relation definition
      description: >-
        Creates a relation definition between two `Active` card definitions. The
        links between cards are built in the background: `status` is
        `Initializing` until that finishes, so read the relation definition
        until it is `Active`. 400: an unknown card definition or card property.
        409: the id is taken.
      operationId: CreateRelationDefinition
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateRelationDefinitionRequest'
        required: true
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RelationDefinitionResponse'
        '400':
          description: Bad Request
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/HttpValidationProblemDetails'
        '401':
          description: Unauthorized
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ProblemDetails'
        '403':
          description: Forbidden
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ProblemDetails'
        '404':
          description: Not Found
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ProblemDetails'
        '409':
          description: Conflict
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ProblemDetails'
        '429':
          description: Too Many Requests
          headers:
            Retry-After:
              description: Number of seconds to wait before retrying.
              schema:
                minimum: 1
                type: integer
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ProblemDetails'
        '500':
          description: Internal Server Error
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ProblemDetails'
      security:
        - kindeOAuth: []
        - bearerAuth: []
        - apiKey: []
components:
  schemas:
    CreateRelationDefinitionRequest:
      required:
        - id
        - name
        - sourceCardId
        - targetCardId
        - match
      type: object
      properties:
        id:
          type: string
          description: >-
            Starts with a lowercase letter, then letters and digits (e.g.
            `productVariants`). It can't match a card property id of either card
            definition. Immutable.
        name:
          type: string
          description: Name of the relation definition.
        sourceCardId:
          type: string
          description: >-
            Raw id of the source card definition (e.g. `products`). It must be
            `Active` and differ from `targetCardId`. Immutable.
        targetCardId:
          type: string
          description: >-
            Raw id of the target card definition (e.g. `variants`). It must be
            `Active`. Immutable.
        match:
          $ref: '#/components/schemas/RelationMatch'
          description: >-
            The card properties whose values link a source card to its target
            cards. Both must be indexed `Text` or `List` card properties (not
            both `List`, no format-only conversions) or `id`.
        description:
          type:
            - 'null'
            - string
          description: Free-text note about the relation definition.
        tags:
          type:
            - 'null'
            - array
          items:
            type: string
          description: Labels for grouping and filtering relation definitions.
        sourceDisplayName:
          type:
            - 'null'
            - string
          description: Label for the relation on the source side, up to 255 characters.
        targetDisplayName:
          type:
            - 'null'
            - string
          description: Label for the relation on the target side, up to 255 characters.
        order:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/RelationOrder'
              description: >-
                How the target cards related to a source card are ordered.
                Omitted = no order.
          description: >-
            How the target cards related to a source card are ordered. Omitted =
            no order.
      description: Holds a new relation definition.
    RelationDefinitionResponse:
      required:
        - id
        - name
        - description
        - tags
        - sourceCardId
        - targetCardId
        - match
        - sourceDisplayName
        - targetDisplayName
        - order
        - status
        - createdAt
        - updatedAt
      type: object
      properties:
        id:
          type: string
          description: >-
            Raw id of the relation definition (e.g. `productVariants`). Use with
            `/v1/relation-definitions/{relationId}`.
        name:
          type: string
          description: Name of the relation definition.
        description:
          type:
            - 'null'
            - string
          description: Free-text note about the relation definition.
        tags:
          type: array
          items:
            type: string
          description: Labels for grouping and filtering relation definitions.
        sourceCardId:
          type: string
          description: Raw id of the source card definition (e.g. `products`).
        targetCardId:
          type: string
          description: Raw id of the target card definition (e.g. `variants`).
        match:
          $ref: '#/components/schemas/RelationMatch'
          description: >-
            The card properties whose values link a source card to its target
            cards.
        sourceDisplayName:
          type:
            - 'null'
            - string
          description: >-
            Label for the relation on the source side (e.g. `Variants`). Null
            when not set.
        targetDisplayName:
          type:
            - 'null'
            - string
          description: >-
            Label for the relation on the target side (e.g. `Variant of`). Null
            when not set.
        order:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/RelationOrder'
              description: >-
                How the target cards related to a source card are ordered. Null
                = no order set.
          description: >-
            How the target cards related to a source card are ordered. Null = no
            order set.
        status:
          $ref: '#/components/schemas/RelationDefinitionStatus'
          description: >-
            Whether the links between cards are built. See
            `RelationDefinitionStatus`.
        createdAt:
          type: string
          description: When the relation definition was created (UTC).
          format: date-time
        updatedAt:
          type: string
          description: When the relation definition last changed (UTC).
          format: date-time
      description: >-
        Links the cards of two card definitions, a source and a target. Segments
        (`relation` in `where`) and destination endpoints (relation content)
        follow relation definitions by id.
    HttpValidationProblemDetails:
      type: object
      properties:
        type:
          type:
            - 'null'
            - string
        title:
          type:
            - 'null'
            - string
        status:
          pattern: ^-?(?:0|[1-9]\d*)$
          type:
            - 'null'
            - integer
            - string
          format: int32
        detail:
          type:
            - 'null'
            - string
        instance:
          type:
            - 'null'
            - string
        errors:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
    ProblemDetails:
      type: object
      properties:
        type:
          type:
            - 'null'
            - string
        title:
          type:
            - 'null'
            - string
        status:
          pattern: ^-?(?:0|[1-9]\d*)$
          type:
            - 'null'
            - integer
            - string
          format: int32
        detail:
          type:
            - 'null'
            - string
        instance:
          type:
            - 'null'
            - string
    RelationMatch:
      required:
        - sourceProperty
        - targetProperty
      type: object
      properties:
        sourceProperty:
          type: string
          description: >-
            Card property id of the source card definition (e.g. `sku`), or `id`
            for the card id.
        targetProperty:
          type: string
          description: >-
            Card property id of the target card definition (e.g. `parentSku`),
            or `id` for the card id.
      description: >-
        Names the card property of each side whose values link the cards: a
        source card is related to the target cards whose value matches its own.
    RelationOrder:
      required:
        - type
        - property
      type: object
      properties:
        type:
          $ref: '#/components/schemas/RelationDefinitionTargetSortingType'
          description: What sets the order. See `RelationDefinitionTargetSortingType`.
        property:
          type: string
          description: >-
            Card property that sets the order. With `BasedOnTargetProperty`, a
            `Decimal` or `Integer` card property of the target card definition.
            With `BasedOnSourceProperty`, a `List` card property of the source
            card definition.
        targetMatchProperty:
          type:
            - 'null'
            - string
          description: >-
            With `BasedOnSourceProperty`, the target card property whose value
            is looked up in the source list. Null = `match.targetProperty`. Must
            be null with `BasedOnTargetProperty`.
      description: Sets how the target cards related to a source card are ordered.
    RelationDefinitionStatus:
      enum:
        - Initializing
        - Updating
        - Active
      description: Tracks whether a relation definition's links between cards are built.
      x-enum-descriptions:
        Initializing: >-
          In progress: the relation definition was just created and its related
          cards are being indexed. It turns `ACTIVE` when that finishes.
        Updating: >-
          In progress: `updateRelationDefinition` changed the criteria and the
          related cards are being indexed again. It turns `ACTIVE` when that
          finishes.
        Active: >-
          Live: the related cards are indexed. Only in this state can the
          criteria change.
    RelationDefinitionTargetSortingType:
      enum:
        - BasedOnTargetProperty
        - BasedOnSourceProperty
      description: Sets what orders the target cards related to a source card.
      x-enum-descriptions:
        BasedOnTargetProperty: >-
          Ordered by a number on each target card: `propertyId` is a `DECIMAL`
          or `INTEGER` target card property.
        BasedOnSourceProperty: >-
          Ordered as the values of a `LIST` card property on the source card
          (`propertyId`), each matched to a target card through
          `targetMatchPropertyId`.
  securitySchemes:
    kindeOAuth:
      type: oauth2
      description: >-
        Sign in with the existing Occtoo Studio identity and selected
        organization.
      flows:
        authorizationCode:
          authorizationUrl: >-
            https://auth.occtoo.com/oauth2/auth?audience=https%3A%2F%2Fapi-weu.occtoo.com
          tokenUrl: https://auth.occtoo.com/oauth2/token
          scopes:
            openid: Authenticate the user with OpenID Connect.
            profile: Read the user's basic profile.
            email: Read the user's email address.
            offline: Refresh the access token without another interactive sign-in.
          x-usePkce: SHA-256
          x-scalar-redirect-uri: https://api.occtoo.com/docs/
    bearerAuth:
      type: http
      description: >-
        Tenant-scoped Occtoo access token, including Kinde machine-to-machine
        application tokens.
      scheme: bearer
      bearerFormat: JWT
    apiKey:
      type: apiKey
      description: Occtoo organization API key.
      name: x-api-key
      in: header

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.