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

# Toggle Bookmark

> Add or remove bookmarks for learning paths and calendar events with a single API call

The `toggleBookmark` mutation provides a convenient way to manage user bookmarks. It automatically creates a bookmark if one doesn't exist, or removes it if it already exists, making it perfect for bookmark toggle buttons in user interfaces.

## How It Works

<Steps>
  <Step title="Check existing bookmark">
    The API checks if a bookmark already exists for the specified entity and current user.
  </Step>

  <Step title="Toggle bookmark state">
    * If bookmark does not exist: Creates a new bookmark
    * If bookmark exists: Removes the existing bookmark
  </Step>

  <Step title="Return success response">
    Returns a success response indicating the operation completed successfully.
  </Step>
</Steps>

## GraphQL Mutation

<CodeGroup>
  ```graphql Toggle Bookmark theme={null}
  mutation toggleBookmark($bookmarkData: BookmarkData!) {
    toggleBookmark(bookmarkData: $bookmarkData) {
      errors
      response
    }
  }
  ```

  ```json Variables - Learning Path theme={null}
  {
    "bookmarkData": {
      "entityId": "123",
      "entityType": "LEARNING_PATH"
    }
  }
  ```

  ```json Variables - Calendar Event theme={null}
  {
    "bookmarkData": {
      "entityId": "456",
      "entityType": "EVENT"
    }
  }
  ```
</CodeGroup>

## Parameters

| Parameter      | Type            | Description                                               |
| -------------- | --------------- | --------------------------------------------------------- |
| `bookmarkData` | `BookmarkData!` | The bookmark data containing entity information to toggle |

### BookmarkData Properties

| Field        | Type                      | Description                                                                             |
| ------------ | ------------------------- | --------------------------------------------------------------------------------------- |
| `entityId`   | `ID!`                     | The unique identifier of the entity to bookmark (learning path ID or calendar event ID) |
| `entityType` | `BookmarkableEntityType!` | The type of entity being bookmarked. Must be either `LEARNING_PATH` or `EVENT`          |

## Response

| Field      | Type          | Description                                                                 |
| ---------- | ------------- | --------------------------------------------------------------------------- |
| `errors`   | `[Violation]` | Contains any validation errors or violations encountered during the process |
| `response` | `Boolean`     | Indicates whether the bookmark toggle operation was successful              |

<RequestExample>
  ```graphql GraphQL Mutation theme={null}
  mutation toggleLearningPathBookmark {
    toggleBookmark(bookmarkData: {
      entityId: "42"
      entityType: LEARNING_PATH
    }) {
      errors
      response
    }
  }
  ```
</RequestExample>

<ResponseExample>
  ```json Successful Operation theme={null}
  {
    "data": {
      "toggleBookmark": {
        "errors": [],
        "response": true
      }
    }
  }
  ```

  ```json Error Response theme={null}
  {
    "data": {
      "toggleBookmark": {
        "errors": ["Entity not found"],
        "response": false
      }
    }
  }
  ```
</ResponseExample>
