// Node.js, using your institution-issued environment and key.
const baseUrl = process.env.AMLOK_API_BASE_URL;
const apiKey = process.env.AMLOK_API_KEY;
if (!baseUrl || !apiKey) throw new Error("Configure API environment and key");
const seen = new Set();
let cursor;
let finished = false;
for (let pageNumber = 0; pageNumber < 1000; pageNumber++) {
const url = new URL("/v1/bank-transactions", baseUrl);
url.search = new URLSearchParams({
subject_id: "biz_example", posted_from: "2026-09-01",
posted_to: "2026-10-01", limit: "100", ...(cursor ? { cursor } : {})
}).toString();
const response = await fetch(url, {
headers: { Authorization: `Bearer ${apiKey}`, Accept: "application/json" },
redirect: "error", signal: AbortSignal.timeout(30000)
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const result = await response.json();
// Persist/process result.data; also inspect result.meta.data_status and coverage.
if (!result.page.has_more) { finished = true; break; }
cursor = result.page.next_cursor;
if (!cursor || seen.has(cursor)) throw new Error("Invalid or repeated cursor");
seen.add(cursor);
}
if (!finished) throw new Error("Client page budget reached; save progress for review");