> For the complete documentation index, see [llms.txt](https://raia2.gitbook.io/raia/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://raia2.gitbook.io/raia/dev-program/integrations-training/gitbook-greater-than-raia-agent.md).

# Gitbook -> raia Agent

<figure><img src="/files/FZ276KvDIEyNlX1BiSXG" alt=""><figcaption></figcaption></figure>

As a user of Raia Agent, I want to automatically sync content from a GitBook space into a Raia Agent as a Markdown file. This will ensure the agent has access to our most up-to-date documentation and knowledge base, allowing it to provide accurate and consistent information.

The n8n workflow should run on a nightly schedule and perform the following actions:

1. **Fetch GitBook Content:** Retrieve all pages from a specified GitBook space.
2. **Consolidate to Markdown:** Convert the fetched GitBook pages into a single, well-structured Markdown file. The Markdown file should include clear metadata, such as:
   * Space Name
   * Page Hierarchy (Table of Contents)
   * Sync Date
3. **Upload to Raia Agent:** Upload the generated Markdown file to the Raia Agent using the API.

**Acceptance Criteria:**

* An n8n workflow is created that successfully fetches all pages from a specified GitBook space.
* The workflow consolidates the content into a single Markdown file with the specified metadata.
* The workflow successfully uploads the Markdown file to the Raia Agent via the API.
* The workflow is scheduled to run every night.
* The workflow includes error handling and notifications for failed runs.

**Technical Details:**

* **GitBook API:**
  * **Authentication:** Bearer Token (`Authorization: Bearer YOUR_GITBOOK_TOKEN`)
  * **Key Endpoints:**
    * `GET /v1/orgs/{orgId}/spaces`: To list all spaces in an organization.
    * `GET /v1/spaces/{spaceId}/content`: To get the content structure of a space.
    * `GET /v1/spaces/{spaceId}/content/pages`: To list all pages in a space.
    * `GET /v1/spaces/{spaceId}/content/page/{pageId}`: To get the content of a specific page (use `format=markdown` if available).
* **Raia Agent API:**
  * **Endpoint:** `POST /external/agent-files/upload`
  * **Request Type:** `multipart/form-data`
  * **Authentication:** API Key in the header.
  * **Request Body:**
    * `file`: The Markdown file to upload.
    * `autoAddToVectorStore`: `true` (to make the content searchable by the agent).

**Implementation Notes:**

* The n8n workflow will require credentials for both the GitBook API and the Raia Agent API.
* The workflow should be designed to handle pagination when fetching the list of pages from GitBook.
* The Markdown file should be structured to maintain the hierarchy of the GitBook space for better readability.
* Consider using the GitBook API to get the space's table of contents to structure the final Markdown file.
* The workflow should be tested with a sample GitBook space before being deployed to production.


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://raia2.gitbook.io/raia/dev-program/integrations-training/gitbook-greater-than-raia-agent.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
