> ## 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.

# OAuth endpoints

> Authorize, token, revoke and discovery for Bachs Apps, with every field and error.

| Endpoint | Method | Who calls it |
| - | - | - |
| `/connect/oauth/authorize` | `GET` | The business's browser |
| `/v1/connect/oauth/token` | `POST` | Your server |
| `/v1/connect/oauth/revoke` | `POST` | Your server |
| `/connect/oauth/.well-known/oauth-authorization-server` | `GET` | Your OAuth library |

Hosts: `https://sandbox-api.bachs.io` and `https://api.bachs.io`.

## Authorize

Send the browser here to start a connection.

| Field | Required | What it is |
| - | - | - |
| `client_id` | Yes | Your app's id. |
| `response_type` | Yes | Always `code`. |
| `redirect_uri` | Yes | One of your callback addresses, exactly. |
| `state` | Yes | A new unguessable value for this attempt. Returned to you unchanged. |
| `code_challenge` | Yes | Unpadded base64url SHA-256 of your verifier. |
| `code_challenge_method` | Yes | Always `S256`. |
| `scope` | No | Space-separated permissions, within your app's. Leave out to ask for all of them. |

On **Allow**, the browser comes back with `code` and `state`. On **Cancel**, with
`error=access_denied` and `state`. An unknown `client_id` or an unregistered
`redirect_uri` is refused without a redirect.

## Token

Authenticate with your client secret: HTTP Basic with `client_id` and the secret,
or `client_secret` in the body. Never both. JSON and form bodies both work.

**Swap a code**

| Field | What it is |
| - | - |
| `grant_type` | `authorization_code` |
| `client_id` | Your app's id. |
| `redirect_uri` | The same callback address as the authorize request. |
| `code` | The code from the callback. Works once, within ten minutes. |
| `code_verifier` | The verifier you made for this attempt. |

**Refresh**

| Field | What it is |
| - | - |
| `grant_type` | `refresh_token` |
| `client_id` | Your app's id. |
| `refresh_token` | The current refresh token. |

**Response**

| Field | What it is |
| - | - |
| `account_id` | The business that approved. |
| `livemode` | `false` in sandbox. |
| `token_type` | `Bearer` |
| `access_token` | Lasts `expires_in` seconds, at most one hour. |
| `refresh_token` | Replaces the one you sent. Each refresh moves the connection's end to 90 days from now. |
| `expires_in` | Seconds until the access token expires. |
| `scope` | The approved permissions, space-separated. |
| `webhook_endpoint_id`, `webhook_signing_secret` | Only when swapping a code, and only when your app has a webhook. |

## Revoke

Ends the connection a token belongs to.

| Field | Required | What it is |
| - | - | - |
| `token` | Yes | A refresh token or access token. |
| `token_type_hint` | No | `refresh_token` or `access_token`. |

Authenticate as for the token endpoint. The answer is `200` with an empty body,
even for an unknown token. A missing `token` gets `400 invalid_request`.

## Discovery

Returns the endpoints and options above in the standard format (RFC 8414):
`authorization_endpoint`, `token_endpoint`, `revocation_endpoint`,
`code_challenge_methods_supported` (`S256`),
`token_endpoint_auth_methods_supported` (`client_secret_basic`,
`client_secret_post`) and `scopes_supported`. No authentication.

## Errors

Errors use `error` and `error_description`.

| `error` | Means | Do this |
| - | - | - |
| `invalid_client` | Unknown app, or a wrong or revoked client secret. `401`. | Check your `client_id` and secret. |
| `invalid_redirect_uri` | The callback address is not registered. | Register it on **OAuth**, exactly. |
| `invalid_scope` | A permission outside your app's, or a webhook event without its read permission. | Ask only for your app's permissions. |
| `invalid_request` | A field is missing or malformed, or the secret was sent twice. | Fix the request. |
| `access_denied` | The business cancelled, or cannot install this app. | Leave it disconnected; it can try again. |
| `invalid_grant` | The code or refresh token is expired, used, revoked or for another app. | Send the business through a new connection. |
| `temporarily_unavailable` | Your webhook could not be set up. The code is not used up. | Try the swap again. |


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