> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chatfly.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Upload Data Sources

> Learn how to upload data sources to your chatbot using the ChatFly API.

## Prerequisites

Before you begin, ensure you have the following:

1. A ChatFly account to obtain an access token.
2. A development environment or a tool for making HTTP requests, such as Curl or a programming language like Python.

## Uploading Data Sources

### API Endpoint

The API endpoint for uploading data sources to your chatbot is:

```text theme={null}
https://backend.chatfly.co/api/scraping/url
```

### Request Body

To upload a data source, send a POST request to the API endpoint with a JSON request body containing the URL of the data source. Here’s an example request body:

```json theme={null}
{
  "bot_id": "xxxx-xxxx-xxxx-xxxx",
  "scrape_url": "Your URL",
  "scrape_type": 2
}
```

* bot\_id (string): ID of your bot.
* scrape\_url (string): Link to the website URL where you want to scrape information.
* scrape\_type (int): The method by which you import the data source.

### Example Request

Here are example commands for uploading data sources using the ChatFly API:

<Warning>
  Replace token with your access token.
</Warning>

<CodeGroup>
  ```json curl theme={null}
  curl -X POST "https://backend.chatfly.co/api/scraping/url" \
  -H "Authorization: Bearer token" \
  -H "Content-Type: application/json" \
  -d '{
    "bot_id": "xxxx-xxxx-xxxx-xxxx",
    "scrape_url": "https://xxxx",
    "scrape_type": 2
  }'
  ```

  ```json python theme={null}
  import requests

  url = 'https://backend.chatfly.co/api/scraping/url'
  headers = {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer token'
  }

  data = {
    "bot_id": "xxxx-xxxx-xxxx-xxxx",
    "scrape_url": "https://xxxx",
    "scrape_type": 2
  }

  response = requests.post(url, headers=headers, json=data)

  if response.status_code == 200:
      print("Request successful!")
      print(response.json())
  else:
      print("Request failed with status code:", response.status_code)
      print(response.text)
  ```

  ```json javascript theme={null}
  const axios = require('axios');

  const url = 'https://backend.chatfly.co/api/scraping/url';
  const headers = {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer token'
  };

  const data = {
      bot_id: 'xxxx-xxxx-xxxx-xxxx',
      scrape_url: 'https://xxxx',
      scrape_type: 2
  };

  axios.post(url, data, { headers })
      .then(response => {
          if (response.status === 200) {
              console.log('Request successful!');
              console.log(response.data);
          } else {
              console.log('Request failed with status code:', response.status);
              console.log(response.data);
          }
      })
      .catch(error => {
          console.error('An error occurred:', error);
      });

  ```
</CodeGroup>

## Get Data Sources

#### API Endpoint

The API endpoint for getting a list of URLs for your chatbot is:

```text theme={null}
https://backend.chatfly.co/api/scraping/url/{bot_id}.
```

<Warning>
  Make sure to replace `{bot_id}` with the UUID of your bot.
</Warning>

#### Request Body

To get a list of URLs, send a GET request to the API endpoint with a params request. Here’s an example params request:

```json theme={null}
{
  "bot_id": "xxxx-xxxx-xxxx-xxxx"
}
```

* bot\_id (string): ID of your bot.

#### Example Request

Here are example commands for getting a list of URLs using the ChatFly API:

<Warning>
  Replace token with your access token.
</Warning>

<CodeGroup>
  ```json curl theme={null}
  curl -X Get "https://backend.chatfly.co/api/scraping/url/xxxx-xxxx-xxxx-xxxx" \
  -H "Authorization: Bearer token" \
  -H "Content-Type: application/json" \

  ```

  ```json python theme={null}
  import requests

  url = 'https://backend.chatfly.co/api/scraping/url/{xxxx-xxxx-xxxx-xxxx}'
  headers = {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer token'
  }

  response = requests.get(url, headers=headers)

  if response.status_code == 200:
      print("Request successful!")
      print(response.json())
  else:
      print("Request failed with status code:", response.status_code)
      print(response.text)
  ```

  ```json javascript theme={null}
  const axios = require('axios');

  const url = 'https://backend.chatfly.co/api/scraping/url/xxxx-xxxx-xxxx-xxxx';
  const headers = {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer token'
  };

  axios.get(url, { headers })
      .then(response => {
          if (response.status === 200) {
              console.log("Request successful!");
              console.log(response.data);
          } else {
              console.log("Request failed with status code:", response.status);
              console.log(response.data);
          }
      })
      .catch(error => {
          console.error("An error occurred:", error);
      });

  ```
</CodeGroup>

#### Response Body

The list of URLs is responded:

```json theme={null}
[
  {
    "knowledge_base_id": "xxxx-xxxx-xxxx-xxxx",
    "url": "Your URL",
    "num_token": 0
  },
  ...
]
```

* knowledge\_base\_id (string): ID of the knowledge base.
* url (string): Your website URL.
* num\_token (int): Number of words.
