# Zendesk -> raia Agent

As a user of Raia Agent, I want to automatically sync our Zendesk Help Center articles into a Raia Agent as a Markdown file. This will provide the agent with our complete knowledge base, enabling it to deliver accurate and up-to-date support to our customers.

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

1. **Fetch Help Center Articles:** Retrieve all articles from our Zendesk Help Center.
2. **Consolidate to Markdown:** Convert the fetched articles into a single, well-structured Markdown file. The file should include:
   * A title and introduction for the knowledge base document.
   * A table of contents organized by category and section.
   * The content of each article, including its title, body (converted from HTML to Markdown), labels, and a link to the original article.
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 articles from the Zendesk Help Center.
* The workflow consolidates the articles into a single Markdown file with a clear, hierarchical structure.
* 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 robust error handling and notifications for failed runs.

**Technical Details:**

* **Zendesk API:**
  * **Authentication:** Basic Authentication using email and API token (`{email_address}/token:{api_token}`).
  * **Endpoint:** `GET https://{subdomain}.zendesk.com/api/v2/help_center/articles.json`
  * **Note:** The `{subdomain}` needs to be configured.
  * The workflow must handle pagination to retrieve all articles.
  * The article `body` is in HTML and needs to be converted to Markdown.
* **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 Zendesk API (subdomain, email, API token) and the Raia Agent API.
* To create a structured table of contents, the workflow should also fetch categories and sections from the Zendesk API.
* Consider using the incremental articles endpoint (`/api/v2/help_center/incremental/articles?start_time={start_time}`) for more efficient daily syncs after the initial full sync.
* The workflow should be tested with a sample of articles before being deployed to production.
