# Authentication

URL: https://api-docs.vestta.io/authentication

Authenticate every request with an API key, and grant each key only the scopes it needs.

Every request to the Vestta API is authenticated with an **API key**. A key belongs to one Vestta workspace: everything the API returns or creates is scoped to that workspace, and the key's **scopes** decide which endpoints it may call.

Keys are created and managed in the Vestta app — see [API keys](/api-keys).

## Sending the key

Send the key in the `X-Api-Key` header:

```bash
curl "https://api.vestta.io/v1/me" \
  -H "X-Api-Key: $VESTTA_API_KEY"
```

For compatibility with existing integrations, the API also accepts the key in the `Authorization` header with the `ApiKey` scheme:

```bash
curl "https://api.vestta.io/v1/me" \
  -H "Authorization: ApiKey $VESTTA_API_KEY"
```

Use `X-Api-Key` in new integrations. When both headers are present, `X-Api-Key` is used and `Authorization` is ignored.

`Authorization: Bearer <key>` is **not** supported. A request that only carries a Bearer token is rejected with `401 API key required`.

## Key format

Keys look like this:

```text
AC_LIVE_<key_id>.<secret>
```

`key_id` identifies the key and is visible in the Vestta app; `secret` is shown only once, when the key is created. Vestta stores a hash of the secret, never the secret itself, so a lost key cannot be recovered — create a new one.

## Scopes

A scope grants access to a group of endpoints. Scopes are chosen when the key is created (under **Permisos** in the Vestta app) and cannot be changed afterwards; to change them, create a new key.

| Scope | In the Vestta app | Grants |
| --- | --- | --- |
| `properties:read` | Propiedades | Read the public property catalogue. |
| `properties:write` | Editar propiedades | Create and update properties and upload photos. |
| `properties:publish` | Publicar propiedades | Publish, unpublish and read processing state. |
| `leads:write` | Editar contactos | Create and update private CRM contacts without outreach. |
| `leads:read` | Leer leads | Read every lead of the workspace, including contact details. |
| `leads:ingest` | Enviar consultas | Create leads from your forms and services. |

This is how scopes map to endpoints, as declared in the [OpenAPI schema](/openapi.json):

- `leads:ingest`: `POST /v1/leads/ingest`, `POST /v1/leads/inquiries`
- `leads:read`: `GET /v1/leads`, `GET /v1/leads/{lead_id}`
- `leads:write`: `POST /v1/leads`, `PATCH /v1/leads/{lead_id}`
- `properties:publish`: `GET /v1/properties/{property_id}/publication`, `PUT /v1/properties/{property_id}/publication`
- `properties:read`: `GET /v1/properties`, `GET /v1/properties/{property_id}`
- `properties:write`: `POST /v1/properties`, `PATCH /v1/properties/{property_id}`, `POST /v1/properties/{property_id}/images/uploads`, `POST /v1/properties/{property_id}/images/uploads/{upload_id}/complete`

Grant the minimum. A website that shows listings and sends contact requests needs `properties:read` and `leads:ingest` — not `leads:read`, which exposes the personal data of every lead in the workspace.

## How a request is checked

Every operation checks authentication, the request quota, the required scope and the request schema:

1. **The key** — present, well formed, known, active, not expired, with a matching secret. Otherwise: `401`.
2. **The quota** — the key must have capacity in its current window. Otherwise: `429` with `Retry-After`. See [Rate limits](/requests#rate-limits).
3. **The scope** — the key must have the endpoint's scope. Otherwise: `403` with `Insufficient scope`.
4. **The parameters and body** — validated against the schema. Otherwise: `422`.

Do not depend on error precedence when a request fails more than one check.

Each `401` has a specific message that tells you what failed. They are listed in [Errors](/errors).

## Where to call the API from

Call the API from your server, not from the browser. The API answers cross-origin requests, but any key used in front-end code is visible to every visitor and can be copied.

To send leads from a public website, post the form to your own backend and call [Create an inquiry](/leads/inquiries) from there, keeping the key in a server-side environment variable.
