Pull analytics into your reports
Copy each day's conversation numbers and sessions into your own reporting, with a key that only has `analytics:read`.
The Analytics page shows how your agents are doing, but your managers may want those numbers next to bookings or sales in your own reporting tool. A short nightly job can fetch yesterday's figures from Careflow and store them wherever your other data lives.
This walkthrough builds that job for a hotel. It reads yesterday's totals, splits them by outcome, and downloads the sessions themselves. You need an API key with Read on Analytics and nothing else, since the job never changes anything. See API keys.
When to run it
Careflow adds up each day's numbers shortly after midnight UTC. Run your job after 01:00 UTC and work in UTC dates throughout. In the examples, yesterday is 2026-10-05.
1. Read yesterday's totals
GET /analytics/trends returns one point per day. Ask for the last seven days and keep yesterday's entry:
curl "https://api.trycareflow.com/analytics/trends?metric=sessions&period=7d" \
-H "Authorization: Bearer sk_live_xxx"
{
"code": "SUCCESS",
"message": "ok",
"data": {
"metric": "sessions",
"period": "7d",
"data": [
{ "date": "2026-10-04", "value": 61, "voice": 44, "whatsapp": 17 },
{ "date": "2026-10-05", "value": 58, "voice": 41, "whatsapp": 17 }
]
}
}
value is the day's total and voice and whatsapp split it by channel. A day with no conversations has no entry at all, so treat a missing date as zero. Repeat with metric=cost for what the day cost and metric=workflows for automations completed. Trends cover the whole workspace and can't be filtered by agent.
2. Count outcomes
Every session ends as success, handoff or drop-off. To count each, list sessions for the day with that status and read the total, asking for a single row so the response stays small:
curl "https://api.trycareflow.com/analytics/sessions?startDate=2026-10-05&endDate=2026-10-05&status=handoff&limit=1" \
-H "Authorization: Bearer sk_live_xxx"
data.total is the number of matching sessions. Run it once for each status, and once without status for the day's total. Add assistantId to count one agent, or channel=voice or channel=whatsapp for one channel. Dates are YYYY-MM-DD.
3. Download the sessions
For row-level data, the export is the simplest route. It returns a CSV file of up to 10,000 sessions for the dates you ask for:
curl "https://api.trycareflow.com/analytics/export?startDate=2026-10-05&endDate=2026-10-05" \
-H "Authorization: Bearer sk_live_xxx" \
-o careflow-2026-10-05.csv
The columns are Start Time, Channel, Duration (s), Status, Cost (USD), Workflow Completed, Phone Number, Disconnect Reason, Avg Latency (ms) and Session ID. The export takes the same status, channel and assistantId filters as the session list. It's a file rather than JSON, so check the response status before you save it.
If you'd rather have JSON, page through the session list instead:
const KEY = process.env.CAREFLOW_API_KEY;
const day = "2026-10-05";
const rows = [];
for (let page = 1; ; page++) {
const url = `https://api.trycareflow.com/analytics/sessions?startDate=${day}&endDate=${day}&limit=100&page=${page}`;
const res = await fetch(url, { headers: { Authorization: `Bearer ${KEY}` } });
const body = await res.json();
if (body.code !== "SUCCESS") throw new Error(body.error || body.message);
for (const s of body.data.sessions ?? []) {
rows.push({
id: s._id,
startedAt: s.startTime,
agent: s.assistantName,
channel: s.channel,
status: s.status,
seconds: s.durationSeconds,
costUsd: s.costUsd,
});
}
if (page >= body.data.pages) break;
}
limit can be up to 100. Each session in the list includes its transcript, so a page can be large. sessions can be null on a day with nothing to show, which is why the loop falls back to an empty list.
To read one conversation in full, GET /analytics/sessions/{id}/transcript returns its messages.
4. Add a rolling summary
For a dashboard tile rather than daily rows, GET /analytics/overview?period=week returns the same summary as the top of the Analytics page: totalSessions, successRate as a percentage, totalCost, avgCostPerSession, avgLatency in milliseconds, and counts by channel and outcome. Add assistantId for one agent.
Keep it light
A nightly run like this makes a handful of requests, well inside your key's 100 a minute. Store what you fetch rather than asking again for the same day, and use the export instead of opening sessions one by one. See Rate limits.
Where to go next
- Analytics overview explains what each number means.
- Authentication covers scopes and keeping keys safe.
- The API Reference lists every analytics field.