Skip to main content
This is the flow your app runs each time a business connects. It needs your app’s client_id, a client secret on your server and a registered callback address. See Create an app. Sandbox uses https://sandbox-api.bachs.io. Live uses https://api.bachs.io, with your live app’s id and secret.
1

Send the business to Bachs

Make a new, unguessable state and a PKCE verifier for each attempt, and keep both in the user’s server-side session. The verifier is 43 to 128 unreserved characters. Its challenge is the unpadded base64url SHA-256 of the verifier.
Node.js
Send the browser to authorizeUrl, in a popup or a normal redirect. Leave out scope to ask for all your app’s permissions. A request lasts ten minutes.An unknown client_id or a callback you did not register is refused without sending the browser anywhere. See the OAuth reference.
2

The business approves

The business signs in and sees your icon and name, “by” your business with a Verified business mark (or a warning if your app is private), a picker of the businesses it can connect, each permission with your reason under it, the events your app will hear about, and your privacy and terms links.It clicks Allow or Cancel. For a private app, the picker only offers businesses that may install it.
3

Check the callback and swap the code

Allow sends the browser to your callback with code and your state. Cancel sends error=access_denied and state. Check for error, then check state matches the session before you use the code.Swap the code from your server. Authenticate with your client secret, as HTTP Basic or as client_secret in the body. JSON and form bodies both work.
Store the tokens and the webhook signing secret on your server. The webhook fields come only when your app has a webhook URL, and only in this response.
A code works once. Using it again ends the connection. A new approval for the same app and business replaces the old connection and its webhook.
For a popup, finish the swap on your server before you tell your own page the result with postMessage, using your exact origin. Never put tokens in that message. Offer a normal redirect when a popup cannot open.
4

Call the API for the business

Send the access token as the bearer credential. It acts as the business that approved, with only the permissions it approved. Do not send your own secret key or X-Account-Id.
A call that needs a permission the business did not approve gets 403. Your app’s calls have their own rate limit for each business, separate from that business’s own limit. Verify each event’s signature with the signing secret before you act on it. See Webhook events.
5

Refresh about every hour

Access tokens last one hour. Send the current refresh token to the same endpoint, with your client secret.
You get a new access token and a new refresh token, and the old pair stops working. Store both together and send one refresh at a time per connection. Each refresh moves the connection’s end to 90 days from now. A connection you do not refresh for 90 days ends.
Never send an old refresh token again. Bachs takes that as a stolen token and ends the connection. Never keep tokens or signing secrets in browser storage, URLs or logs.

Ask for more permissions later

Add the permission to your app. The checks run again before the change saves. New connections get it at once. A business already connected keeps what it approved until it approves the new permission in Connected apps, where your app shows “Asks for more access”. The new permission arrives with your next refresh after that.

Test before you go live

In sandbox, run through: approval and cancel, a wrong state, a permitted call, a refused call, a signed event at your webhook, a refresh, a reused old refresh token, and a disconnect that sends you app.deauthorized. See When a connection ends.