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

# relationDefinitionById

> Gets a relation definition by its global id, archived ones included. Fails with `NotFoundError` when no relation definition has it.



**query** `relationDefinitionById(id: ID!): RelationDefinition!`

## Arguments

**`id`**: `ID!` (required)

Global id of the relation definition (`RelationDefinition.id`).

## Returns

`RelationDefinition!`

**`createdAt`**: `DateTime!`

When the relation definition was created (UTC).

---

**`createdByUser`**: `UUID!`

Id of the user who created the relation definition.

---

**`description`**: `String`

Free-text note about the relation definition.

---

**`displayCategory`**: `RelationDisplayCategory!`

Display hint for clients such as Studio. See `RelationDisplayCategory`.

---

**`endpoints`**: `EndpointsConnection`

Endpoints whose live or pending content follows the relation definition.

**Arguments:**

- `after`: `String` — Returns the elements in the list that come after the specified cursor.
- `first`: `Int` — Returns the first _n_ elements from the list.

---

**`id`**: `ID!`

Global id of the relation definition: base64 of `RelationDefinition:<raw id>`. `relationDefinitionById` and the update, delete and restore mutations take it. The raw id (e.g. `productAccessories`) is what `relationDefinitions(where: { id })`, `RelationsCriteriaInput.relationDefinitionId` and endpoint content selections use.

---

**`inUse`**: `Boolean!`

True if an endpoint or a segment uses the relation definition. While it's true, `deleteRelationDefinition` fails.

---

**`isDeleted`**: `Boolean!`

True if the relation definition is archived. `relationDefinitions` returns archived ones too and can't filter on this field, so check it in the results. `restoreRelationDefinition` restores it.

---

**`lastModified`**: `DateTime!`

When the relation definition last changed (UTC).

---

**`lastModifiedByUser`**: `UUID!`

Id of the user who last changed the relation definition.

---

**`name`**: `String!`

Name of the relation definition.

---

**`relationDefinitionStatus`**: `RelationDefinitionStatus!`

State of the relation definition. See `RelationDefinitionStatus`.

---

**`segments`**: `SegmentsConnection`

Segments whose criteria include a `relations` criterion for the relation definition.

**Arguments:**

- `after`: `String` — Returns the elements in the list that come after the specified cursor.
- `before`: `String` — Returns the elements in the list that come before the specified cursor.
- `first`: `Int` — Returns the first _n_ elements from the list.
- `last`: `Int` — Returns the last _n_ elements from the list.

---

**`sourceCardDefinition`**: `CardDefinition!`

Source card definition.

---

**`sourceCardDefinitionId`**: `ID!`

Global id of the source card definition (`CardDefinition.id`).

---

**`sourceCriteria`**: `JSON`

Criteria on the source side, as a JSON list of objects, each with an `operator`. Exactly one `dynamic` item, in `sourceCriteria` or `targetCriteria`, links the cards: `{"operator":"dynamic","sourcePropertyId":"sku","targetPropertyId":"parentSku"}` relates a source card to the target cards whose `parentSku` matches its `sku`. Other items use the search criteria shapes (e.g. `equals`) with source card property ids, and filter the source cards when the relation is followed from a target card.

---

**`sourceCriteriaPropertyIds`**: `[String!]!`

Card property ids of the source card definition that the criteria use: the `dynamic` item's `sourcePropertyId` and the property ids of the filters in `sourceCriteria`.

---

**`sourceRelationDisplayName`**: `String`

Label for the relation on the source side (e.g. `Accessories`). Null when not set.

---

**`tags`**: `[String!]!`

Labels for grouping and filtering relation definitions.

---

**`targetCardDefinition`**: `CardDefinition!`

Target card definition.

---

**`targetCardDefinitionId`**: `ID!`

Global id of the target card definition (`CardDefinition.id`).

---

**`targetCriteria`**: `JSON`

Criteria on the target side, same shape as `sourceCriteria`. Items other than the `dynamic` one filter the target cards a source card is related to, by target card property id. Example: `[{"operator":"equals","propertyId":"status","values":["Active"],"invert":false}]` keeps only target cards whose `status` is `Active`.

---

**`targetCriteriaPropertyIds`**: `[String!]!`

Card property ids of the target card definition that the criteria use: the `dynamic` item's `targetPropertyId` and the property ids of the filters in `targetCriteria`.

---

**`targetRelationDisplayName`**: `String`

Label for the relation on the target side (e.g. `Accessory of`). Null when not set.

---

**`targetRelationOrderByProperty`**: `String`

> Deprecated: Target relation order by property should be set via TargetRelationSortingConfiguration using SortingType = BasedOnTargetProperty

---

**`targetRelationSortingConfiguration`**: `RelationDefinitionSortingConfiguration`

How the target cards related to a source card are ordered. Null = no order set.

---

**`tenantId`**: `UUID!`

Id of the tenant that owns the item.

## Examples

```graphql Query
query RelationDefinitionById($id: ID!) {
  relationDefinitionById(id: $id) {
    createdAt
    createdByUser
    description
    displayCategory
    endpoints {
      edges {
        cursor
        node {
          __typename
        }
      }
      nodes {
        activeContent
        apiVersion {
          __typename
        }
        apiVersionId
        cardDefinitions {
          __typename
        }
        description
        displayName
      }
      pageInfo {
        endCursor
        hasNextPage
        hasPreviousPage
        startCursor
      }
      totalCount
    }
    id
  }
}
```

```json Variables
{
  "id": "id"
}
```

```json Response
{
  "data": {
    "relationDefinitionById": {
      "createdAt": "value",
      "createdByUser": "value",
      "description": "string",
      "displayCategory": "DEFAULT",
      "endpoints": {
        "edges": [
          {
            "cursor": "string",
            "node": {
              "__typename": "Endpoint"
            }
          }
        ],
        "nodes": [
          {
            "activeContent": "value",
            "apiVersion": {
              "__typename": "ApiVersion"
            },
            "apiVersionId": "id",
            "cardDefinitions": {
              "__typename": "CardDefinitionsConnection"
            },
            "description": "string",
            "displayName": "string"
          }
        ],
        "pageInfo": {
          "endCursor": "string",
          "hasNextPage": true,
          "hasPreviousPage": true,
          "startCursor": "string"
        },
        "totalCount": 1
      },
      "id": "id"
    }
  }
}
```


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