> For the complete documentation index, see [llms.txt](https://docs.horizon.ipaper.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.horizon.ipaper.io/horizon-api/methods-and-events/chapter-legacy-campaigns.md).

# Chapter (legacy campaigns)

### `getChapter`

Get a specific chapter by providing a chapter `guid`. The function is executed asynchronously. Returns an `ILeafletChapter`.

```javascript
const chapter = await api.chapter.getChapter(chapterGuid);
console.log('Chapter', chapter);
```

`ILeafletChapter`

<table><thead><tr><th width="307">Property</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>$type</td><td><code>'chapter'</code></td><td>content type</td></tr><tr><td>chapterGuid</td><td><code>string</code></td><td>the unique chapter guid</td></tr><tr><td>title</td><td><code>string</code> (optional)</td><td>title of the chapter</td></tr><tr><td>excludeFromTableOfContents</td><td><code>boolean</code></td><td>whether the chapter should be excluded from the table of contents</td></tr></tbody></table>

### `getChapters`

Get all chapters in the experience. Returns an array of `ILeafletChapter`.

```javascript
const chapters = api.chapter.getChapters();
console.log('Chapters', chapters);
```

`ILeafletChapter`

<table><thead><tr><th width="307">Property</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>$type</td><td><code>'chapter'</code></td><td>content type</td></tr><tr><td>chapterGuid</td><td><code>string</code></td><td>the unique chapter guid</td></tr><tr><td>title</td><td><code>string</code> (optional)</td><td>title of the chapter</td></tr><tr><td>excludeFromTableOfContents</td><td><code>boolean</code></td><td>whether the chapter should be excluded from the table of contents</td></tr></tbody></table>

### `getChapterElement`

Get a specific chapter element by providing a chapter `guid`. Returns an `HTMLElement`.

```javascript
const element = api.chapter.getChapterElement(chapterGuid);
console.log('Element', element);
```

### `getChaptersInView`

Get all chapters currently in view. Returns an array of `ILeafletChapter`

```javascript
const inView = api.chapter.getChaptersInView();
console.log('In view', inView);
```

`ILeafletChapter`

<table><thead><tr><th width="307">Property</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>$type</td><td><code>'chapter'</code></td><td>content type</td></tr><tr><td>chapterGuid</td><td><code>string</code></td><td>the unique chapter guid</td></tr><tr><td>title</td><td><code>string</code> (optional)</td><td>title of the chapter</td></tr><tr><td>excludeFromTableOfContents</td><td><code>boolean</code></td><td>whether the chapter should be excluded from the table of contents</td></tr></tbody></table>

***

## Subscription events

The following events can be subscribed to in order to execute code when they occur. The code that should be executed is passed as a callback function when subscribing. You can set up multiple subscriptions to the same event.

These can be very useful f.ex. for tracking with Google Analytics, etc.

### `subscribe`

Subscribe to chapters entering the viewport.

```javascript
api.chapter.subscribe((chapterEvent) => {
    // your code
});
```

`chapterEvent`

| Property | Type                           | Description                           |
| -------- | ------------------------------ | ------------------------------------- |
| action   | `'viewEnter'` \| `'viewLeave'` | name of the event action that occured |
| source   | `undefined`                    | property not in use                   |
| value    | `ILeafletChapter`              | the chapter the event occured for     |

`ILeafletChapter`

<table><thead><tr><th width="307">Property</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>$type</td><td><code>'chapter'</code></td><td>content type</td></tr><tr><td>chapterGuid</td><td><code>string</code></td><td>the unique chapter guid</td></tr><tr><td>title</td><td><code>string</code> (optional)</td><td>title of the chapter</td></tr><tr><td>excludeFromTableOfContents</td><td><code>boolean</code></td><td>whether the chapter should be excluded from the table of contents</td></tr></tbody></table>

### `unsubscribe`

In addition, when you set up a subscription you will get an `unsubscribe` function returned which can be used to cancel the subscription at any time. For example:

```javascript
let mySubscription = api.chapters.subscribe((chapterEvent) => {
    // your code
});

mySubscription.unsubscribe();
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.horizon.ipaper.io/horizon-api/methods-and-events/chapter-legacy-campaigns.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
