# Get all knowledge bases for a location by location Id (paginated)

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

Lists knowledge bases for a sub-account (location), with optional name search and cursor pagination.
WHEN TO USE: use this when you need to see which knowledge bases exist; use getKnowledgeBaseById for one; use createKnowledgeBase to add one.
RETURNS: a page of knowledge bases, activeCount, hasMore, and lastKnowledgeBaseId for the next page.

## Authentication

Send `Authorization: Bearer <token>` using:

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

## Parameters

### Header Parameters

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

### Query Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `locationId` | string | Yes | The location ID to retrieve knowledge bases for |
| `query` | string | No | search query for knowledge base name |
| `limit` | number | No | Maximum number of knowledge bases to return |
| `lastKnowledgeBaseId` | string | No | ID of the last knowledge base from the previous page (for pagination) |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/knowledge-bases/": {
      "get": {
        "summary": "Get all knowledge bases for a location by location Id (paginated)",
        "operationId": "getAllKnowledgeBasesForALocationByLocationIdPaginated",
        "description": "Lists knowledge bases for a sub-account (location), with optional name search and cursor pagination.\nWHEN TO USE: use this when you need to see which knowledge bases exist; use getKnowledgeBaseById for one; use createKnowledgeBase to add one.\nRETURNS: a page of knowledge bases, activeCount, hasMore, and lastKnowledgeBaseId for the next page.",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          },
          {
            "name": "locationId",
            "required": true,
            "in": "query",
            "description": "The location ID to retrieve knowledge bases for",
            "schema": {
              "example": "qIyivCmsuEOSnyoFYEej",
              "type": "string"
            }
          },
          {
            "name": "query",
            "required": false,
            "in": "query",
            "description": "search query for knowledge base name",
            "schema": {
              "example": "bot training",
              "type": "string"
            }
          },
          {
            "name": "limit",
            "required": false,
            "in": "query",
            "description": "Maximum number of knowledge bases to return",
            "schema": {
              "default": 20,
              "example": 20,
              "type": "number"
            }
          },
          {
            "name": "lastKnowledgeBaseId",
            "required": false,
            "in": "query",
            "description": "ID of the last knowledge base from the previous page (for pagination)",
            "schema": {
              "example": "ZwTB8S0yo0FIBY6OPZTD",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated knowledge bases retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetAllKnowledgeBasesPaginatedResponseDTO"
                }
              }
            }
          },
          "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.readonly"
            ]
          }
        ]
      }
    }
  },
  "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": {
      "GetAllKnowledgeBasesPaginatedResponseDTO": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "description": "Success status of the operation",
            "example": true
          },
          "data": {
            "description": "Paginated knowledge bases data",
            "example": {},
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "knowledgeBases": {
                    "description": "Array of knowledge bases",
                    "example": [
                      {
                        "id": "ZwTB8S0yo0FIBY6OPZTD",
                        "name": "My Knowledge Base",
                        "createdAt": "2025-08-02T20:26:57.057Z"
                      }
                    ],
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "description": "Knowledge base ID",
                          "example": "ZwTB8S0yo0FIBY6OPZTD"
                        },
                        "name": {
                          "type": "string",
                          "description": "Knowledge base name",
                          "example": "bot training kb"
                        },
                        "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",
                        "createdAt"
                      ],
                      "title": "KnowledgeBaseListItemDTO"
                    }
                  },
                  "activeCount": {
                    "type": "number",
                    "description": "Total count of all active knowledge bases",
                    "example": 16
                  },
                  "hasMore": {
                    "type": "boolean",
                    "description": "Whether there are more knowledge bases available",
                    "example": true
                  },
                  "lastKnowledgeBaseId": {
                    "type": "string",
                    "description": "ID of the last knowledge base in this page (use for next page request)",
                    "example": "ZwTB8S0yo0FIBY6OPZTD"
                  }
                },
                "required": [
                  "knowledgeBases",
                  "activeCount",
                  "hasMore"
                ],
                "title": "GetAllKnowledgeBasesPaginatedDataDTO"
              }
            ]
          }
        },
        "required": [
          "success",
          "data"
        ],
        "title": "GetAllKnowledgeBasesPaginatedResponseDTO"
      },
      "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 GET 'https://services.leadconnectorhq.com/knowledge-bases/?locationId=<LOCATIONID>' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3'
```

**Node.js**

```javascript
const options = {
  method: 'GET',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3'
  }
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/knowledge-bases/?locationId=<LOCATIONID>', 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"
}

params = {
    "locationId": "<LOCATIONID>"
}

response = requests.get(url, params=params, headers=headers)
print(response.json())
```

**PHP**

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

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/knowledge-bases/?locationId=<LOCATIONID>',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
  ],
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .get("https://services.leadconnectorhq.com/knowledge-bases/?locationId=<LOCATIONID>")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/knowledge-bases/?locationId=<LOCATIONID>"
  req, _ := http.NewRequest("GET", url, nil)
  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/?locationId=<LOCATIONID>")

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

request = Net::HTTP::Get.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"

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

**PowerShell**

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

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/knowledge-bases/?locationId=<LOCATIONID>' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
```
