# Generate a client

bind.co ships no SDK of its own. The API reference is a standard OpenAPI document, so you generate a
typed client for your language with the usual OpenAPI tools, and regenerate it whenever you like.

## 1. Download the reference

```sh
curl -o bind-openapi.json https://api.bind.co/v1/openapi.json
```

It describes every public `/v1` route: parameters, bodies, answers, examples, errors, rate limits and the
scopes each route needs. No token is needed to read it.

## 2. Generate

Use one of the generators below. Each command reads the file you downloaded;
you can pass the URL instead.

**TypeScript**, with openapi-ts by Hey API:

```sh
npx @hey-api/openapi-ts -i bind-openapi.json -o src/bind-client
```

For types only, with openapi-typescript:

```sh
npx openapi-typescript https://api.bind.co/v1/openapi.json -o src/bind-api.d.ts
```

**Python**, with openapi-python-client:

```sh
pipx run openapi-python-client generate --path bind-openapi.json --output-path bind_client
```

**Any other language**, with OpenAPI Generator. Pick the language with `-g`, for example `go`,
`java`, `kotlin`, `csharp`, `php` or `ruby`:

```sh
npx @openapitools/openapi-generator-cli generate -i bind-openapi.json -g go -o bind-client
```

## 3. What to expect

**Method names.** Every operation has an `operationId` that is a stable snake_case name, such as
`expenses_search`, `expenses_get_one` or `send_draft`. Generators turn it into the method name. A
rename is a breaking change, announced in the [changelog](https://staging.api.bind.co/docs/changelog).

**Operation types.** Each operation type in the catalogue, such as `expenses`, has its own routes and
types. When a new type is added, download the reference again and regenerate.

**Authentication.** The reference declares two schemes, and each operation names the one it takes:

- `oauth2`: the user's access token, sent as `Authorization: Bearer <token>`. The operation lists
  the scopes it needs.
- `clientBasic`: your application's `client_id` and `client_secret` over HTTP Basic, on the webhook
  routes and the token routes.

A few routes, such as `GET /v1/operations/{operation_type}/schema`, take no credentials at all.

**OAuth lives at the API root.** The OAuth endpoints are `https://api.bind.co/oauth2/authorize`,
`/oauth2/token`, `/oauth2/revoke` and `/oauth2/introspect`, with no `/v1`, as
`https://api.bind.co/.well-known/oauth-authorization-server` advertises. The reference also lists
them under `/v1`, where they answer the same, so a generated client can call them. Build the
`/oauth2/authorize` URL yourself and send the user's browser there; the
[quickstart](https://staging.api.bind.co/docs/quickstart) shows how.

**Errors.** Every error answer has the same body, `BindErrorBody` in the reference. Branch on its
`error` field; see [Errors](https://staging.api.bind.co/docs/errors).
