Code examples
All examples read the key from the EXTRACTIVIO_KEY environment variable.
curl
# A file on disk
curl -X POST "https://extractivio.com/api/v1/convert?date_order=mdy" \
-H "Authorization: Bearer $EXTRACTIVIO_KEY" \
-F "file=@statement.pdf"
# Raw bytes
curl -X POST "https://extractivio.com/api/v1/convert" \
-H "Authorization: Bearer $EXTRACTIVIO_KEY" \
-H "Content-Type: application/pdf" \
--data-binary @statement.pdf
# A URL, returned as a QuickBooks file
curl -X POST "https://extractivio.com/api/v1/convert?format=qbo" \
-H "Authorization: Bearer $EXTRACTIVIO_KEY" \
-H "Content-Type: application/json" \
-d '{"file_url": "https://example.com/statement.pdf"}' \
-o statement.qbo
# Usage
curl "https://extractivio.com/api/v1/usage" -H "Authorization: Bearer $EXTRACTIVIO_KEY"
Python
import os, requests
BASE = "https://extractivio.com"
HEADERS = {"Authorization": f"Bearer {os.environ['EXTRACTIVIO_KEY']}"}
def convert(path, date_order=None):
with open(path, "rb") as f:
r = requests.post(
f"{BASE}/api/v1/convert",
params={"date_order": date_order} if date_order else {},
headers=HEADERS,
files={"file": (os.path.basename(path), f, "application/pdf")},
timeout=90,
)
if r.status_code != 200:
err = r.json()["error"]
raise RuntimeError(f"{err['code']}: {err['message']}")
return r.json()
result = convert("statement.pdf", date_order="mdy")
check = result["balance_check"]
print(len(result["transactions"]), "transactions")
if check["checkable"] == 0:
print("No running balance: result is unverified")
elif check["reconciled"] < check["checkable"]:
print(check["checkable"] - check["reconciled"], "rows do not reconcile")
for w in result["warnings"]:
print("warning:", w)
net = sum(t["amount"] for t in result["transactions"])
print("net change:", round(net, 2), result["currency"] or "")
Node.js
import { readFile } from "node:fs/promises";
const BASE = "https://extractivio.com";
async function convert(path, dateOrder) {
const url = new URL("/api/v1/convert", BASE);
if (dateOrder) url.searchParams.set("date_order", dateOrder);
const res = await fetch(url, {
method: "POST",
headers: { Authorization: `Bearer ${process.env.EXTRACTIVIO_KEY}`, "Content-Type": "application/pdf" },
body: await readFile(path),
});
const body = await res.json();
if (!res.ok) throw new Error(`${body.error.code}: ${body.error.message}`);
return body;
}
const result = await convert("statement.pdf", "mdy");
const { checkable, reconciled } = result.balance_check;
console.log(`${result.transactions.length} transactions, balance check ${reconciled}/${checkable}`);
A folder of statements, with pacing
import glob, time
for path in sorted(glob.glob("statements/*.pdf")):
try:
result = convert(path)
except RuntimeError as e:
code = str(e).split(":")[0]
if code == "rate_limited":
time.sleep(60)
result = convert(path)
elif code == "quota_exceeded":
print("Quota used up, stopping")
break
else:
print(path, "failed:", e)
continue
print(path, len(result["transactions"]), result["balance_check"])
time.sleep(1.1) # stays under 60 requests a minute
Stored results
# Convert and keep the result
curl -X POST "https://extractivio.com/api/v1/convert?store=true" \
-H "Authorization: Bearer $EXTRACTIVIO_KEY" -F "file=@statement.pdf"
# List what is stored, summaries only
curl "https://extractivio.com/api/v1/conversions?summary=true&limit=10" \
-H "Authorization: Bearer $EXTRACTIVIO_KEY"
← Function callingUsage and stored results →View as Markdown