> ## 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.

# Conversation History

> In this guide, we can get conversation history for a fixed period of time.

## Prerequisites

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

## Uploading Data Sources

Currently here Uploading Data Source for url.

### API Endpoint

The API endpoint for uploading data sources to your chatbot is: `https://backend.chatfly.co/api/chat/history/{bot_id}/{date_from}/{date_to}/{order}`

<Warning>
  Make sure to replace `{bot_id}`, `{date_from}`, `{date_to}`, `{order}` with the your bot information.
</Warning>

### Request Params

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

```params theme={null}
{
  "bot_id": "xxxx-xxxx-xxxx-xxxx",
  "date_from": "2023-01-01T00:00:00",
  "date_to": "2030-12-31T00:00:00",
  "order": "created_at.desc"
}
```

* bot\_id (string): ID of your bot
* date\_from (datetime): start date you want get conversation history
* date\_to (datetime): end date you want get conversation history
* order: sort for your conversation history

### Example Request

Here’re example command sto uploading data sources using the ChatFly API:

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

<CodeGroup>
  ```json curl theme={null}
  curl -X POST "https://backend.chatfly.co/api/chat/history" \
  -H "Authorization: Bearer token" \
  -H "Content-Type: application/json" \
  -d '{
    "bot_id": "xxxx-xxxx-xxxx-xxxx",
    "date_from": "2023-01-01T00:00:00",
    "date_to": "2030-12-31T00:00:00",
    "order": "created_at.desc"
  }'

  ```

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

  url = "https://backend.chatfly.co/api/chat/history"
  headers = {
      "Authorization": "Bearer token",
      "Content-Type": "application/json"
  }
  data = {
      "bot_id": "xxxx-xxxx-xxxx-xxxx",
      "date_from": "2023-01-01T00:00:00",
      "date_to": "2030-12-31T00:00:00",
      "order": "created_at.desc"
  }

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

  # Print the response status code and content
  print("Response Status Code:", response.status_code)
  print("Response Content:", response.json())
  ```

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

  const url = 'https://backend.chatfly.co/api/chat/history';
  const headers = {
    'Authorization': 'Bearer token',
    'Content-Type': 'application/json'
  };
  const data = {
    'bot_id': 'xxxx-xxxx-xxxx-xxxx',
    'date_from': '2023-01-01T00:00:00',
    'date_to': '2030-12-31T00:00:00',
    'order': 'created_at.desc'
  };

  axios.post(url, data, { headers })
    .then(response => {
      console.log('Response Status Code:', response.status);
      console.log('Response Content:', response.data);
    })
    .catch(error => {
      console.error('Error:', error);
    });
  ```
</CodeGroup>

### Response Body

Response examples like this:

```json theme={null}
[
  [
  {
    "bot_name": "Chatfly",
    "bot_id": "3f1dfb85-177c-4690-a24a-5eef24410601",
    "user_id": "868af88e-9b14-4f55-8124-8e9903a90048",
    "session_id": "f1576597-e64e-6096-c875-631fd1ceb1f2",
    "created_at": "2023-11-04T06:38:26.901921Z",
    "chat_history_response": [
      {
        "sender_type": "user",
        "content": "Hi"
      },
      {
        "sender_type": "assistant",
        "content": "Hello! How can I assist you today?"
      },
      {...
      },
      {...
      }
    ]
  }
]
]
```
