Developer guide
Inventory sync — the host integration guide
Your app knows when a job uses materials and when stock is bought. TheGuyBooks keeps the books. This guide shows how to send that stock movement into each client’s books, safely and exactly once, with the @theguysapp/books-host-sdk package or any HTTP client.
The package is ESM-only and needs Node.js >=22. Its current version and every change are on npm.
Whose stock is it?
Read this first. Every call names a tenant in its path: /v1/tenants/{tenantId}/inventory/…. That tenant is the shelf that moves. When a job used the Boss’s stock, post to the Boss’s tenant. When it used a crew member’s own stock, post to that crew member’s tenant.
- One host key may post to many tenants — every client you serve.
- One document never spans two tenants. A job that used both shelves posts TWO documents, one per tenant, each with its own
source_event_id. - Mappings are per tenant too. The same item in your app maps to the Boss’s item in the Boss’s books and to the crew member’s item in theirs.
- Your app decides which shelf was used. Books never guesses.
A job that used 2 bags from the Boss’s shelf and 1 bag from the crew member’s truck:
await books.usage.post(bossTenantId, {
source_event_id: sourceEventId('job', jobId, 'usage-boss-shelf'),
occurred_on: '2026-10-01',
lines: [{ external_id: 'mulch-bag', qty: '2' }],
});
await books.usage.post(crewTenantId, {
source_event_id: sourceEventId('job', jobId, 'usage-crew-shelf'),
occurred_on: '2026-10-01',
lines: [{ external_id: 'mulch-bag', qty: '1' }],
});Turn inventory connectivity on first
One step comes before any code, and only an owner of your host account can take it: turning inventory connectivity on in your host console. Until it is on, no inventory key can be minted. The console shows no inventory key tools, and the server refuses the mint itself, so there is no way around it. It is free, and it is done once for your whole account.
- Who: an owner of your host account. A developer seat sees the same place without the button: “Your software can send stock movements straight into each client’s books. It’s off for now — an owner turns it on here, and then inventory keys unlock in this section.”
- Where: your host console, Set up → Advanced: API & automation, the card titled “Inventory connectivity”.
- Tick the box “I accept the Terms of Service, including section 2.4 (Host API), version terms-of-service-2026-10-18”.
- Press “Turn it on”. It stays off until the box is ticked.
What you see after: the card gives way to the Inventory keys section, with one line under its heading — “Inventory connectivity is on since <the day>. Your install guide was sent to <your email> on <the day>.” — and a “Send it again” button. If the email has not gone out yet, the line ends “Your install guide has not been sent yet.” instead.
The install email: pressing “Turn it on” emails an install checklist to the owner who pressed it — a link to the inventory sync guide, the sandbox offer, the conformance check, the list each client’s owner works through in their books, and where to mint the key and find your client ids. It never carries a key. “Send it again” re-sends it, to whoever presses that button.
Who can have it: hosts on the white-label seat-block plan, the plan whose console has Set up → Advanced: API & automation. For any other plan the server refuses it: “Inventory connectivity is part of the white-label plan.”
Once it is on, the Inventory keys section mints inventory keys — up to 2 live at a time, each shown once.
Install and connect
npm install @theguysapp/books-host-sdk
import { BooksHost, BooksRefusal, BooksTransportError, sourceEventId } from '@theguysapp/books-host-sdk';
const books = new BooksHost({
baseUrl: process.env.BOOKS_BASE_URL!,
key: process.env.BOOKS_HOST_KEY!,
});| Ring | baseUrl | Keys start with |
|---|---|---|
| Sandbox — build and test here first | https://sandbox.theguybooks.com | tgb_test_ |
| Production — real books | https://theguybooks.com | tgb_ |
The sandbox is the preprod ring, with test data only: nothing there is real money, and it answers the /v1 API and nothing else. Want to test against fake books first? A sandbox workspace and a test key are provisioned on request: reply to your inventory install email, or write to support@theguys.app, and we set them up within one business day.
- Production keys come only from your host console: Set up → Advanced: API & automation → Inventory keys. We never email a key.
- A key works only on the ring that minted it: a
tgb_test_key on the sandbox, atgb_key on production. - A key has one scope, chosen when you mint it: an inventory key reaches the inventory calls and nothing else. The seven calls below take an inventory key, or a workspace key, which reaches every call (the scope table is under Keys and secret handling). You can hold 2 live inventory keys at a time, so you can roll one without downtime.
- Each client’s
tenantIdis listed under Your client ids on the same console page. Store it next to the client in your app. - The same client also creates your clients’ books, brings each buyer in, pauses, reinstates, removes and restores a client, and reads its reports, with a workspace key:
tenants.create,tenants.list,tenants.listAll,tenants.get,tenants.createOnboardingLink,tenants.updateOwner,tenants.bind,tenants.waitForClaimed,tenants.remove,tenants.restore,tenants.suspend,tenants.reinstate,tenants.exportandreports.get. That road is written up step by step athttps://theguybooks.com/docs/host-setup#connecting-your-clients. reports.getreads the balance sheet, profit and loss, accounts receivable aging, trial balance, adjusted trial balance or general ledger, in cents. The reports answer a paused client too, and a removed one until its export window closes. The general ledger covers at most one year per call.files.content(tenantId, fileId)reads one uploaded file’s bytes as aUint8Arraywith itsmimeType,fileName,byteSizeandetag, taking the ids from the export’sreceipt_filesrows; its refusals are typedBooksRefusals, and one whose malware scan is still pending carriesretryAfter, the seconds to wait before asking again.hosts.usageandhosts.subscriptionread your seats and your subscription. Any route the spec documents that has no method of its own is sent withbooks.request(method, path, body?)— the same retries, refusals and rate-limit handling as every call above.
The seven calls
Call 1, what is on the shelf: GET /v1/tenants/{tenantId}/inventory/items?as_of=YYYY-MM-DD. as_of is required. Each tracked item comes back with item_id, name, unit_label, external_id (your mapping, or null), available_units (a decimal string), as_of, pending_posts (your documents still queued that name it) and stale. The answer carries binding: false — see The contract below. It never carries cost or value.
const shelf = await books.items.available(tenantId, { asOf: '2026-10-01' });
for (const item of shelf.items) {
console.log(item.external_id, item.available_units, item.unit_label, item.pending_posts);
}Call 2, say which Books item your item is: PUT /v1/tenants/{tenantId}/inventory/mappings/{externalId} with name, unit_label and an optional unit_factor (how many Books units one of your units is; default 1). You PROPOSE; the tenant’s OWNER confirms it in Books. Books never matches on name by itself. The answer’s status is proposed, confirmed or refused, and it carries the mapping’s revision; a confirmed one also carries item_id, unit_mismatch and pending_change. Books does not email or notify the owner about a proposal; they see it under Books → Inventory → Connected apps → Mappings, where the tab shows how many wait.
A proposal can say more about the item. These fields are all optional: on_hand and on_hand_as_of, unit_cost and unit_cost_as_of, reorder_point, reorder_qty, lead_time_days, notes, observed_at and base_revision. Leave a field out and you say nothing about it: what Books holds from you stays. Send it as JSON null and you say it is cleared in your system.
- Units: send
on_hand,reorder_pointandreorder_qtyas counts of yourunit_label, andunit_costas the cost of ONEunit_label— exactly asqtyon your usage and purchase lines. Books converts them with theunit_factorthe owner confirmed.pending_change.fields[].valueechoes your numbers back unchanged: in your unit, never converted, a quantity written to four places (3reads back as3.0000). - The
itemblock of calls 3 and 4 reportsreorder_pointandreorder_qtyin the item’s own unit, itsunit_label, as Books holds them — never converted back to yours. To compare, multiply your number byunit_factor; with a factor of1the numbers are the same. - On a confirmed mapping, a proposal whose
unit_labeldiffers from the confirmed one answers 200 withunit_mismatch: true, and nothing of it is stored: no newrevision, no new pending change. Fix your unit, or ask the owner to re-confirm the mapping, then send it again. Thebase_revisioncheck comes first.
Your on_hand and unit_cost help the owner open the item in their books: Books shows them as a starting point for the owner’s own opening count and value, which the owner checks and saves. Books never writes stock or value from them, and derives no stock, value or money from anything a proposal carries. Your notes are shown to the owner and never written to the item. observed_at is when you saw these values: the owner sees it, and Books never uses it to order or decide anything.
Every mapping carries a revision, a whole number Books issues. It moves on every accepted change — a proposal that differs from your last one, the owner’s confirm, the owner’s apply or keep — and never when you send the same body again. Send the revision you last read as base_revision. If the mapping has moved on since, the proposal is refused 409 revision_conflict and nothing is changed: details.revision is the current revision and details.mapping is the mapping as calls 3 and 4 answer it. Look at it, then send your proposal again with the new base_revision. Leave base_revision out and Books takes the proposal as your latest word.
A proposal never changes a confirmed mapping — it becomes a pending change the owner applies or keeps in Books; nothing applies by itself. When your name, reorder_point, reorder_qty or lead_time_days differs from the Books item, those fields become ONE pending change: pending_change: { revision, received_at, fields: [{ field, value }] }, or null when nothing waits. A newer proposal replaces it only when those values change. A value the owner kept is remembered, so sending it again raises nothing. Your unit_label and unit_factor never change a confirmed mapping, and on_hand, unit_cost, their dates, notes and observed_at are never part of a pending change: the owner sees them as information.
const mapping = await books.mappings.propose(tenantId, 'mulch-bag', {
name: 'Mulch, 2 cu ft bag',
unit_label: 'bag',
unit_factor: '1',
on_hand: '24', // 24 bags
on_hand_as_of: '2026-10-01',
unit_cost: '4.50', // what ONE bag cost you
unit_cost_as_of: '2026-10-01',
reorder_point: '5',
reorder_qty: '20',
lead_time_days: 3,
notes: 'Keep off the ground.',
observed_at: '2026-10-01T14:30:00Z',
base_revision: lastRevision, // the revision you last read; leave it out the first time
});
// mapping.status stays 'proposed' until the owner confirms it.
// Store mapping.revision: it is your base_revision next time.
if (mapping.status === 'confirmed' && mapping.pending_change) {
// mapping.pending_change.fields waits for the owner to apply or keep.
}Calls 3 and 4, learn what the owner decided: GET /v1/tenants/{tenantId}/inventory/mappings/{externalId} reads one mapping, and GET /v1/tenants/{tenantId}/inventory/mappings?status=&cursor=&limit= pages through all of yours, newest proposal first (status is optional: proposed, confirmed or refused; limit 1 to 100, default 50). Each mapping carries its status, the owner’s item_id once confirmed, the host_item_name, host_unit_label and unit_factor, and proposed_at, confirmed_at and updated_at. This is how you learn a confirm: read the mapping, never propose again just to find out. An id you never proposed answers 404 mapping_not_found.
revision: the mapping’s current revision, the one to send asbase_revision(see call 2).item: the Books item a confirmed mapping points at, read-only —name,unit_label,active,reorder_point,reorder_qty,lead_time_daysandupdated_at(when the item or its stock settings last changed). It isnullunless the mapping is confirmed. Itsreorder_pointandreorder_qtyare in the item’s own unit (see Units under call 2). It never carries the item’s cost, value, quantity on hand or accounts.decisions: the owner’s latest decision on each field you proposed, as{ field, decision, revision, decided_at }.decisionisapplied(the owner took your value) orkept(the owner kept their own). It is empty until the owner decides something.
Read the mapping to learn an apply or a keep, the same way you learn a confirm. Books sends you no notice of either.
const current = await books.mappings.get(tenantId, 'mulch-bag');
if (current.status === 'confirmed') {
// The owner chose current.item_id: posts naming mulch-bag can post now.
// current.item is that item as Books holds it; current.decisions says what the owner applied or kept.
}
// Or everything still waiting for the owner:
const waiting = await books.mappings.list(tenantId, { status: 'proposed' });Call 5, stock used up: POST /v1/tenants/{tenantId}/inventory/usage — ONE document per call: source_event_id, occurred_on (YYYY-MM-DD), an optional memo, and 1 to 100 lines of external_id and qty (a decimal string greater than zero). Books answers 202 { event_id, status: queued } and posts it moments later.
const queued = await books.usage.post(tenantId, {
source_event_id: sourceEventId('job', jobId, 'usage'),
occurred_on: '2026-10-01',
memo: 'Job 1042, back garden',
lines: [{ external_id: 'mulch-bag', qty: '3' }],
});
// queued.event_id is Books’ id for this document.Call 6, stock bought: POST /v1/tenants/{tenantId}/inventory/purchases — the same shape, and each line also carries amount, the cost you actually paid for the line, as a decimal string. amount is the money Books posts. rate is optional: send it when you have an exact price per unit, and then qty × rate must equal amount. Leave it out when you only know the quantity and the total — 300 units for 100.00 has no exact four-place price — and Books shows amount ÷ quantity as the line’s rate. It posts as an expense paid from the account the owner chose, and answers 202 like usage.
await books.purchases.post(tenantId, {
source_event_id: sourceEventId('order', orderId, 'purchase'),
occurred_on: '2026-10-01',
lines: [
{ external_id: 'mulch-bag', qty: '10', rate: '4.50', amount: '45.00' },
{ external_id: 'stake', qty: '300', amount: '100.00' }, // no exact price: leave rate out
],
});Call 7, what happened: GET /v1/tenants/{tenantId}/inventory/posts?cursor=&limit= pages through your posts for the tenant, newest first (limit 1 to 100, default 50). Each post has its status: queued, posted (with every document_id and journal_entry_id it wrote), refused (with reason, message and details) or voided (a delete you sent — voided names the version it took back; see Idempotency and corrections). next_cursor fetches the next page, and is null on the last one. There are no webhooks in v1, so you poll this.
const page = await books.posts.list(tenantId, { cursor, limit: 100 });
for (const post of page.posts) {
console.log(post.source_event_id, post.correction_seq, post.status, post.refused?.reason);
}
// Or let the SDK walk the pages for you (a long-running worker):
for await (const outcome of books.posts.follow(tenantId, { cursor })) {
await saveOutcome(outcome);
}On its own, posts.follow never stops: after the last page it polls for new outcomes until you stop iterating. A cron job or a serverless function must end its run, so give it a stop: maxPages (end after that many pages), until(page) (end after the page it returns true for) or signal (an AbortSignal; aborting ends the walk before its next request, or at once while it waits between polls). Every outcome already read is yielded before it ends, and ending is a normal end of the loop, never an error. The next run reads from the newest page again; store outcomes keyed by event_id, so seeing one twice is harmless.
// A cron run: read the newest pages, then stop before the platform’s time limit.
for await (const outcome of books.posts.follow(tenantId, { maxPages: 5, signal: AbortSignal.timeout(50_000) })) {
await saveOutcome(outcome);
}The outbox pattern
Never call Books in the middle of your own database transaction. If your transaction rolls back after the call, Books has a document your app forgot. Use an outbox instead — four steps:
- In the SAME transaction that finishes the job, write an outbox row: the tenant, the document body and its
source_event_id. - After the commit, a worker sends each unsent row to Books.
- Store what Books answered on the row:
event_idon success, the refusalcodeon a refusal. - Poll the outcomes and store each post’s final
statuson its row.
// db is your own database layer.
for (const row of await db.outbox.unsent()) {
try {
const answer = await books.usage.post(row.tenantId, row.body);
await db.outbox.markSent(row.id, answer.event_id);
} catch (err) {
if (err instanceof BooksRefusal) {
await db.outbox.markRefused(row.id, err.code, err.message);
} else if (err instanceof BooksTransportError) {
// Leave the row unsent. The next run sends the SAME body again.
} else {
throw err;
}
}
}Because every row carries its own source_event_id, sending a row twice is safe — see the next section.
Idempotency and corrections
source_event_id is required on every write. Make it stable — build it from your own record, never from the clock or a random number. sourceEventId('job', jobId, 'usage') does that for you.
- Same
source_event_id, same body: Books answers 200 with that document’s current outcome. Nothing posts twice. - Same
source_event_id, different body: 422idempotency_mismatch. Use a new id for a new document, or the nextcorrection_seqto change or delete this one.
You can change OR delete a document after you sent it. To change it, send the SAME source_event_id with correction_seq set one higher (the first version is 1) and the WHOLE new document. Books takes back what the earlier version posted and posts the new version in full, whether or not the date moved. The books end up as if only the new version had ever been sent.
// Job 1042 really used 4 bags, not 3.
await books.usage.post(tenantId, {
source_event_id: sourceEventId('job', jobId, 'usage'),
correction_seq: 2,
occurred_on: '2026-10-01',
lines: [{ external_id: 'mulch-bag', qty: '4' }],
});To delete it — the job or the purchase was deleted in your app — send a VOID: the same source_event_id, the next correction_seq, void: true, and nothing else (no lines, occurred_on or memo). Books takes back what the earlier version posted and posts nothing. On the outcomes cursor that version reads voided, and voided names the version it took back (null when nothing was standing — for example, the earlier version had been refused).
// Job 1042 was deleted in your app.
await books.usage.void(tenantId, {
source_event_id: sourceEventId('job', jobId, 'usage'),
correction_seq: 3,
});
// The same for a deleted purchase:
await books.purchases.void(tenantId, {
source_event_id: sourceEventId('order', orderId, 'purchase'),
correction_seq: 2,
});- A correction or a void waits for the version before it to finish. Sent too soon, it answers 409
previous_version_pending— retry it a few seconds later. - If Books cannot take the earlier version back — its stock is already used (
insufficient_stock) or its date is in a closed period (period_closed) — the correction or void is refused as a whole, withdetails.phaseset tovoid_previousanddetails.documentIdnaming the document that could not be taken back. The earlier version stays posted, every document of it, and nothing of the new version posts. - A void is a version like any other: the same void again answers 200 with its outcome, and a void with
correction_seq1 is refused 400invalid_body— there is nothing to void yet. - When the owner fixes a refusal in Books and presses Retry, Books posts the same body as the next version. You will see it on the outcomes cursor with a higher
correction_seq. - A revoked key stops new posts at once. It destroys nothing: documents Books already accepted still post.
Refusals, and who fixes them
Every error has one shape: { error, message, details }. The SDK throws it as BooksRefusal with code, message, details and status. Some answers come back on the call itself; others come back later, as a refused post on the outcomes cursor.
Who fixes it. Most refusals are fixed by the tenant’s OWNER inside Books, under Books → Inventory → Connected apps. Your support team is their first stop: tell the owner what the refusal says and where to fix it. Never send them to TheGuyBooks.
What each client’s owner does in their books, under Books → Inventory → Connected apps — a list you can forward:
- Turn stock tracking on in their books.
- Track each item your app will move as inventory.
- Confirm each mapping your app proposes — the right item and the unit factor — or refuse it.
- For a proposed item they do not have yet, create it in their books straight from the proposal with Create it in my books — one at a time, or every proposed item at once with Review all proposed.
- When your app proposes a change to an item they already mapped, apply it or keep their own under Mappings — nothing changes until they decide.
- Choose the account your purchases are paid from.
- When stock runs short, record the missing purchase or count.
- When an item has no cost yet, record a purchase or an opening balance.
- When a bank or card line may already be the same purchase, decide: the same purchase, or a different one.
- Reopen a closed period if a document has to post on a date inside it — only the owner can.
- After fixing any of these, press Retry on the document under Needs attention.
On the call itself:
| Code | What it means | Who fixes it |
|---|---|---|
invalid_body (400) | A field of the body is wrong. details.field names it and details.issue says why — for example line_arithmetic_mismatch when a purchase line sends a rate and qty × rate is not amount. | You — fix the document and send it again. |
invalid_report_params (400) | A query value is missing or wrong, such as as_of on the items read or a cursor Books did not issue. | You. |
body_too_large (413) | The body is over the size limit. | You — send smaller documents (at most 100 lines each). |
idempotency_mismatch (422) | This source_event_id and correction_seq were already used with a different body. On POST /v1/tenants: this external_id already names a client created with a different body (details.tenant_id). | You — a new id, or the next correction_seq; for a client, a new external_id, or the identical body to retry. |
previous_version_pending (409) | The version before this correction has not finished posting. | You — retry in a few seconds. |
unauthorized (401) | The key is missing, wrong, revoked or expired. | You — use a live key from your console. |
insufficient_scope (403) | The key’s scope does not reach this call — see the scope table under Keys and secret handling. | You — use a key whose scope reaches the call. |
host_suspended (403) | Your host account is paused. | You — in your host console. |
tenant_not_found (404) | That tenant is not one of your clients. | You — check the id under Your client ids. |
mapping_not_found (404) | You never proposed a mapping for that item id in these books (reading one mapping). | You — propose it first (call 2). |
revision_conflict (409) | On a proposal: the base_revision you sent is not the mapping’s current revision, because the mapping changed since you read it. Nothing was changed. details.revision is the current revision and details.mapping is the mapping as calls 3 and 4 answer it. | You — look at the mapping, then send your proposal again with the current base_revision. |
tenant_suspended (403) | That client’s books are paused. | You — reinstate the client when you are ready. |
not_found (404) | There is no such call. | You — check the path. |
On the client calls — creating a client’s books, its onboarding link and its owner, setting your own id on it, removing it, restoring it and exporting it:
| Code | What it means | Who fixes it |
|---|---|---|
tenant_removed (409) | The client was removed from your roster. Every call on it answers this except reading it, removing it, restoring it, exporting it and reading its reports. details carries tenant_id, removed_at and export_until, the last day its books can be exported. | You — within 24 hours restore it in your console or with POST /v1/tenants/{tenantId}/restore, or create the client again with a new external_id; after that e-mail support@theguys.app — we restore it, with its team’s access, within the retention window (90 days); its books stay exportable with GET /v1/tenants/{tenantId}/export until then. |
external_id_bound (409) | On POST /v1/tenants: this external_id is set on a client you made in the console, with PUT /v1/tenants/{tenantId}/external-id. details.tenant_id names it. | Nobody — it is yours already: read it with GET /v1/tenants/{tenantId} instead of creating it. |
external_id_already_set (409) | On PUT /v1/tenants/{tenantId}/external-id: the client already carries a different external_id (details.external_id), and it never changes once set. | You — keep the id it carries; sending that same id again is safe. |
external_id_taken (409) | On PUT /v1/tenants/{tenantId}/external-id: another of your clients already carries this external_id (details.tenant_id). | You — use a different id, or work with the client that carries it. |
tenant_claimed (409) | The owner already reached these books, so no link can be made and the owner’s address can no longer be changed. | Nobody — send the owner to your sign-in page. |
owner_missing (409) | The client has no owner login yet, so no link can be made. | You — set the owner with PUT /v1/tenants/{tenantId}/owner. An address already on file is retried by itself. |
return_url_not_allowed (400) | return_url is not on a return address you registered. | You — register it in your console: Set up → Advanced: API & automation → Return addresses. |
onboarding_link_rate_limited (429) | More than 10 links for one client in the last hour. | You — wait Retry-After seconds (also details.retry_after); the SDK never waits this one out for you. |
owner_email_rate_limited (429) | On POST /v1/tenants and PUT /v1/tenants/{tenantId}/owner: this owner address was already named 3 times in the last hour. That number is kept per address, across every caller, console invitations included. Nothing was written. | You — wait Retry-After seconds (also details.retry_after), then send it again. See Rate limits and retries. |
seat_limit_reached (402) | Every seat on your account is taken, so the client was not created or restored. On a restore, details.seats_used and details.seat_limit say how many. | You — add a block in your console, then send the call again. |
undo_expired (409) | The client was removed more than 24 hours ago, so the undo window has closed. details carries tenant_id, removed_at and undo_window_hours. | You — e-mail support@theguys.app to restore it; we restore it, with its team’s access, within the retention window. |
export_window_closed (409) | The client was removed more than 90 days ago, so its books can no longer be exported. details carries tenant_id, removed_at and export_until. | Nobody — email support@theguys.app if you believe this is wrong. |
The export lists every uploaded file as a receipt_files row — id, file name, type, size, scan status and the document it belongs to — without the bytes. Fetch each file with GET /v1/tenants/{tenantId}/files/{fileId}/content: the answer is the raw file with its content type and file name, or a JSON refusal from the route's error list. The scan_status in the export row is a cache and may read pending for a clean file, so fetch and handle the refusal codes rather than filtering on it. Your client must follow HTTP redirects on this route: today it answers 200 with the bytes, and a future release may answer 302 to a short-lived link. storage_path is internal and is never an input to any call.
On the file call, GET /v1/tenants/{tenantId}/files/{fileId}/content:
| Code | What it means | Who fixes it |
|---|---|---|
file_not_found (404) | No uploaded file with that id belongs to this client. | You — take the id from the export’s receipt_files rows. |
file_scan_pending (503) | The file’s malware scan has not finished. | Nobody — wait Retry-After seconds and fetch it again. |
file_scan_blocked (403) | The file failed its malware scan, or the scan could not complete. It is not served. | Nobody on your side — skip the file. |
file_not_scannable (403) | The scanner could not read the file, such as a password-protected PDF. It is not served over the API. | Nobody — the owner can still download it in their books. |
file_not_scanned (409) | The file has no scan verdict and none arrived in time. We have been alerted. | Us — skip the file; it is not coming on a retry. |
file_scan_unavailable (503) | The file’s scan status could not be read. | Nobody — wait Retry-After seconds and fetch it again. |
Later, as a refused post (refused.reason):
| Code | What it means | Who fixes it |
|---|---|---|
unmapped_item | A line names an external_id with no mapping in this tenant’s books. | You propose the mapping; the owner confirms it and presses Retry. |
mapping_not_confirmed | The mapping is proposed but the owner has not confirmed it yet. | The owner — confirm it under Mappings, then Retry. |
item_not_tracked | The Books item the mapping points at does not track stock. | The owner. |
item_inactive | The Books item the mapping points at has been made inactive. | The owner — reactivate the item or re-map it, then Retry. |
inventory_not_enabled | Stock tracking is switched off in these books. An owner can turn it off and back on; your mappings are kept while it is off. | The owner. |
insufficient_stock | The shelf would go below zero. details.shortages lists each short item: itemId, itemName, requestedQty, onHandQty, unitLabel and dipDate (the first day it would dip). details.phase is void_previous when the shortage came from taking back the earlier version of a correction. | The owner — record the missing purchase or count, then Retry. |
date_before_costing_start | The date is before these books started tracking stock costs. | The owner, or you if the date was wrong (send a correction). |
invalid_quantity | A quantity rounds to zero in Books once the mapping’s unit_factor is applied. | You — check the quantity; the owner checks the mapping’s unit. |
no_value_change | The item has no cost in the books yet, so using it changes nothing. | The owner — record a purchase or opening balance, then Retry. |
host_purchase_account_unset | The owner has not chosen which account your purchases are paid from. | The owner — choose it in Connected apps, then Retry. |
invalid_pay_from_account | The chosen pay-from account cannot pay a purchase. | The owner — choose another account, then Retry. |
possible_duplicate_feed_line | A bank or card line already in the books fits this purchase; details names it: feed_entry_id, occurred_on, amount, posted_by (rule, person or unknown) and the rule. | The owner decides: the same purchase (nothing to do) or a different one (Retry posts it). |
period_closed | The date falls in a period the owner has closed. | Nobody on your side. Only the owner can reopen the period — or you post the change on an open date. |
The one with no fix on your side. period_closed is the only refusal your app cannot work around by changing what it sends for that date. The owner closed those books on purpose; tell them, and let them decide.
refused.reasonis an open set: Books may add a code. Handle one you do not know as a refusal for the owner to look at in Books, and show itsmessage. The spec typesdetailsforinsufficient_stockandpossible_duplicate_feed_line; every other code carries a plain object.unit_mismatchis not a refusal. A mapping answer carriesunit_mismatch: truewhen the owner confirmed the item with a different unit than the one you sent. Nothing of that proposal is stored — no newrevision, no new pending change — because its numbers are in a unit the owner did not confirm. Fix your unit and send it again, or tell the owner; only they can re-confirm it.- You will never see
mixed_cogs_accounts: Books splits a document by cost account by itself. rate_limited(429) andrate_limiter_unavailable(503) are not refusals. Wait, then send the same request again — see Rate limits and retries.internal_error(500) is a failure on Books’ side, not a refusal. Retry it like a network failure, with the samesource_event_id. Itsdetails.status_pageis the status page (https://theguybooks-status.betteruptime.com), which says whether the trouble is ours.
The contract
What Books promises, and what it does not. These sentences are the rules; build to them.
Not a reservation. Every items answer says binding: false and carries this sentence: “the number was true as of as_of; it is not a reservation; a post against it may still be refused.”
- Read availability when you need it, and never cache it. A number from an hour ago is not a number about now.
- A post into a closed period is refused, and there is no host-side remedy (see Refusals).
- The API is
/v1. Changes to it are additive only: new fields and new calls, never a renamed or removed one. A breaking change would be a new/v2. - Answers only grow: ignore any response field you do not know. A new field can appear in any answer at any time, and your code must keep working when one does.
Rate limits and retries
- Three budgets: each key may make 120 calls every 60 seconds, and each IP address 240. On top of that, your whole host account may make 300 calls every 60 seconds, shared by all your keys. Two keys never buy two budgets.
- Every answer carries
RateLimit-Limit,RateLimit-RemainingandRateLimit-Reset(seconds) for the per-key budget. Slow down beforeRateLimit-Remainingreaches zero. - Over any of the three budgets: 429
rate_limitedwithRetry-After. Wait that long, then send the same request again. - One more limit, per owner address: an address can be named 3 times every 3600 seconds, by
POST /v1/tenantswith anowner_email(eitherowner_invite) and byPUT /v1/tenants/{tenantId}/owner. It counts the address itself, not your key or the client, and invitations sent from your console count too. Past it: 429owner_email_rate_limitedand nothing is written. ItsRetry-After(alsodetails.retry_after) can be as long as 3600 seconds, so the SDK throws it at once and never retries it. - These do not count against an address: a create sent again with an
external_idthat already names your client, setting the owner address a client already has, and any call refused for some other reason. - If Books cannot reach its rate limiter, writes answer 503
rate_limiter_unavailablewithRetry-After. Nothing was recorded, so nothing is lost: send it again later. Reads stay open.
Retry a network failure or a 5xx answer with a growing wait between tries, and ALWAYS with the SAME source_event_id — that is what makes the retry safe. NEVER retry a refusal: the same document gets the same answer every time. Fix the cause, or send a correction.
The SDK does all of this for you, and throws BooksTransportError only after its retries run out.
Books requires no polling interval. Any cadence inside the budgets works — every few minutes is typical. A refused post already names the mapping to re-read: unmapped_item and mapping_not_confirmed carry each line’s external_id in details.lines.
Keys and secret handling
Every key has one scope, chosen when you mint it, and each scope has its own name in your console:
| Scope | Name in your console | What it reaches | Most live at a time |
|---|---|---|---|
full | Workspace key | every call the API has, the inventory calls included | 2 |
tenant-lifecycle | Automation key | pause and reinstate a client, nothing else | 5 |
inventory | Inventory key | the 7 inventory calls, nothing else | 2 |
- Keep the key on your server only. Never put it in a page your visitors load, a mobile app, or a client bundle.
- Keep it in your environment or a secret manager. Never commit it to a code repository.
- Each key is shown ONCE, when you mint it. Copy it straight into your secret store.
- Think a key leaked? Roll it in your console. Roll mints a new key and keeps the old one working for the overlap you pick (1h, 24h, 7d) while you switch over; then the old one stops.
- Build against the sandbox with a
tgb_test_key. Use atgb_key only on production.
# .env on your server — never in the browser BOOKS_BASE_URL=https://sandbox.theguybooks.com BOOKS_HOST_KEY=tgb_test_…
The conformance check
Going live on production: the check is OPTIONAL. Nothing in Books requires it before your first real post. Run in its inventory mode, it leaves two things in the client’s books: the proposed mapping conformance-probe, which the owner must REFUSE, and two refused test documents under Needs attention.
The alternative is one real usage and one real purchase of a test item, then a void of each (see Idempotency and corrections in the inventory sync guide). That leaves two voided documents, and the test items with their inventory accounts at zero. The owner of the books decides which of the two to leave behind.
The package’s command has two modes. The inventory mode, the default, proves your key, your base URL and a tenant are wired correctly:
BOOKS_HOST_KEY=tgb_test_… npx @theguysapp/books-host-sdk conformance --base-url https://sandbox.theguybooks.com --tenant <tenantId>
- It only READS and triggers REFUSALS. It posts nothing by itself, so it is safe on production too.
- It reads the items, proposes a mapping and reads it back, sends a usage post that is refused, sends it again to prove the replay, sends a different body to prove the 422, and reads the outcomes cursor and a page of mappings.
- It leaves things behind in the tenant’s books: the proposed mapping called
conformance-probe, and two refused test documents in Needs attention (under Connected apps).
Tell the owner: refuse the probe, never confirm it. The owner should REFUSE the conformance-probe mapping in Connected apps and never confirm it. A confirmed probe followed by Retry on one of the refused test documents WOULD post a real usage document.
The onboarding mode certifies the road that brings a buyer in — create, link, landing page — with your workspace key:
BOOKS_HOST_KEY=tgb_… npx @theguysapp/books-host-sdk conformance --mode onboarding --base-url https://theguybooks.com --owner-email <an address you control> --return-url <https://your-app/welcome>
- It reads your seats first; when every seat is taken it stops there with
seat_limit_reached, and nothing is made. - It creates a throwaway client called “Conformance check <time>” with
owner_invite: link, reads it asinvited, mints its onboarding link on your--return-url(an origin you registered under Return addresses), opens the landing page with a plain GET and expects the client’s name, reads the client as stillinvited(opening the page spends nothing), then removes the client and reads it back removed. - It leaves nothing on your roster: the client is removed at the end, even when a check fails. If the remove itself fails, the output names the client to remove in your console.
- It does NOT certify
startedorclaimed: both need the buyer to press the button on the landing page. - A login may be made for
--owner-email, so use an address you control. The owner email is held and never goes out: the client is removed seconds after it is made, and a removed client is never emailed. - Run it on production, where the landing page is public. On the sandbox the links open on our login-walled preview (Vercel Deployment Protection), so the landing check fails there with a line that names the wall; the steps before it still count.
The spec and the changelog
GET /v1/openapi.json (no key needed) is the OpenAPI 3.1 document of these calls, generated from the same code that checks every request. Point any OpenAPI tool at it to build a client in your own language. The document describes the whole host API, the client calls included, although its title says inventory.
Every change to /v1, newest first:
- 2026-11-16 — GET /v1/tenants/{tenantId}/files/{fileId}/content no longer sends Content-Length. The web framework's November 2026 security release stops a route from setting that header. Nothing else about the answer changed: the bytes, Content-Type, Content-Disposition and ETag are as before. Read the file's size from the bytes you received. SDK 0.9.1 does it for you: files.content(...).byteSize is always the length of data. On SDK 0.9.0 and earlier it reads null from this day.
- 2026-11-16 — Owner emails: a time on a held email, and a limit per owner address. Every earlier request and answer is unchanged and only grows, except the one new refusal below. (1) The onboarding block of every client answer (GET /v1/tenants, GET /v1/tenants/{tenantId}, and the answers of the owner, external-id, remove and restore routes) carries a new field, owner_email_held_until. When the client has reached its limit of 5 owner emails in 24 hours and an email is still owed, it is the time (UTC) before which that email will not be sent; the email then goes out by itself. Otherwise it is null. (2) An owner address can be named at most 3 times an hour: by POST /v1/tenants when it creates a client with owner_email (owner_invite email or link), and by PUT /v1/tenants/{tenantId}/owner when it changes the address. The count is per address, not per client or per key, and invitations sent from the console count too. Past it, the call is refused 429 owner_email_rate_limited (new) with Retry-After and details.retry_after, and nothing is written. Not counted: a create that replays an external_id you already used, an owner change to the address already on file, and any call refused for another reason. Wait Retry-After seconds, then send the same call again. (3) SDK 0.9.0 ships with this change: the new field in its types, owner_email_rate_limited in RefusalCode (thrown at once, never retried by the SDK), and a README that carries the 2026-11-15 entry for the first time.
- 2026-11-15 — Changing a client's owner no longer resets the day's limit of owner emails. The request and the answer keep the same fields. (1) A client's owner is emailed at most 5 times in any 24 hours. Before, PUT /v1/tenants/{tenantId}/owner started that count again, so the new owner was always emailed at once. Now the count carries across the change: when the limit is reached, the change is still saved, and the email to the new owner goes out by itself once the limit clears. (2) The route's description and its owner_email field's description now say so.
- 2026-11-08 — Stock tracking can be turned off, and one new refusal. Every earlier request and answer is unchanged and only grows. (1) A client's owner can now turn stock tracking off in Books, and back on. While it is off, every inventory post (usage or purchase) is refused inventory_not_enabled, the code a client that never turned tracking on already answers, until the owner turns it back on; reads, mapping proposals and confirmed mappings stay as they are, and turning it back on keeps every mapping. (2) A post naming a Books item the owner has made inactive is refused item_inactive (new): details.lines names each such line by index and external_id. The owner reactivates the item or re-maps it, then retries. refused.reason stays an open set. (3) In GET /v1/tenants/{tenantId}/export, the inventory_settings row carries two new fields: disabled_at, when the owner turned stock tracking off, and disabled_by, the user who did; both are null while tracking is on. A new field on an existing row does not change schema_version, which stays 4: answers only grow, and clients ignore any response field they do not know. (4) SDK 0.8.0 ships with this change: its README lists item_inactive.
- 2026-11-07 — New: GET /v1/tenants/{tenantId}/files/{fileId}/content returns one uploaded file's bytes. The export's receipt_files rows are the list; uploaded files are no longer the one thing the export does not cover.
- 2026-11-03 — Two new fields on export rows. Every earlier request and answer is unchanged and only grows. (1) In GET /v1/tenants/{tenantId}/export, each estimates row carries client_key: a token the estimate editor sends so a save that is retried, or the same form saved twice, makes one estimate. It has no business meaning; null when none was sent. (2) Each receipt_files row carries estimate_id: the estimate the file is attached to, null when it is attached to something else or to nothing. A file attached to an estimate is copied, as a new row with its own id, onto the invoice or sale the estimate becomes. A new field on an existing row does not change schema_version, which stays 4: answers only grow, and clients ignore any response field they do not know.
- 2026-11-01 — Estimates in the export. Every earlier request and answer is unchanged and only grows. (1) GET /v1/tenants/{tenantId}/export answers schema_version 4: the document also carries five new keys, right after deposit_payments: estimates (the quotes the owner sends a customer), estimate_lines (their lines), estimate_revisions (the frozen copy of each one sent), estimate_events (each estimate's history: sent, viewed, accepted, declined and the rest) and estimate_conversions (the invoice or sale an estimate became). They are written by the books' estimates feature, so they are empty arrays until the owner makes an estimate. The links a customer opens to read an estimate are never in the document. (2) Each customers and crm_contacts row carries a new field, email, null when none is stored. A new field on an existing row does not change schema_version: answers only grow, and clients ignore any response field they do not know. (3) SDK 0.6.0 ships with this change.
- 2026-10-31 — A client's reports for every client you can export, three new reports, and refusal lists per route. Every earlier request and answer is unchanged and only grows. (1) GET /v1/tenants/{tenantId}/reports/{report} answers an active client, a suspended one, and a removed one for 90 days after the remove, as the export does; after that it is refused 409 export_window_closed (details.tenant_id, removed_at, export_until), the export's exact answer. It no longer answers 403 tenant_suspended or 409 tenant_removed. The one tenant_removed message now ends: its books can still be exported with GET /v1/tenants/{tenantId}/export, and its reports read with GET /v1/tenants/{tenantId}/reports/{report}, until the day its export window closes. (2) Three new report ids: trial-balance and adjusted-trial-balance (as_of, and basis, accrual or cash), and general-ledger (from, to, and basis). The general ledger covers at most one year per call: to must fall on or before the day before from's anniversary, and a wider range is refused 400 invalid_report_params naming to. Amounts are integer cents, from the same engines as the books' own screens. (3) Every route's refusals in this spec are now its own: a route names only the codes it can answer, status by status. The export's 403, for example, names host_suspended and insufficient_scope and no longer tenant_suspended, which it never answered; a route that works on a client's books names tenant_suspended (403) and tenant_removed (409). No refusal body changed. (4) SDK 0.5.0 ships with this change: reports.get(tenantId, report, query), typed by the report it answers.
- 2026-10-25 — The item bridge: a richer mapping proposal, a revision on every mapping, and the owner's apply or keep. Every earlier request and answer is unchanged and only grows. (1) PUT /v1/tenants/{tenantId}/inventory/mappings/{externalId} accepts optional on_hand, on_hand_as_of, unit_cost, unit_cost_as_of, reorder_point, reorder_qty, lead_time_days, notes, observed_at and base_revision. Each is a statement on its own: omitted means no statement, JSON null means cleared in your system. on_hand, reorder_point and reorder_qty count your unit_label, and unit_cost is the cost of one unit_label, exactly as qty on a usage or purchase line; Books converts them with the confirmed unit_factor. on_hand and unit_cost are a pre-fill for the owner's own opening count and value, never written to the books; Books derives no stock, value or money from them. notes are shown to the owner and never written to the item; observed_at is shown and never used to decide anything. (2) Every mapping carries revision, a whole number Books issues: it moves on every accepted change (a proposal that differs, the owner's confirm, the owner's apply or keep) and never on the same body sent again, and every PUT answer carries it. A base_revision that is not the current revision is refused 409 revision_conflict (new; details.revision, and details.mapping as the GET answers it), and nothing changes. (3) A proposal still never changes a confirmed mapping. A name, reorder_point, reorder_qty or lead_time_days that differs from the Books item becomes ONE pending change the owner applies or keeps in Books; the PUT answer carries it as pending_change { revision, received_at, fields: [{ field, value }] }, value echoing yours in your unit, never converted, or null when nothing waits. Nothing applies by itself, and a value the owner kept raises nothing when sent again. A different unit_label on a confirmed mapping answers unit_mismatch: true, as before, and nothing of that proposal is stored: no new revision, no new pending change. (4) GET /v1/tenants/{tenantId}/inventory/mappings/{externalId} and GET /v1/tenants/{tenantId}/inventory/mappings carry revision, item (the confirmed Books item, read-only: name, unit_label, active, reorder_point and reorder_qty in the item's own unit, lead_time_days and updated_at; null unless confirmed; never cost, value, on-hand or accounts) and decisions ([{ field, decision: applied or kept, revision, decided_at }], the owner's latest per field, empty when none). Read the mapping to learn an apply or a keep. (5) Answers only grow: clients ignore any response field they do not know. (6) GET /v1/tenants/{tenantId}/export answers schema_version 3: the document also carries host_mapping_changes, the owner's apply and keep decisions on host proposals. (7) SDK 0.4.0 ships with this change.
- 2026-10-25 — Clarified, nothing changed: every request and answer is exactly as before. (1) How inventory connectivity is turned on, and what it unlocks: an owner of the host account turns it on once, in the host console under Set up, Advanced: API & automation, on the Inventory connectivity card (accept the Terms of Service, including section 2.4, then Turn it on). It comes with the white-label seat-block plan. It emails an install checklist to the owner who pressed it and unlocks inventory keys; until it is on, an inventory key cannot be minted, because the server refuses the mint. (2) One scope table: a full (workspace) key reaches every call, the inventory calls included; a tenant-lifecycle (automation) key reaches suspend and reinstate only; an inventory key reaches the seven inventory calls only. The insufficient_scope refusal points at it. (3) Three request budgets, each enforced: per key, per IP address, and per host, shared by every key the host holds; the RateLimit-* headers report the per-key budget. (4) The conformance check is optional before going live. It leaves the conformance-probe mapping to refuse and two refused documents; the alternative, one real usage and one real purchase each voided, leaves two voided documents; the owner of the books decides. Books never emails the owner about a proposed mapping, and no polling interval is required. (5) This document describes the whole host API, the client calls included, although its title says inventory. (6) SDK 0.3.4, shipping with this change: its README carries these sections and names the package version, and the conformance spec check pins the OpenAPI version, the API version v1 and the seven inventory operations instead of the document title. The host setup guide, the inventory sync guide and the new /docs page say the same.
- 2026-10-19 — Your own id on a client made in the console, the client list in pages, and a fuller export. Every earlier answer is unchanged and only grows. (1) PUT /v1/tenants/{tenantId}/external-id (new) sets external_id, your own id for the client, on a client that has none (one made in the console): once, and then it is frozen. Sending the id the client already carries answers 200 with the client and changes nothing. It is refused 409 external_id_already_set (new) when the client already carries a different id (details.external_id), 409 external_id_taken (new) when another of your clients carries this one (details.tenant_id), and 409 tenant_removed for a removed client; a suspended client can be bound. It needs a full key, and every bind is written to the client's audit trail. (2) POST /v1/tenants with an external_id bound that way answers 409 external_id_bound (new; details.tenant_id names the client): it is yours already, so read it with GET /v1/tenants/{tenantId}. For a client your software created, the replay of the same body (200) and a different body (422 idempotency_mismatch) are unchanged. (3) GET /v1/tenants pages: limit (1-100) answers that many clients, and cursor carries on after them. Every answer now carries next_cursor, null when there are no more. Without limit the answer is the whole list, as before, up to 1,000 clients, with next_cursor set when there are more. The filters and the page compose; a cursor this API did not issue is refused 400 invalid_report_params. (4) GET /v1/tenants/{tenantId}/export answers schema_version 2: the document also carries team (who had access: user_id, role, email, member_since, and source, live for a current member or snapshot for the access a removed client had when it was removed, with snapshotted_at) and the saved reports as custom_reports and management_reports. Uploaded files are listed as receipt_files rows without their bytes. (5) GET /v1/tenants/{tenantId}/reports/{report} now answers invalid_report_params with message and details.param too, the envelope every other route answers; its param and detail stay. (6) Clarified, nothing changed: a key starts with tgb_ on production and tgb_test_ on every other ring; check how a key starts, never its length, which may grow. The host setup guide now says so. (7) SDK 0.3.3, shipping with this change: tenants.bind, tenants.list takes cursor and limit and answers next_cursor, and tenants.listAll walks every page.
- 2026-10-18 — GET /v1/tenants finds a client in one call. Every earlier answer is unchanged and only grows. (1) Each row now carries the whole onboarding block: state, owner_email, invited_at, link_issued_at and claimed_at, the same block GET /v1/tenants/{tenantId} answers, so a client made in the console is found and read without a second call. (2) Two filters, either or both: owner_email (compared trimmed and lower-cased, the way the address is stored; a client with no owner address never matches) and external_id (exact, as you sent it on create). Both sent, both must match. A filter that matches several clients answers several, oldest first; no match answers 200 with an empty tenants list; a removed client still lists, with its block. (3) A filter sent empty (or owner_email sent as only spaces) is refused 400 invalid_report_params naming it (param, detail, details.param), and so is a query key the route does not know, which it used to ignore. (4) SDK 0.3.2, shipping with this change: tenants.list takes { ownerEmail, externalId }; tenants.list() with no argument is unchanged.
- 2026-10-18 — Export a client's books, and one answer for a removed client. (1) GET /v1/tenants/{tenantId}/export (new) answers one client's complete books as ONE versioned JSON document, streamed: schema_version, generated_at, the tenant, one array per table of the books (journal entries and their lines, the chart of accounts, customers, vendors, items with their quantity on hand, classes, invoices, bills, payments, the uploaded files as receipt_files rows without their bytes, bank transactions, rules, CRM, mileage, reports and settings), then counts, and complete: true as the LAST key. A document without complete: true was cut short, and its error key says why. It can be tens of megabytes. It answers an active client, a suspended one, and a removed one for 90 days after the remove; after that 409 export_window_closed (a new code; details.tenant_id, removed_at, export_until). It needs a full key (a tenant-lifecycle or inventory key is refused 403 insufficient_scope), and every export is written to the client's audit trail. (2) A REMOVED client now answers 409 tenant_removed where it used to answer 403 tenant_suspended: on every route but the tenant read, the remove, the restore and the export (the chart, the lists, the imports, reports, books, events, embed-token and the seven inventory routes). PATCH /v1/tenants/{tenantId}/config on a removed client is now refused 409 tenant_removed too; a suspended client can still be rebranded, and a suspended client still answers 403 tenant_suspended everywhere else. Every tenant_removed answer, on every route, carries one message (the day it was removed, the 24-hour undo, our restore on request inside the retention window, and the last day of the export) and details { tenant_id, removed_at, export_until }; suspend and reinstate keep their detail field, carrying the same sentence. (3) The 500 internal_error answer gains a message and details { status_page, support }, and the 503 rate_limiter_unavailable answer gains details.status_page: the status page says whether the trouble is ours. (4) SDK 0.3.1, shipping with this change, adds tenants.export.
- 2026-10-18 — Remove and restore a client by key: the console's Remove and Undo buttons, exactly. (1) DELETE /v1/tenants/{tenantId} (new) removes the client: its sign-in stops at once, its seat is freed at once, and its books are kept under the retention policy. It works on an active or a suspended client and answers 200 with the tenant as GET /v1/tenants/{tenantId} does (status removed, removed_at set); removing a client that is already removed changes nothing and answers 200 with it. (2) POST /v1/tenants/{tenantId}/restore (new) is the undo, for 24 hours after the remove: 200 with the tenant (status active, removed_at null), every login it had back in; after 24 hours 409 undo_expired (details.tenant_id, removed_at, undo_window_hours — e-mail support to restore it); when every seat is taken 402 seat_limit_reached in the error envelope (details.seats_used, seat_limit — add a block in your console, then restore again); restoring a client that is not removed changes nothing and answers 200 with it. Neither route reads a body; both answer 404 tenant_not_found for a tenant that is not yours. Both need a full key: a tenant-lifecycle or inventory key is refused 403 insufficient_scope. (3) SDK 0.3.0, shipping with this change, adds tenants.remove, tenants.restore, tenants.suspend, tenants.reinstate, hosts.usage, hosts.subscription and a request() escape hatch for any route on the same transport.
- 2026-10-18 — Clarified, nothing changed: POST /v1/hosts/me/domains answers a domain another host already holds with 409 domain_taken, and no other code means a taken domain. Its other refusals are 400 invalid_domain, platform_domain or reserved_domain, 429 domain_limit_reached, 502 vercel_error and 503 domain_automation_unavailable. Every one of them is in the SDK's generated RefusalCode.
- 2026-10-04 — Host-auto-provision: a host's software can now create a client's books safely on a retry, bring the buyer into them, and read where they stand. (1) POST /v1/tenants REQUIRES external_id — your own id for the client, 1-255 characters (400 invalid_body naming it when missing). The same external_id with the same body answers 200 with the tenant as it stands now and the header Idempotent-Replayed: true, creating nothing; with a different body 422 idempotency_mismatch (details.tenant_id); for a removed tenant 409 tenant_removed (details.tenant_id). The answer carries external_id. (2) POST /v1/tenants takes owner_invite: email (the default — the owner is emailed at create) or link (the email is held for your own redirect and sent only if the client is still not claimed 15 minutes later). (3) owner.status answers invited whether or not the owner's address already had a login (that owner is emailed a note instead of a set-up link); granted_existing is no longer sent and stays in the enum only so older clients still parse. (4) GET /v1/tenants/{tenantId} (new) answers the tenant with external_id and onboarding { state: owner_pending | invited | started | claimed, owner_email, invited_at, link_issued_at, claimed_at }; GET /v1/tenants gains external_id and onboarding.state per tenant. (5) POST /v1/tenants/{tenantId}/onboarding-links (new) answers 201 { url, expires_at }: a one-use link under your brand, good for ten minutes, that ends every older one; redirect your buyer to it and never send it anywhere else. Optional return_url must be on an origin you registered in the host console (400 return_url_not_allowed); refusals 409 tenant_claimed, 409 owner_missing, 409 tenant_removed, 403 tenant_suspended, 429 onboarding_link_rate_limited (ten an hour per client, Retry-After). Reaching return_url does not mean the client is set up — read the tenant until onboarding.state is claimed. (6) PUT /v1/tenants/{tenantId}/owner (new) corrects the owner address until the client is claimed (409 tenant_claimed after): every live link stops working and the new owner is emailed.
- 2026-10-02 — Five additions for hosts, every earlier request and answer unchanged. (1) A purchase line's rate is optional: amount is the money Books posts; sent, qty × rate must still equal amount (400 line_arithmetic_mismatch); left out, the line shows amount ÷ qty per Books unit, rounded half up to four places. (2) GET …/inventory/mappings/{externalId} reads where one mapping stands (status, the owner's item_id, what the host proposed, proposed_at, confirmed_at, updated_at; 404 mapping_not_found for an id never proposed), and GET …/inventory/mappings?status=&cursor=&limit= pages through the host's mappings, newest proposal first; an inventory key reaches both. (3) A refused post's details are typed for insufficient_stock (shortages of itemId, itemName, requestedQty, onHandQty, unitLabel, dipDate, and phase void_previous with documentId on a take-back) and possible_duplicate_feed_line; reason is an open set, and every other code keeps a free details object. (4) Written down, not changed: when a correction's or void's take-back of the earlier version is refused (insufficient_stock or period_closed, details.phase void_previous), the earlier version stays posted, whole, and nothing of the new version posts. (5) GET …/inventory/posts is unchanged; SDK 0.1.3 now passes its limit (1-100) and lets posts.follow stop (maxPages, until, signal), so a cron host can end its run.
- 2026-10-02 — This spec now describes the whole API: the nineteen older /v1 routes (tenants, suspend and reinstate, config, hosts/me usage, subscription and domains, seed-accounts, accounts, customers, classes, qbd-import, import/{type}, reports, books and embed-token) are generated from the schemas that now validate them, every success and every refusal documented exactly as answered. Every answer those routes gave before is unchanged, refusals included, except one: a body field of the wrong JSON type that a route used to ignore or quietly coerce (for example a number for name on POST /v1/tenants, or the string "false" for dry_run on an import) is now refused 400 invalid_body naming the field, and nothing is written. A null on an optional field still means not sent.
- 2026-10-01 — The void correction: POST …/inventory/usage and …/purchases also accept { source_event_id, correction_seq (2 or more), void: true } with no lines, occurred_on or memo — the host deleted the document. Books voids what the earlier version posted and posts nothing; the outcome reads status voided, with voided { correction_seq, document_id, journal_entry_id } naming the version it took back (null when nothing was standing). A void is a version like any other: the same body again answers 200, a different body 422 idempotency_mismatch, and before the previous version finished 409 previous_version_pending.
- 2026-10-01 — GET /v1/openapi.json added — the generated OpenAPI 3.1 spec of the pipeline routes; no key required
- 2026-09-30 — POST /v1/tenants/{id}/inventory/purchases is live: it queues one purchase document and answers 202 { event_id, status: queued }, with the same idempotency, 422 and 409 answers as usage. A purchase posts as an expense paid from the account the tenant’s owner chose (refused host_purchase_account_unset until one is set, and invalid_pay_from_account if the chosen account cannot pay a purchase).
- 2026-09-30 — The bank-feed duplicate gate: a purchase is never posted twice with its own bank or card charge. When a bank line already posted in the books (by one of the tenant’s rules, a person, or before the writer was recorded) fits the purchase (same pay-from account, exact amount, within the bank feed’s match window), the purchase is refused possible_duplicate_feed_line with details naming that feed entry (posted_by rule, person or unknown), and the owner decides — if it is a different purchase, the owner’s retry posts it as a new version; when the purchase posts first, the later bank line is offered to the owner as a match instead of being posted.
- 2026-09-30 — An owner may retry a refused inventory document in Books after fixing its cause; the retry is the next version (correction_seq + 1) of the same body, and GET …/inventory/posts shows it like any other version.
- 2026-09-30 — GET /v1/tenants/{id}/inventory/posts?cursor=&limit= pages through this host’s inventory posts for the tenant, newest first (limit 1-100, default 50): each post’s status (queued, posted with every document it wrote, or refused with reason, message and details) and an opaque next_cursor.
- 2026-09-30 — POST /v1/tenants/{id}/inventory/purchases validates a purchase document (qty × rate must equal amount, 400 line_arithmetic_mismatch) and answers 404 until host purchases are switched on.
- 2026-09-30 — POST /v1/tenants/{id}/inventory/usage queues one usage document (source_event_id, occurred_on, memo, correction_seq, 1-100 lines of external_id and qty) and answers 202 { event_id, status: queued }; the same body again answers 200 with its current outcome, a different body 422 idempotency_mismatch, and a correction before the previous version finished 409 previous_version_pending.
- 2026-09-30 — PUT /v1/tenants/{id}/inventory/mappings/{externalId} proposes which Books item a host item is ({ name, unit_label, unit_factor }); the owner confirms it in Books. Answers { status: proposed | confirmed | refused, item_id }, 201 on a new proposal; a confirmed mapping whose unit differs answers unit_mismatch: true.
- 2026-09-30 — GET /v1/tenants/{id}/inventory/items?as_of=YYYY-MM-DD lists the tenant’s tracked items with available_units as of that date, this host’s external_id and pending_posts; binding: false — the number is not a reservation. as_of is required (400 invalid_report_params).
- 2026-09-30 — A write (POST, PUT, PATCH, DELETE) answers 503 rate_limiter_unavailable with Retry-After: 30 when the rate limiter cannot be reached; nothing is recorded, so retry. Reads stay open.
- 2026-09-30 — Every call after authentication also counts against a per-host budget of 300 requests a minute, shared by all of the host’s keys; a breach answers 429 rate_limited with Retry-After.
- 2026-09-30 — Every response carries RateLimit-Limit, RateLimit-Remaining and RateLimit-Reset (seconds) for the calling key’s per-minute budget whenever the rate limiter is running.
- 2026-09-30 — A key may expire (a roll in the console gives the old key a dated end); an expired key answers 401 like a revoked one. Keys minted off production start tgb_test_.
- 2026-09-30 — New key scope inventory: it reaches only the five /v1/tenants/{id}/inventory/… routes (answering 404 until they ship) and 403 insufficient_scope everywhere else.
- 2026-09-30 — Every response carries Cache-Control: no-store.
- 2026-09-30 — POST /v1/tenants/{id}/events answers a reused source_event_id with a different body as 422 idempotency_mismatch (was 409 invalid_idempotent_request).
- 2026-09-30 — Every write refuses a body over its size limit with 413 body_too_large (256 KiB; 8 MiB on the two QBD import routes, replacing their payload_too_large body check).
- 2026-09-30 — Malformed JSON, a non-object body, or an invalid field answers 400 invalid_body naming the field, instead of being read as an empty body.
- 2026-09-30 — POST /v1/tenants/{id}/events: occurred_at, when sent, must be an RFC 3339 date-time with an offset or Z, or a YYYY-MM-DD date.
- 2026-09-30 — POST /v1/tenants/{id}/events: source_event_id is required (1-255 characters, no control characters, no surrounding whitespace).
- 2026-09-30 — POST /v1/tenants/{id}/events stamps source "host" on every event and refuses a body that names a source.
Setting up your branded login or your own domain? That is the host setup guide.
