This article provides a ready-to-use Python script that retrieves Conversation History API Response from Kore.ai Platform using the getMessagesV2 API.
The script automatically handles:
- Pagination using the
skipparameter - Large datasets
- API rate limits (HTTP 429)
- Flattening and formatting all message data
- Exporting the result into an Excel file
This tool is ideal for customers who need to:
Audit user–bot conversation logs
Perform troubleshooting
Generate analytics or compliance reports
Extract raw conversation data for external systems
What the Script Does
The script:
1. Connects to Conversation History API
Uses the endpoint:
/api/public/bot/{botId}/getMessagesV2
2. Fetches ALL conversation messages for a date range
It pulls:
- Incoming and outgoing messages
- Message text
- Session details
- Channel information
- User/message/session tags
- Timestamps
3. Automatically paginates using the skip parameter
The script:
- Starts with
skip = 0 - Fetches messages
- Adds the number of fetched records to
skip - Continues until no more messages are returned
4. Handles API rate limits
If the API returns 429 – Too Many Requests, the script:
- Waits 2, 4, 6, 8, 10 seconds
- Retries automatically
5. Exports all results into Excel
Creates:
conversation_history.xlsx
Formatted, clean, and ready for analysis.
Prerequisites
Before you run the script, ensure the following:
Python 3.8 or later
Check using:
python --version
Required Python libraries
Install dependencies:
pip install requests pandas openpyxl
A valid Kore.ai JWT Auth Token
You must generate a JWT token with permissions to access:
- Conversation History
- Bot messages
- Analytics logs
Please refer to this additional article on community to know how to generate JWT token
Replace inside script:
AUTH_TOKEN = "your_jwt_token_here"
Correct Kore.ai Bot API URL
Replace:
API_URL = "https://<your-host>/api/public/bot/<botId>/getMessagesV2"
Valid date range
Set:
DATE_FROM = "YYYY-MM-DD" DATE_TO = "YYYY-MM-DD"
How to Run the Script
- Save the script as:
fetch_conversation_history.py
- Open a terminal or command prompt.
- Run:
python fetch_conversation_history.py
- After completion, you will see:
conversation_history.xlsx
Output Format
The exported file includes columns such as:
Column Name Description
| Column Name | Description |
|---|---|
| id | Message ID |
| botId | Bot Identifier |
| type | incoming / outgoing |
| status | Message status |
| createdOn | Timestamp |
| channel | Channel type (e.g., web, rtm) |
| text | User or bot message |
| sessionId | Session Identifier |
| tags_message | Message tags |
| tags_user | User-level tags |
| tags_session | Session-level tags |
| tags_altText | Accessibility tags |
Notes & Limitations
- API results depend on your Kore.ai workspace logging and retention policy.
- JWT token must be valid at runtime.
- Large date ranges may take several minutes.
- Some messages may not contain text (media, system events, etc.).
Disclaimer
This is a sample implementation provided for illustrative purposes only and should not be considered production-ready code. It has been created as a use-case example to assist users who want to download the Conversation History API response and export the data into Excel or CSV formats.Preformatted text
Sample Scripts:
GetMessageV2MonthonMonth.txt (3.7 KB)
ConversationHistoryV2API Script.txt (3.1 KB)