Skip to main content

UC-019 — Analyze Message History

Goal
Query message history and export data for reports and audits
Channel
SMS, RCS, WhatsApp (one channel per query)
Estimated time
15 minutes

Real-world scenarios​

  • Monthly report: The TravelDream marketing manager generates a monthly report with sending volumes by channel and delivery rate.
  • Per-channel analysis: The BrandCo team compares SMS vs WhatsApp performance to optimize the communication strategy.
  • Audit trail: The compliance officer exports the messages sent to a specific customer for a GDPR audit.

The history and its export hold the messages sent through the API. Campaign messages are not part of them, not even those of campaigns created with POST /campaigns: for campaign results use GET /campaigns/{id}, GET /campaigns/stats or a delivery-report export with the campaignId (UC-002).

Analysis flow​

The diagram shows the interactive query flow and the asynchronous export for large datasets.

Prerequisites​

  • Active API Key with the MESSAGES and EXPORTS operations
  • At least one message sent through the API
  • For large volume exports: allow time for asynchronous processing

Step 1 — Query message history​

channel, from and to are required. A date alone covers the whole day in UTC.

curl -X GET "https://api.qlara.ai/api/partner-gateway/messages/history?channel=SMS&from=2026-04-01&to=2026-04-09&page=0&limit=20" \
-H "X-Api-Key: YOUR_API_KEY"

Response — Message history​

The response is a JSON array, one entry per message (one per part for an SMS split into several parts, every part with the same customerMessageId):

[
{
"customerMessageId": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
"channel": "SMS",
"destination": "+393471234567",
"deliveryStatus": "DELIVERED",
"deliveryStatusDescription": "delivered",
"sendDate": "2026-04-09T08:15:00Z",
"deliveryDate": "2026-04-09T08:15:03Z",
"readDate": null
},
{
"customerMessageId": "a2c4e6f8-1234-5678-9abc-def012345678",
"channel": "SMS",
"destination": "+393489876543",
"deliveryStatus": "UNDELIVERABLE",
"deliveryStatusDescription": "undeliverable",
"sendDate": "2026-04-08T14:00:00Z",
"deliveryDate": null,
"readDate": null
}
]
Accepted date formats

from and to accept a date (2026-04-01, the whole UTC day), a date-time without offset (2026-04-01T10:30:00, read as UTC) or a full ISO 8601 date-time with offset (2026-04-01T00:00:00%2B02:00, 2026-04-09T23:59:59Z). Percent-encode a + as %2B. Any other shape is answered 400 with the list of accepted formats.

Behind the scenes — Filters and pagination
  1. One channel per query: channel is SMS, RCS or WHATSAPP (case-insensitive). To cover several channels, run one query per channel.
  2. Status filter: add status with one deliveryStatus name, in any letter case, to keep a single delivery status. The names depend on the channel (see the Delivery Statuses table): SMS uses ACCEPTED, REJECTED, DELIVERED, EXPIRED, DELETED, UNDELIVERABLE and UNKNOWN; RCS uses DELIVERED, EXPIRED, ERROR, DISABLED, UNSUPPORTED and UNKNOWN; WhatsApp uses the RCS ones plus CONVERSATION_CLOSED. A status the channel never uses (for example ERROR on SMS) returns an empty array; a value that is not a delivery status name is answered 400 with the list of allowed values.
  3. Pagination: page starts at 0 and limit defaults to 20. page must be 0 or more and limit from 1 to 1000, with page × limit no higher than 2147483647; otherwise the API answers 400. The response is a plain array, and page and limit count its entries, so every part of an SMS counts. Without status, you are on the last page when it holds fewer items than limit. With status, the filter is applied to each page of limit messages after it has been read: a page can hold fewer items than limit, or none, while later pages still hold matches, so neither a short nor an empty page means you have reached the end. To collect every message in one status, page without status until a page holds fewer items than limit, and keep the entries whose deliveryStatus you want.
  4. Required range: from and to are mandatory, and from must not be later than to; otherwise the API answers 400.
  5. Sender and recipient filters are available on the export, not on the query.

Step 2 — Export data for reports​

For large datasets, queue an asynchronous CSV export. Dates are ISO 8601 with offset; sender and recipient are optional filters.

curl -X POST https://api.qlara.ai/api/partner-gateway/messages/history/export \
-H "Content-Type: application/json" \
-H "X-Api-Key: YOUR_API_KEY" \
-d '{
"startDateTime": "2026-03-01T00:00:00+01:00",
"endDateTime": "2026-03-31T23:59:59+02:00"
}'

Response — Export queued​

202 Accepted with an empty body. The export covers every channel and only the messages sent through the API.

Asynchronous export

The file is generated in the background. Track it through the export endpoints: the list tells you when it is ready, the detail gives you the download URL.

# List your exports, newest first
curl -X GET "https://api.qlara.ai/api/partner-gateway/exports?page=0&limit=10" \
-H "X-Api-Key: YOUR_API_KEY"

Response — Export list​

{
"data": [
{
"id": 369,
"type": "DELIVERY_REPORT",
"detail": {
"type": "DELIVERY_REPORT",
"exportFormat": "CSV",
"startDateTime": "2026-02-28T23:00:00Z",
"endDateTime": "2026-03-31T21:59:59Z",
"sendType": "API"
},
"createdAt": "2026-04-09 14:00:12.200+0000",
"expiresAt": "2026-04-16 14:00:12.199+0000",
"isAvailableForDownload": true
}
],
"page": 0,
"limit": 10,
"totalCount": 1,
"totalPages": 1
}

A history export appears as a DELIVERY_REPORT with sendType API, and only once its file is ready, already with isAvailableForDownload: true: a queued or running export is not listed yet, and one whose generation fails never appears and reports no error. Since the POST returned no id, recognize yours as the new entry whose detail matches your request and whose createdAt is later than the request; if none shows up within a reasonable time, request the export again. Then fetch the download URL:

curl -X GET "https://api.qlara.ai/api/partner-gateway/exports/369" \
-H "X-Api-Key: YOUR_API_KEY"

Response — Download URL​

{
"url": "https://storage.example.com/exports/369/delivery-report-2026-03.csv?X-Amz-Expires=3600&X-Amz-Signature=..."
}
Behind the scenes — Export process
  1. Queue: the request is placed on a dedicated queue so that it does not affect the real-time API.
  2. Scope: the export covers all channels (SMS, RCS, WhatsApp) but only the messages sent through the API, the same ones GET /messages/history shows.
  3. Storage: the file stays downloadable until expiresAt, 7 days after it was generated. The signed download URL expires sooner: until expiresAt, call GET /exports/{exportId} again whenever you need a fresh one. After expiresAt, POST /exports/{exportId} queues a new export with the same filters, which appears in GET /exports under a new id once its file is ready.
  4. Format: CSV only, one row per SMS part, with the last three characters of every destination replaced by ***.

Expected result​

StepActionResult
1GET /messages/historyArray of messages for the channel and date range
2POST /messages/history/export202 Accepted, export queued
3GET /exportsOnce its file is ready, the new export appears with isAvailableForDownload: true
4GET /exports/{exportId}Download URL

Complete end-to-end example​

Scenario TravelDream: monthly SMS report for March.

BASE="https://api.qlara.ai/api/partner-gateway"

# 1. Data preview (first 5 messages)
echo "=== March History Preview ==="
curl -s -X GET "$BASE/messages/history?channel=SMS&from=2026-03-01&to=2026-03-31&page=0&limit=5" \
-H "X-Api-Key: YOUR_API_KEY" | jq '.[] | {destination, deliveryStatus, sendDate}'

# 2. Queue the full export (202, empty body), noting the time of the request in UTC
REQUESTED_AT=$(date -u +"%Y-%m-%d %H:%M:%S")
curl -s -o /dev/null -w "export queued: HTTP %{http_code}\n" -X POST "$BASE/messages/history/export" \
-H "Content-Type: application/json" \
-H "X-Api-Key: YOUR_API_KEY" \
-d '{"startDateTime": "2026-03-01T00:00:00+01:00", "endDateTime": "2026-03-31T23:59:59+02:00"}'

# 3. Poll the list until the new export appears (listed only once its file is ready), for up to 10 minutes
EXPORT_ID=""
for ATTEMPT in $(seq 1 60); do
EXPORT_ID=$(curl -s -X GET "$BASE/exports?page=0&limit=10" \
-H "X-Api-Key: YOUR_API_KEY" | jq -r --arg since "$REQUESTED_AT" \
'[.data[] | select(.detail.sendType == "API" and .detail.startDateTime == "2026-02-28T23:00:00Z" and .createdAt >= $since)][0].id // empty')
[ -n "$EXPORT_ID" ] && break
sleep 10
done
if [ -z "$EXPORT_ID" ]; then
echo "No export after 10 minutes: it failed, request it again"
exit 1
fi

# 4. Download
DOWNLOAD_URL=$(curl -s -X GET "$BASE/exports/${EXPORT_ID}" \
-H "X-Api-Key: YOUR_API_KEY" | jq -r '.url')
echo "Download: $DOWNLOAD_URL"

Variants​

Only failed messages​

curl -X GET "https://api.qlara.ai/api/partner-gateway/messages/history?channel=SMS&from=2026-04-01&to=2026-04-09&status=UNDELIVERABLE" \
-H "X-Api-Key: YOUR_API_KEY"

This returns the first page of UNDELIVERABLE messages, but the filter is applied to each page after it is read, so this page can be short or empty while later ones still hold matches. An SMS can also fail as REJECTED or EXPIRED. To collect every failed message, page without status until a page holds fewer items than limit, and keep the entries whose deliveryStatus is a failure; for SMS, the export is an alternative, as its Delivery result column carries the status. ERROR is an RCS and WhatsApp status, so status=ERROR on SMS always returns an empty array.

Messages sent to one recipient (GDPR audit)​

The query endpoint has no recipient filter; use the export with recipient:

curl -X POST https://api.qlara.ai/api/partner-gateway/messages/history/export \
-H "Content-Type: application/json" \
-H "X-Api-Key: YOUR_API_KEY" \
-d '{
"startDateTime": "2025-01-01T00:00:00+01:00",
"endDateTime": "2026-04-09T23:59:59+02:00",
"recipient": "+393471234567"
}'

Common errors​

400 Bad Request — Missing parameters​

{
"status": "fail",
"data": "Required query params: 'channel' (RCS, WHATSAPP, SMS), 'from' and 'to' (yyyy-MM-dd (a whole day, UTC), yyyy-MM-ddTHH:mm:ss (UTC) or ISO-8601 with an offset such as 2025-01-15T00:00:00+01:00 or 2025-01-15T00:00:00Z)"
}

Solution: pass all three parameters. channel is one of SMS, RCS, WHATSAPP.

400 Bad Request — Date in an unknown format​

{
"status": "fail",
"data": "Invalid 'from': '27/08/2026'. Accepted formats: yyyy-MM-dd (a whole day, UTC), yyyy-MM-ddTHH:mm:ss (UTC) or ISO-8601 with an offset such as 2025-01-15T00:00:00+01:00 or 2025-01-15T00:00:00Z"
}

Solution: use one of the formats listed in the message, and percent-encode a + in the offset as %2B.

Next steps​

References​