waiaconnect

Documentation / Essential

Receive the Coexistence conversation history

GET /v1/connections/:id/history

Markdown

Building with AI? Connect it to your account over MCP: it checks your setup, creates webhooks and templates with your confirmation and writes the code for you. See how →

When a number is connected through Coexistence, before Meta's window opens, the business answers whether it wants us to deliver its conversation history: up to 6 months, the messages from both sides, no groups. The history stays on the phone: nothing there is deleted or moved. The choice is now: Meta shares the history only once, when the number is connected, and if the business answers no it can't be requested later. If it answers yes, we request it from Meta (the business has to accept sharing it in the WhatsApp Business app), keep it encrypted for up to 7 days and deliver it to you in two ways, whichever happens first:

· By webhook: history.batch events with up to 500 messages each (in Meta's shape, like message.received, with contact and direction), signed like every other event, and a history.completed when nothing is left. They go through a separate queue that never delays your live messages: a large history can take hours.
· By API, if you don't have a webhook yet: GET /v1/connections/{id}/history returns the batches in order (limit 1 to 5, after = the previous nextCursor). Reading does not delete: once you stored a batch, confirm it with POST /v1/connections/{id}/history/{batchId}/ack.

Each batch is deleted as soon as it is delivered (your 2xx or your confirmation); what is not delivered is deleted after 7 days anyway. If batches are still undelivered on the fifth day, we notify ONCE per number (panel and email) with the date they will be deleted. It is not traffic and does not consume your quota. If the business answered no, we request nothing from Meta. If we ever ran out of space, we stop storing new history and tell you with history.dropped.

# 1) read a page (reading does NOT delete)
curl "https://api.waiaconnect.com/v1/connections/conn_…/history?limit=1" -H "Authorization: Bearer wc_live_YOUR_API_KEY"
# → { "data": [ { "batchId": "hb_…", "count": 500, "messages": [ … ] } ], "hasMore": true, "nextCursor": 1 }

# 2) once you stored it, confirm it → deleted from WAIA Connect at once
curl -X POST "https://api.waiaconnect.com/v1/connections/conn_…/history/hb_…/ack" -H "Authorization: Bearer wc_live_YOUR_API_KEY"
# 3) next page: ?after=1 (the nextCursor) — until hasMore is false
const H = { "Authorization": "Bearer wc_live_YOUR_API_KEY" };
let after = 0, hasMore = true;
while (hasMore) {
  const page = await (await fetch(`https://api.waiaconnect.com/v1/connections/conn_…/history?limit=1&after=${after}`, { headers: H })).json();
  for (const batch of page.data) {
    await saveMessages(batch.messages);            // your storage; dedupe on batch.batchId
    await fetch(`https://api.waiaconnect.com/v1/connections/conn_…/history/${batch.batchId}/ack`, { method: "POST", headers: H });
  }
  hasMore = page.hasMore;
  after = page.nextCursor;
}
<?php
$h = ["Authorization: Bearer wc_live_YOUR_API_KEY"];
$after = 0;
do {
  $ch = curl_init("https://api.waiaconnect.com/v1/connections/conn_…/history?limit=1&after=" . $after);
  curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => $h]);
  $page = json_decode(curl_exec($ch), true);
  foreach ($page["data"] as $batch) {
    save_messages($batch["messages"]); // your storage; dedupe on batchId
    $ack = curl_init("https://api.waiaconnect.com/v1/connections/conn_…/history/" . $batch["batchId"] . "/ack");
    curl_setopt_array($ack, [CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_HTTPHEADER => $h]);
    curl_exec($ack);
  }
  $after = $page["nextCursor"];
} while ($page["hasMore"]);
import requests
H = {"Authorization": "Bearer wc_live_YOUR_API_KEY"}
after, has_more = 0, True
while has_more:
    page = requests.get("https://api.waiaconnect.com/v1/connections/conn_…/history", headers=H, params={"limit": 1, "after": after}).json()
    for batch in page["data"]:
        save_messages(batch["messages"])  # your storage; dedupe on batchId
        requests.post(f"https://api.waiaconnect.com/v1/connections/conn_…/history/{batch['batchId']}/ack", headers=H)
    has_more, after = page["hasMore"], page["nextCursor"]

Photos, audio and documents arrive without the file (type: "media_placeholder", no id). Meta sends the file only for the last 14 days, in a separate message with the same message id and its image.id (or .audio.id, …), and not always: if it arrives, download it with GET /v1/media/{id} within 7 days. Each one carries our connect.media: { status: "available", available_until } if it came with its id, or { status: "unavailable", reason } with older_than_14_days (Meta never sends it), meta_failed (Meta could not fetch it from the phone; that 131052 no longer reaches you as message.status) or pending (it may arrive in a later batch).

Deduplicate on batchId: a batch can reach you twice (for example, if we restart in the middle of a delivery).

If you integrate with onboarding links, send historyDelivery: true|false when you create the link if you already asked your customer; otherwise the page asks them.

history.synced still arrives as a summary of each Meta chunk (progress: 100 = Meta finished).