# Create a new knowledge base (max 15 knowledge bases per location)

POST https://services.leadconnectorhq.com/knowledge-bases/

Creates a new knowledge base for a location (maximum 15 per location).
WHEN TO USE: use this when you need to add a brand-new knowledge source; use updateKnowledgeBase to rename one; use create (FAQs) or trainDiscoveredUrls to add content.
RETURNS: success and the created knowledge base, including its server-assigned id.

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `knowledge-bases.write`

## Parameters

### Header Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Version` | string | Yes | API Version |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/knowledge-bases/": {
      "post": {
        "summary": "Create a new knowledge base (max 15 knowledge bases per location)",
        "operationId": "createANewKnowledgeBaseMax15KnowledgeBasesPerLocation",
        "description": "Creates a new knowledge base for a location (maximum 15 per location).\nWHEN TO USE: use this when you need to add a brand-new knowledge source; use updateKnowledgeBase to rename one; use create (FAQs) or trainDiscoveredUrls to add content.\nRETURNS: success and the created knowledge base, including its server-assigned id.",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateKnowledgeBaseDTO"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Knowledge base created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateKnowledgeBaseResponseDTO"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "Location-Access": [
              "knowledge-bases.write"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account.",
        "type": "http"
      },
      "Agency-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency (OR) Private Integration Token of Agency.",
        "type": "http"
      },
      "Agency-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency.",
        "type": "http"
      }
    },
    "schemas": {
      "CreateKnowledgeBaseDTO": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "Name of the knowledge base",
            "example": "My Knowledge Base"
          },
          "description": {
            "type": "string",
            "description": "Optional description of the knowledge base",
            "example": "A knowledge base for customer support FAQs"
          },
          "locationId": {
            "type": "string",
            "description": "The location ID this knowledge base belongs to",
            "example": "qIyivCmsuEOSnyoFYEej"
          }
        },
        "required": [
          "name",
          "locationId"
        ],
        "title": "CreateKnowledgeBaseDTO"
      },
      "CreateKnowledgeBaseResponseDTO": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "description": "Success status of the operation",
            "example": true
          },
          "data": {
            "description": "Created knowledge base details",
            "example": {},
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "description": "Knowledge base ID",
                    "example": "ZwTB8S0yo0FIBY6OPZTD"
                  },
                  "name": {
                    "type": "string",
                    "description": "Knowledge base name",
                    "example": "KB for Bot Training"
                  },
                  "nameLowerCase": {
                    "type": "string",
                    "description": "Knowledge base name in lowercase",
                    "example": "kb for bot training"
                  },
                  "locationId": {
                    "type": "string",
                    "description": "Location ID",
                    "example": "qIyivCmsuEOSnyoFYEej"
                  },
                  "kbMetadata": {
                    "type": "object",
                    "description": "Knowledge base metadata",
                    "example": {},
                    "readOnly": true
                  },
                  "deleted": {
                    "type": "boolean",
                    "description": "Whether the knowledge base is deleted",
                    "example": false
                  },
                  "createdAt": {
                    "type": "string",
                    "description": "Date when knowledge base was created",
                    "example": "2025-08-02T20:26:57.057Z"
                  },
                  "updatedAt": {
                    "type": "string",
                    "description": "Date when knowledge base was last updated",
                    "example": "2025-08-02T20:26:57.057Z"
                  }
                },
                "required": [
                  "id",
                  "name",
                  "nameLowerCase",
                  "locationId",
                  "kbMetadata",
                  "deleted",
                  "createdAt",
                  "updatedAt"
                ],
                "title": "KnowledgeBaseDataDTO"
              }
            ]
          }
        },
        "required": [
          "success",
          "data"
        ],
        "title": "CreateKnowledgeBaseResponseDTO"
      },
      "BadRequestDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 400
          },
          "message": {
            "type": "string",
            "example": "Bad Request"
          }
        },
        "title": "BadRequestDTO"
      },
      "UnauthorizedDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 401
          },
          "message": {
            "type": "string",
            "example": "Invalid token: access token is invalid"
          },
          "error": {
            "type": "string",
            "example": "Unauthorized"
          }
        },
        "title": "UnauthorizedDTO"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X POST 'https://services.leadconnectorhq.com/knowledge-bases/' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "name": "My Knowledge Base",
  "description": "A knowledge base for customer support FAQs",
  "locationId": "qIyivCmsuEOSnyoFYEej"
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "name": "My Knowledge Base",
      "description": "A knowledge base for customer support FAQs",
      "locationId": "qIyivCmsuEOSnyoFYEej"
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/knowledge-bases/', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/knowledge-bases/"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "v3"
}

payload = {
    "name": "My Knowledge Base",
    "description": "A knowledge base for customer support FAQs",
    "locationId": "qIyivCmsuEOSnyoFYEej"
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())
```

**PHP**

```php
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/knowledge-bases/',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "name": "My Knowledge Base",
  "description": "A knowledge base for customer support FAQs",
  "locationId": "qIyivCmsuEOSnyoFYEej"
}',
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

**Java**

```java
HttpResponse<String> response = Unirest
  .post("https://services.leadconnectorhq.com/knowledge-bases/")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"name\":\"My Knowledge Base\",\"description\":\"A knowledge base for customer support FAQs\",\"locationId\":\"qIyivCmsuEOSnyoFYEej\"}")
  .asString();
```

**Go**

```go
package main

import (
  "fmt"
  "net/http"
  "io"
  "strings"
)

func main() {
  url := "https://services.leadconnectorhq.com/knowledge-bases/"
  payload := strings.NewReader(`{
  "name": "My Knowledge Base",
  "description": "A knowledge base for customer support FAQs",
  "locationId": "qIyivCmsuEOSnyoFYEej"
}`)
  req, _ := http.NewRequest("POST", url, payload)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "v3")

  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)
  fmt.Println(string(body))
}
```

**Ruby**

```ruby
require 'uri'
require 'net/http'

url = URI("https://services.leadconnectorhq.com/knowledge-bases/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"
request["Content-Type"] = "application/json"
request.body = '{
  "name": "My Knowledge Base",
  "description": "A knowledge base for customer support FAQs",
  "locationId": "qIyivCmsuEOSnyoFYEej"
}'

response = http.request(request)
puts response.read_body
```

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "v3"
}

$body = '{
  "name": "My Knowledge Base",
  "description": "A knowledge base for customer support FAQs",
  "locationId": "qIyivCmsuEOSnyoFYEej"
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/knowledge-bases/' -Method 'POST' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
