Load TikTok Chat History: Cursor Pagination With UnifyPort
To load older TikTok private messages through UnifyPort, take history_cursor from the conversation list item and send it unchanged as before.cursor in a history request. Subscribe to conversation.history first: the messages arrive asynchronously, not in the HTTP response. Continue with the callback’s data.history.next_cursor only when data.history.has_more is true and the cursor is usable.
Key takeaways
- A cursor belongs to one account and conversation; it is not a message ID or a timestamp.
- HTTP
202acknowledges the request, not receipt of messages. - Persist callback messages before advancing the pagination state.
- Keep history out of live auto-reply triggers, and do not automatically repeat an uncertain request.
Choose conversation loading, not archive export
TikTok’s official Data Types documentation includes direct-message history in data exports. That is a different contract from loading older context into a connected support conversation. Our export versus live-DM guide explains that architectural choice; this tutorial covers the narrower UnifyPort history-cursor workflow.
UnifyPort is an unofficial interface. Its current request conversation history reference documents TikTok private-chat cursors. Do not infer group support, a complete backup, or recovery of every missed event. Availability still needs checking for your connected account.
Capture the first cursor with its conversation
Prepare the receiver and subscribe to conversation.history without removing existing live-message subscriptions. Follow the webhook delivery reference for signature verification and durable acceptance before returning 2xx.
Read the account’s conversation list and retain the selected item’s conversation_id and history_cursor together. Keep the account ID alongside them in your application. If the history cursor is absent or empty, disable history loading rather than manufacture a value.
Do not confuse the list’s pagination cursor with an item’s history_cursor: one traverses conversations, while the other starts history loading inside the selected chat. Switching accounts or chats must switch the entire history state, not merely its screen title.
This illustrative JavaScript constructs only the first request body from a returned conversation item. It performs no network request:
function firstHistoryRequest(conversation) {
const conversationId = conversation?.conversation_id;
const cursor = conversation?.history_cursor;
if (typeof conversationId !== 'string' || !conversationId.trim() ||
typeof cursor !== 'string' || !cursor.trim()) {
throw new Error('Select a conversation with a history cursor');
}
return {
conversation_id: conversationId,
before: { cursor },
limit: 50
};
}
Send that body through the documented history operation using a backend-held X-Api-Key. limit accepts integers from 1 to 50 and is a requested count, not a promised batch size. Preserve the cursor exactly; the validation above does not trim the submitted value. Do not add WhatsApp’s message_id, sent_at, or direction anchor fields to TikTok’s before object.
Advance from the callback, not the HTTP response
Use the following as application design recommendations, not additional API statuses:
| Observation | Recommended action |
|---|---|
HTTP 202 with data.status=accepted | Show that the request was accepted; wait for history |
| Matching history callback | Persist and merge its messages before considering continuation |
data.history.has_more=true and a non-empty data.history.next_cursor | Offer another explicit load using that cursor unchanged |
| More results indicated but no usable next cursor | Stop advancement and retain diagnostic evidence |
| No callback, missing continuation metadata, or timeout | Keep the result uncertain; do not invent an end marker |
Serialize history requests per account and conversation. Match callbacks to that scope, and keep late callbacks for another open chat from changing the current chat’s cursor. The HTTP request_id is for troubleshooting, not a task ID or callback correlation key.
Merge messages idempotently using account, conversation, and message identity. Duplicate deliveries must not duplicate timeline rows. Store continuation metadata with the durable batch processing result; advancing before storage succeeds can leave your UI moving past content it never retained.
Keep newly received live messages and historical context on separate processing paths. An older customer question should not open a fresh ticket or send an automatic answer merely because it arrived in a history callback. Preserve applicable edits, deletion decisions, and retention rules when merging older content.
Recover without borrowing WhatsApp semantics
An invalid cursor, including one from another account or conversation, returns 400 invalid_request. Inspect its origin and scope rather than repeatedly submitting it. After a timeout, a callback may still arrive; retain the pending context and avoid automatic resubmission.
The WhatsApp history guide uses a native-message anchor. Do not copy that anchor builder or its cursor-free continuation rules into TikTok code. A shared operation name does not make the provider contracts identical.
Before enabling the control, test a missing initial cursor, duplicate callbacks, switching chats while waiting, a callback after an HTTP timeout, and a failed storage transaction. These are proposed acceptance checks, not reported test results.
FAQ
Does 202 contain the older messages?
No. It acknowledges acceptance. Available history arrives asynchronously through conversation.history.
Can I use the last message ID as the TikTok cursor?
No. Start with the conversation item’s history_cursor; continue with the callback’s data.history.next_cursor when more history is indicated. Treat both as opaque strings.
Does a short batch mean the archive is complete?
No. Use the supplied continuation metadata rather than message count, and do not equate the end of available pagination with a complete account archive.
Next step and sources
Implement the cursor state against Request conversation history before enabling the Load older messages button.
References checked on 2026-12-01; product behavior follows the current repository documentation, not a claimed release date:
Turn messaging integration into a stable product pipeline.
Start by sending through one API, then bring every inbound message back into your business system with standard events.