This page is for pulling data out: copying ledgers and vouchers into your CRM, warehouse or dashboard, and keeping that copy current.
What you have to work with
There are no webhooks, no change feed and no updatedSince filter. No read can answer "what changed
since my last call". You poll, and you work out the differences yourself. What is available:
| Tool | What it gives you | Limit |
|---|---|---|
page and pageSize |
Every row, 1000 at a time | Offset paging over a list that can move while you read it |
from and to on /v1/vouchers |
Vouchers in a date window | Filters the voucher's date, not when it changed |
GET /v1/status |
When rows of each kind were last written, per company | Coarse: "something landed", not what |
X-Tally-Synced-At |
The same timestamp, on list responses | |
guid |
A stable id for each record | |
alterId |
Tally's change counter | Only on GET /v1/vouchers/:guid, not on lists |
So the pattern is: check cheaply whether anything landed, re-read a generous window, match by guid,
and run a full comparison on a slower schedule to catch what the window misses.
Setup
These examples run on Node 18 or later, on your server.
const BASE = "https://relay.autotally.ai";
const TOKEN = process.env.AUTOTALLY_TOKEN;
const COMPANY = "Sharma Traders";
async function get(path, params = {}) {
const url = new URL(path, BASE);
for (const [k, v] of Object.entries(params)) {
if (v !== undefined) url.searchParams.set(k, v);
}
const res = await fetch(url, { headers: { authorization: `Bearer ${TOKEN}` } });
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
return { body: await res.json(), syncedAt: res.headers.get("x-tally-synced-at") };
}
Full export
Walk the pages until you have total rows. pageSize tops out at 1000.
async function readAll(path, params = {}) {
const items = [];
for (let page = 1; ; page++) {
const { body } = await get(path, { ...params, company: COMPANY, page, pageSize: 1000 });
items.push(...body.items);
if (body.items.length === 0 || items.length >= body.total) return items;
}
}
const ledgers = await readAll("/v1/ledgers");
const allVouchers = await readAll("/v1/vouchers");
Each ledger in the list has name, guid, parent, gstin, panNumber and creditPeriodDays.
For a full ledger, with closing balance, addresses and contacts, call GET /v1/ledgers/:name.
Each voucher in the list has guid, voucherNumber, date, voucherType, partyName, narration,
amount, reference, irn, ewayBillNo and isCancelled. Lists do not include ledger entries.
For those, call GET /v1/vouchers/:guid once per voucher, and only for the ones you need.
Rows can shift between pages if a sync lands while you read, so a row may appear twice or be missed.
Store by guid so a repeat does no harm, and let the next run pick up a miss.
Pulling customers
Customers are ledgers whose parent is Sundry Debtors, or a group under it. There is no group filter
on /v1/ledgers, so read them all and filter. Walk /v1/groups to include subgroups:
function customersOf(ledgers, groups, root = "Sundry Debtors") {
const wanted = new Set([root.toLowerCase()]);
for (let grew = true; grew; ) {
grew = false;
for (const g of groups) {
const name = g.name.trim().toLowerCase();
const parent = (g.parent ?? "").trim().toLowerCase();
if (wanted.has(parent) && !wanted.has(name)) { wanted.add(name); grew = true; }
}
}
return ledgers.filter((l) => wanted.has((l.parent ?? "").trim().toLowerCase()));
}
const groups = await readAll("/v1/groups");
const customers = customersOf(ledgers, groups);
Incremental sync
Three steps, on a schedule you choose. Every few minutes is plenty, since the data behind it does not change faster than the extension syncs.
1. Skip work with /v1/status
Save lastSyncedAt per kind of record. If it has not moved, nothing has landed, so skip the read.
async function changedKinds(companyName, lastSeen) {
const { body: status } = await get("/v1/status");
const company = status.companies.find((c) => c.name === companyName);
if (!company) return { changed: [], status };
const changed = company.entities.filter(
(e) => e.lastSyncedAt && e.lastSyncedAt !== lastSeen[e.entityType],
);
return { changed, status };
}
entityType values include Ledger, Voucher and OutstandingBill.
Do not treat "unchanged" as "up to date". If tallyReachable is false, your copy may be behind
because nothing can land. Show that in your product, with lastSeenAt.
2. Re-read an overlapping window
from and to filter by voucher date, so a window covers new vouchers and recent edits. Make it wider
than you think you need. Accountants post late and back-date, so 45 days is a sensible start, and the
right number depends on your customer.
function daysAgo(n) {
return new Date(Date.now() - n * 86_400_000).toISOString().slice(0, 10);
}
async function syncRecentVouchers(store) {
const rows = await readAll("/v1/vouchers", { from: daysAgo(45) });
for (const v of rows) store.upsert(v.guid, v);
return rows;
}
Match by guid. Do not match by voucherNumber: numbers repeat across voucher types, and an edit in
Tally can change them.
3. Catch what the window misses
The window cannot see two things, so run a full comparison on a slower schedule, nightly or weekly:
- Back-dated edits. Someone changes a voucher from three months ago. It falls outside your window.
- Deletes. A deleted row stops appearing in lists. Nothing tells you it went.
Compare a full read against your store. Anything you hold that Tally no longer returns was deleted.
async function fullReconcile(store) {
const rows = await readAll("/v1/vouchers");
const seen = new Set(rows.map((v) => v.guid));
for (const v of rows) store.upsert(v.guid, v);
// A failed or empty read must never delete your data.
if (rows.length === 0) return { deleted: 0 };
const gone = store.guids().filter((guid) => !seen.has(guid));
for (const guid of gone) store.markDeleted(guid);
return { deleted: gone.length };
}
Guard this hard. If a response is empty or short, do not mark anything deleted. Compare
totalwith your previous count, and stop for a person to look if it dropped sharply. Soft-delete on your side so you can undo a bad run.
A voucher that is cancelled in Tally stays in the list with isCancelled: true. A voucher deleted in
Tally leaves the synced copy some time after the delete, and later than an edit would arrive.
Outstanding bills
GET /v1/outstandings returns the whole set for a company, with no paging, so read it as one snapshot.
See Integrate a CRM or SaaS.
Numbers can be strings
Parse every numeric field. amount on a voucher list is one to watch.
const toNumber = (v) => (v === null || v === undefined || v === "" ? 0 : Number(v));
Polling responsibly
Reads come from the synced copy, so they do not load the customer's Tally. Still, keep the schedule
reasonable. Use /v1/status to avoid reads that cannot find anything new, and handle 429 as described
in Errors.
A fresh=true read does not fetch from Tally, so it is not a way to get a newer answer now. See
Synced data and freshness.
