# Uploads a file to knowledge base (max file size: 10MB)

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

Uploads a PDF, DOC, or DOCX file (max 10MB) into a knowledge base for training.
WHEN TO USE: use this when you need to add a document source; use getFilesByKnowledgeBasePublic to list uploads; use deleteFile to remove a file. Do not use this for website pages — use discoverWebsite / trainDiscoveredUrls.
RETURNS: success and the uploaded file url, fileId, and folder path.

## 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/files": {
      "post": {
        "summary": "Uploads a file to knowledge base (max file size: 10MB)",
        "operationId": "uploadsAFileToKnowledgeBaseMaxFileSize10mb",
        "description": "Uploads a PDF, DOC, or DOCX file (max 10MB) into a knowledge base for training.\nWHEN TO USE: use this when you need to add a document source; use getFilesByKnowledgeBasePublic to list uploads; use deleteFile to remove a file. Do not use this for website pages — use discoverWebsite / trainDiscoveredUrls.\nRETURNS: success and the uploaded file url, fileId, and folder path.",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "File upload with metadata",
          "content": {
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/KnowledgeBaseFileUploadRequestDTO"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Uploads a file to knowledge base",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateFileResponseDTO"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedDTO"
                }
              }
            }
          },
          "422": {
            "description": "Unprocessable Entity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnprocessableDTO"
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InternalServerErrorDTO"
                }
              }
            }
          }
        },
        "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": {
      "KnowledgeBaseFileUploadRequestDTO": {
        "type": "object",
        "properties": {
          "locationId": {
            "type": "string",
            "description": "location id",
            "example": "ocQHyuzHvysMo5N5VsXc"
          },
          "knowledgeBaseId": {
            "type": "string",
            "description": "knowledge base id",
            "example": "ocQHyuzHvysMo5N5VsXc"
          },
          "file": {
            "type": "string",
            "format": "binary",
            "description": "File to upload (max size: 10MB). Supported formats: PDF, DOC, DOCX"
          }
        },
        "required": [
          "file",
          "knowledgeBaseId"
        ],
        "title": "KnowledgeBaseFileUploadRequestDTO"
      },
      "CreateFileResponseDTO": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "description": "success",
            "example": true
          },
          "data": {
            "description": "details of the uploaded file",
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string",
                    "description": "url of the uploaded file",
                    "example": "https://storage.googleapis.com/bucket/locations/abc123/file.pdf"
                  },
                  "fileId": {
                    "type": "string",
                    "description": "file id of the uploaded file",
                    "example": "ocQHyuzHvysMo5N5VsXc"
                  },
                  "folderPath": {
                    "type": "string",
                    "description": "folder path of the uploaded file",
                    "example": "locations/ocQHyuzHvysMo5N5VsXc"
                  }
                },
                "required": [
                  "url",
                  "fileId",
                  "folderPath"
                ],
                "title": "CreateFileResponseDataDTO"
              }
            ],
            "example": {
              "url": "https://storage.googleapis.com/bucket/locations/abc123/file.pdf",
              "fileId": "ocQHyuzHvysMo5N5VsXc",
              "folderPath": "locations/ocQHyuzHvysMo5N5VsXc"
            }
          }
        },
        "required": [
          "success",
          "data"
        ],
        "title": "CreateFileResponseDTO"
      },
      "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"
      },
      "UnprocessableDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 422
          },
          "message": {
            "example": [
              "Unprocessable Entity"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "error": {
            "type": "string",
            "example": "Unprocessable Entity"
          }
        },
        "title": "UnprocessableDTO"
      },
      "InternalServerErrorDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "description": "HTTP status code",
            "example": 500
          },
          "message": {
            "type": "string",
            "description": "Error message",
            "example": "Internal Server Error"
          }
        },
        "title": "InternalServerErrorDTO"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X POST 'https://services.leadconnectorhq.com/knowledge-bases/files' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: multipart/form-data' \
  --data-raw '{
  "locationId": "ocQHyuzHvysMo5N5VsXc",
  "knowledgeBaseId": "ocQHyuzHvysMo5N5VsXc"
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'multipart/form-data'
  },
  body: JSON.stringify({
      "locationId": "ocQHyuzHvysMo5N5VsXc",
      "knowledgeBaseId": "ocQHyuzHvysMo5N5VsXc"
  })
};

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

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

payload = {
    "locationId": "ocQHyuzHvysMo5N5VsXc",
    "knowledgeBaseId": "ocQHyuzHvysMo5N5VsXc"
}

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/files',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: multipart/form-data',
  ],
  CURLOPT_POSTFIELDS => '{
  "locationId": "ocQHyuzHvysMo5N5VsXc",
  "knowledgeBaseId": "ocQHyuzHvysMo5N5VsXc"
}',
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .post("https://services.leadconnectorhq.com/knowledge-bases/files")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "multipart/form-data")
  .body("{\"locationId\":\"ocQHyuzHvysMo5N5VsXc\",\"knowledgeBaseId\":\"ocQHyuzHvysMo5N5VsXc\"}")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/knowledge-bases/files"
  payload := strings.NewReader(`{
  "locationId": "ocQHyuzHvysMo5N5VsXc",
  "knowledgeBaseId": "ocQHyuzHvysMo5N5VsXc"
}`)
  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/files")

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 = '{
  "locationId": "ocQHyuzHvysMo5N5VsXc",
  "knowledgeBaseId": "ocQHyuzHvysMo5N5VsXc"
}'

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

**PowerShell**

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

$body = '{
  "locationId": "ocQHyuzHvysMo5N5VsXc",
  "knowledgeBaseId": "ocQHyuzHvysMo5N5VsXc"
}'

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