How to Extract Conversation History API response from Using Custom Python Script and Save it in a CSV/ Excel File

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 skip parameter
  • 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:

:check_mark: Audit user–bot conversation logs
:check_mark: Perform troubleshooting
:check_mark: Generate analytics or compliance reports
:check_mark: Extract raw conversation data for external systems

:bullseye: 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:
:page_facing_up: conversation_history.xlsx

Formatted, clean, and ready for analysis.

:puzzle_piece: Prerequisites

Before you run the script, ensure the following:

:check_mark: Python 3.8 or later

Check using:

python --version

:check_mark: Required Python libraries

Install dependencies:

pip install requests pandas openpyxl

:check_mark: A valid Kore.ai JWT Auth Token

You must generate a JWT token with permissions to access:

Replace inside script:

AUTH_TOKEN = "your_jwt_token_here"

:check_mark: Correct Kore.ai Bot API URL

Replace:

API_URL = "https://<your-host>/api/public/bot/<botId>/getMessagesV2"

:check_mark: Valid date range

Set:

DATE_FROM = "YYYY-MM-DD" DATE_TO = "YYYY-MM-DD"

:inbox_tray: How to Run the Script

  1. Save the script as:

fetch_conversation_history.py

  1. Open a terminal or command prompt.
  2. Run:

python fetch_conversation_history.py

  1. After completion, you will see:

conversation_history.xlsx

:outbox_tray: 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

:warning: 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.).

:warning: 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)