---
title: "Map Knowledge Base Collection"
method: POST
path: "/knowledge-bases/{kbId}/map"
tags: ["Knowledge Base"]
---

# Map Knowledge Base Collection

`POST /knowledge-bases/{kbId}/map`

## Request

- Base URL: `https://api.speakai.co/v1`
- URL: `https://api.speakai.co/v1/knowledge-bases/{kbId}/map`
- Auth: API key in header `x-speakai-key` and API key in header `x-access-token`

### Attach a Collection

Requires the OWNER or ADMIN role. Attaches this collection to a folder or agent, so retrieval actually uses it -- a collection with no mapping is created but inert. Idempotent: mapping the same (collection, owner) pair again returns the existing row rather than erroring. ownerType cannot be automation here -- an automation's collection is set on its own AI step, not through this endpoint; see Get Collection Owners for how that link is surfaced instead.

## Path parameters

- `kbId` string, required

## Request body

- object
  - `ownerType` 'folder' | 'agent', required
  - `ownerId` string, required

## Response `200`

OK

- object
  - `status` 'success'
  - `data` object
    - `knowledgeBaseId` string
    - `ownerType` 'folder' | 'agent': Never automation here: an automation's collection lives on its own AI step, not a mapping row -- see GET .../owners for how an automation link is surfaced instead.
    - `ownerId` string
    - `createdAt` string, date-time

## Other responses

- `400`: Bad Request
- `403`: Forbidden
- `404`: Not Found

---

[API](https://skmtc.dev/speakai/apis/speak-ai-api.md) · [All operations](https://skmtc.dev/speakai/apis/speak-ai-api/llms.txt) · [OpenAPI document](https://skmtc.dev/speakai/apis/speak-ai-api/revisions/52d777e6d46e?raw)
