> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bachs.io/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Money is always a decimal string at the currency's precision (for example "29.00"), paired with an ISO 4217 currency field. Never use minor units.
> Build against the sandbox first: base URL https://sandbox-api.bachs.io with sk_sandbox_ keys. Production is https://api.bachs.io with sk_live_ keys; going live is a key swap.
> Treat webhooks (for example collection.succeeded) as the source of truth for fulfilment, never client-side events or redirects.
> Subscriptions are created by completing a checkout for a recurring product. There is no direct create-subscription endpoint.
> IDs carry resource prefixes (cust_, prod_, sub_, chk_, inv_, ref_) and timestamps are ISO 8601 UTC.

# How Bachs Apps work

> One app followed from the day it is built to the day it is removed.

This page follows one made-up app the whole way. **Acme** is a business on Bachs
that makes a helpdesk called **Deskly**. **Mama's Kitchen** is a merchant on Bachs
that wants Deskly to see its payments and make refunds.

## Words you will see

| Word | What it is |
| - | - |
| App | Deskly's record at Bachs: its name, icon, what it may ask for and where to send people back to. |
| `client_id` | Deskly's public name tag, like `app_9Kd2Mw7Qx1Lr5Tn8Vb3Hs6Pz`. Safe to put in a link. |
| Client secret | Deskly's password, like `appsk_live_…`. Only Deskly's server knows it. Bachs keeps a hash, never the value. |
| Permission | One thing the app may do, like `payments:read` or `refunds:write`. Each comes with a reason Deskly wrote. |
| Callback address | The page on Deskly's site Bachs sends the merchant back to. It must match one Deskly registered, letter for letter. |
| `state` | A random value Deskly makes for each attempt, so it knows the browser that comes back is the one that left. |
| PKCE verifier | A second random value Deskly keeps on its server. A code stolen on the way back is useless without it. |
| Code | A one-time ticket Bachs hands back after the merchant says yes. It works once, and only with the client secret and the verifier. |
| Access token | The key Deskly calls the API with, as Mama's Kitchen. It lasts one hour and can only do what was approved. |
| Refresh token | The key Deskly uses to get a new access token. Each use gives a new pair and ends the old pair. |
| Connection | Bachs' record that Mama's Kitchen let Deskly in, with which permissions, and whether it is still on. |

## The life of an app

**1. Acme builds Deskly in sandbox**

In **Developer Portal → Apps**, Acme creates Deskly and gets its client
secret, shown once. It adds an icon, links, a callback address, the
permissions it wants with a reason for each, and a webhook. It clicks
**Test install** to run a connection against one of its own sandbox
businesses. See [Create an app](https://docs.bachs.io/apps/create-an-app.md).

**2. Acme copies it to live and publishes it**

**Copy to live** makes the live Deskly with a new live secret. It starts
private. Acme clicks **Publish** and picks unlisted or public. Eight checks
run in seconds and Deskly is live. See [Publish your app](https://docs.bachs.io/apps/publish.md).

**3. Mama's Kitchen clicks Connect**

On Deskly's site, or on **Install** in the Bachs app directory, which sends
them to Deskly's site. Deskly's server makes a `state` and a verifier and
sends the browser to Bachs.

**4. Mama's Kitchen approves on Bachs**

The approval page shows Deskly, "by Acme" with a **Verified business** mark,
a business picker, each permission with Deskly's reason, and Deskly's privacy
and terms links. They click **Allow**. Bachs sends the browser back to
Deskly with a one-time code.

**5. Deskly swaps the code for tokens**

Deskly's server sends the code, its client secret and the verifier to
Bachs. It gets an access token, a refresh token, and the signing secret
for the webhook Bachs just set up for this business. See
[Connect a business](https://docs.bachs.io/apps/connect-a-business.md).

**6. Deskly works for Mama's Kitchen**

It calls the API with the access token, limited to the approved
permissions, and receives signed events such as `collection.succeeded`.
About every hour it refreshes. Each refresh moves the connection's end to
90 days from then.

**7. The connection ends**

Mama's Kitchen disconnects, Deskly revokes it, nobody refreshes for 90 days,
Acme deletes Deskly, or Bachs suspends it. Deskly gets
[`app.deauthorized`](https://docs.bachs.io/guides/webhooks/events/app-deauthorized) first, then
its tokens and webhook for that business stop. Mama's Kitchen's business is
not touched. See [When a connection ends](https://docs.bachs.io/apps/disconnect.md).

## Why each safety step is there

| Step | What goes wrong without it |
| - | - |
| Exact callback address | An attacker puts their own site as the callback, and the code lands with them. |
| `state` | Someone tricks a merchant's browser into finishing a connection the merchant never started. |
| PKCE verifier | A code copied from a browser history or a log could be swapped for tokens. |
| Client secret on your server | Anyone who knows your `client_id` could pretend to be your app. |
| One-hour access token | A leaked token works for days instead of minutes. |
| New refresh token each time | A stolen refresh token keeps working quietly. With rotation, the first reuse ends the connection. |
| Automatic checks | A broken or fake-looking app reaches merchants. |
| `app.deauthorized` | Your app keeps showing a business as connected after it was cut off. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.