# Diagnosing 403 and 404

## Start with a test call

`organization/get-all` is open to every installed integration, so it checks the URL, the key and the IP
in one go.

```bash
curl -i 'https://api.bito.uz/integration-api/integration/api/v2/organization/get-all' \
  -H "api-key: $BITO_API_KEY"
```

Look at `code` in the response body:

| Response | Meaning | Next step |
|---|---|---|
| `code: 0` | URL, key and IP are fine. The problem is a specific method or permission | [403](#403) or [404](#404) |
| Non-zero `code` | The request reached the API and was refused | [Error codes](https://docs.bito.uz/en/guide/errors.md) |
| No `code` field at all | The request did not hit any API method | [404](#404) |

## 404

A missing **record** does not give `404` in Bito — it comes back as `400` with its own code (for
example `26000`). `404` means there is no such method and path pair.

Check in order:

1. **HTTP method.** A wrong method gives `404`, not `405`. Lists are `POST`, reading one record is
   `GET`, updating is `PUT`, deleting is `DELETE`. See [HTTP methods](https://docs.bito.uz/en/guide/api.md#http-methods).
2. **Base URL.** `https://api.bito.uz/integration-api/integration/api/v2/` — you need both
   `integration-api` and `integration/api/v2`. Dev environment: `https://api.systematicdev.uz/...`.
3. **Path, letter by letter.** Words are hyphenated (`sale-order`, `get-by-id`), no trailing `/`.
4. **Id in the path.** `GET /product/get-by-id/{id}` — the id goes in the path itself, not in the body
   or the query string. Not every method works this way: check each in the [reference](https://docs.bito.uz/en/api/index.md).

## 403

First tell the `code` apart.

### `code: 10024` — IP not on the list

The integration has an `ip_whitelist` and the call came from another address. `data` holds the IP Bito
saw.

- Add that IP (or its CIDR range) to the list. Up to 50 entries.
- The list is IPv4 only: a call over IPv6 is refused.
- If your server's IP changes, get a static outbound address or leave the list empty.

### `code: 10003` — missing permission

Look at `data`.

| `data` | Cause | Fix |
|---|---|---|
| A permission name (`customer_create`, `sale`) | The permission was not approved at install | Add it to `required_permissions`; it works after the merchant re-approves |
| A section name (`reports`, `sales`, `file`, `webhook`) | The app declares permissions and this section has no permission key, so it is closed | See below |
| `boss`, `warehouse_id` or another role key | The user in the `user_id` header lacks the right | [User roles](#roles) |
| Empty | `user_id` is not in this account or is blocked; or writing a `source` without `multiple_sources` switched on | Check the header and the setting |

Which method needs which permission: [Permissions](https://docs.bito.uz/en/api/permissions.md).

**Sections without a permission key.** With even one permission in `required_permissions`, reports,
sources, files, settings, webhooks and similar sections close (except `organization/get-all` and
`get-by-id`). More in [Create an integration](https://docs.bito.uz/en/guide/create.md).

::: warning Webhooks
An app that declares `required_permissions` cannot call the webhook methods.
:::

**Changed the list?** Existing installs keep working with the list approved at install until the
merchant approves the new one.

### User roles

A request runs as the account owner, or as the user in the `user_id` header when you send it.

- If that user's role, organization or warehouse access is not enough, you get `403`. The app's
  permission does not replace it.
- Only an owner-level user can manage webhook subscriptions.
- To check, send the same request without `user_id`: if it passes, the user's role is the cause.

## 401

| `code` | Cause | Fix |
|---|---|---|
| `10004`, `data`: `api-key is not provided in the header` | Neither `api-key` nor `Authorization` arrived | Check the header name and that no proxy strips it |
| `10004` | The session was ended: the secret was rotated or the integration uninstalled | Authorize again |
| `10014` | The access token is invalid or expired | [Refresh the token](https://docs.bito.uz/en/guide/oauth/tokens.md#refresh) |

Two subtleties:

- When an `Authorization` header is present, the call is treated as OAuth and `api-key` is not read. Do
  not put the API key in `Authorization`.
- A wrong **API key** returns `400`, not `401`: `115006` or `11000`. An integration that is not
  installed returns `400` with `115004`. See [Error codes](https://docs.bito.uz/en/guide/errors.md#auth).

Still stuck? Send [support](https://docs.bito.uz/en/guide/support.md) the method, full URL, time, HTTP status and response body —
without keys or tokens.
