Export the call history
This guide exports the organization's calls with GET /v1/calls. It uses cursor pagination, which costs the same on any page, even with hundreds of thousands of calls.
Before you start
- An API key with the Chamadas e transcrições (
calls:read) scope. - Python 3.11 or later with
requests, or Node.js 18 or later.
Export to CSV
import csv
import os
import time
import requests
API = "https://api.diska.ai/v1"
FIELDS = [
"id", "started_at", "ended_at", "duration_seconds", "channel", "direction", "status",
"agent_name", "caller_name", "caller_contact", "end_reason", "summary",
]
session = requests.Session()
session.headers["Authorization"] = f"Bearer {os.environ['DISKA_API_KEY']}"
def get(path: str, params: dict | None = None) -> dict:
while True:
response = session.get(f"{API}{path}", params=params, timeout=60)
if response.status_code == 429: # rate limit: wait as long as the API says
time.sleep(int(response.headers.get("Retry-After", "5")))
continue
response.raise_for_status()
return response.json()
params = {"cursor": "start", "limit": 200} # optional filters: agent_id, status, channel
total = 0
with open("calls.csv", "w", newline="", encoding="utf-8") as file:
writer = csv.DictWriter(file, fieldnames=FIELDS, extrasaction="ignore")
writer.writeheader()
while True:
page = get("/calls", params)
writer.writerows(page["items"])
total += len(page["items"])
if not page["next_cursor"]:
break
params["cursor"] = page["next_cursor"]
print(f"{total} calls exported to calls.csv")
// Node.js 18 or later, in a .mjs file
import { createWriteStream } from 'node:fs'
import { setTimeout as sleep } from 'node:timers/promises'
const API = 'https://api.diska.ai/v1'
const FIELDS = ['id', 'started_at', 'ended_at', 'duration_seconds', 'channel', 'direction', 'status',
'agent_name', 'caller_name', 'caller_contact', 'end_reason', 'summary']
async function get(path, params) {
for (;;) {
const response = await fetch(`${API}${path}?${new URLSearchParams(params)}`, {
headers: { Authorization: `Bearer ${process.env.DISKA_API_KEY}` }
})
if (response.status === 429) { // rate limit: wait as long as the API says
await sleep(1000 * Number(response.headers.get('retry-after') || 5))
continue
}
if (!response.ok) throw new Error(`${response.status} ${await response.text()}`)
return response.json()
}
}
const cell = value => `"${String(value ?? '').replaceAll('"', '""')}"`
const out = createWriteStream('calls.csv')
out.write(FIELDS.join(',') + '\n')
const params = { cursor: 'start', limit: 200 } // optional filters: agent_id, status, channel
let total = 0
for (;;) {
const page = await get('/calls', params)
for (const call of page.items) out.write(FIELDS.map(f => cell(call[f])).join(',') + '\n')
total += page.items.length
if (!page.next_cursor) break
params.cursor = page.next_cursor
}
out.end()
console.log(`${total} calls exported to calls.csv`)
- The first page asks for
cursor=start; the next ones use thenext_cursorreceived. Whennext_cursorisnull, you are done. limit=200is the maximum per page.- If the API answers
429, the script waits as long as theRetry-Afterheader says and repeats the request. - To export only part of it, add filters to
params:agent_id,statusorchannel. See the parameters.
Include transcripts
The list does not carry the transcript. To get it, ask for each call's detail and save one JSON line per call:
import json
import os
import time
import requests
API = "https://api.diska.ai/v1"
session = requests.Session()
session.headers["Authorization"] = f"Bearer {os.environ['DISKA_API_KEY']}"
def get(path: str, params: dict | None = None) -> dict:
while True:
response = session.get(f"{API}{path}", params=params, timeout=60)
if response.status_code == 429:
time.sleep(int(response.headers.get("Retry-After", "5")))
continue
response.raise_for_status()
return response.json()
params = {"cursor": "start", "limit": 200, "status": "completed"}
with open("calls.jsonl", "w", encoding="utf-8") as file:
while True:
page = get("/calls", params)
for call in page["items"]:
detail = get(f"/calls/{call['id']}") # transcript, actions and post-call result
file.write(json.dumps(detail, ensure_ascii=False) + "\n")
time.sleep(0.5) # at most 120 requests per minute per key
if not page["next_cursor"]:
break
params["cursor"] = page["next_cursor"]
Each line has the same content as GET /v1/calls/{call_id}: transcript (messages), executed actions and post-call result. The script makes one request per call and waits half a second between them to stay under 120 requests per minute: 10,000 calls take about an hour and a half.
Export only what is new
The API does not filter by date, but the list is newest first. To export only since the last run, stop when started_at is older than that date, like the calls_since function in Sync calls with your CRM.
Take care
- Exports contain personal data: contacts, names and what was said. Store them with the same care as the rest of your customers' data.
- Recording audio is not exported by the API. Listen to recordings in History.

