> ## Documentation Index
> Fetch the complete documentation index at: https://docs.federalaccess.cl/llms.txt
> Use this file to discover all available pages before exploring further.

# Sync accesses

> Keep a copy of the access log in your system without missing any, including the ones that arrive late.

To bring the access log into your system, for example to compute attendance, walk `GET /accesses` with the cursor the API returns. If you store the cursor between requests, you get each access once and never skip one.

You need a key with the `accesses:read` scope.

## How the list is ordered

Each access has two timestamps:

| Field | What it is |
| - | - |
| `occurred_at` | When the access happened at the gate |
| `received_at` | When the access reached Federal Access |

The list is ordered by **arrival** (`received_at`), not by `occurred_at`. The two are usually almost the same. But if a device at the gate loses its connection, it sends its accesses when it reconnects: an access from yesterday can arrive today.

Because the list is ordered by arrival, that access shows up after your cursor, and you get it on your next request.

## Sync

**1. Run the initial load**

Request `GET /accesses` without a `cursor`. The list starts at the beginning of the installation's history.

```bash theme={null}
curl "https://apex.federalaccess.cl/public/v1/accesses?limit=1000" \
  -H "Authorization: Bearer $FEDERAL_ACCESS_API_KEY"
```

Each response carries a page of accesses, `has_more`, and `next_cursor`:

```json theme={null}
{
  "data": [
    { "id": 9001, "occurred_at": "2026-03-10T12:00:00.000-03:00", "received_at": "2026-03-10T12:00:02.123-03:00" }
  ],
  "has_more": true,
  "next_cursor": "eyJ2IjoxLCJpZCI6OTAwMX0"
}
```

`limit` defaults to 500, with a maximum of 1000.

**2. Store the accesses and the cursor together**

Store the page's accesses and `next_cursor` in the same transaction. Use the access `id` as the key to insert or update.

If your process crashes between pages, resume from the last stored cursor. If you get a page again, the `id` prevents duplicates.

**3. Continue while there's more**

While `has_more` is `true`, request the next page, sending the latest `next_cursor` as `cursor`:

```bash theme={null}
curl "https://apex.federalaccess.cl/public/v1/accesses?limit=1000&cursor=eyJ2IjoxLCJpZCI6OTAwMX0" \
  -H "Authorization: Bearer $FEDERAL_ACCESS_API_KEY"
```

The initial load can take many pages. Space out your requests to stay under the [limit of 5 per second](https://docs.federalaccess.cl/en/guides/rate-limits.md).

**4. Poll**

`has_more: false` means there are no more accesses **for now**. Wait an interval, for example one minute, and repeat the request with the latest `next_cursor`. Repeat this step forever.

### Example

```python theme={null}
import time
import requests

BASE_URL = "https://apex.federalaccess.cl/public/v1"

def sync(api_key, cursor, save):
    headers = {"Authorization": f"Bearer {api_key}"}
    while True:
        params = {"limit": 1000}
        if cursor:
            params["cursor"] = cursor
        response = requests.get(f"{BASE_URL}/accesses", headers=headers, params=params)

        if response.status_code == 429:
            time.sleep(int(response.headers["Retry-After"]))
            continue
        response.raise_for_status()

        page = response.json()
        save(page["data"], page["next_cursor"])
        cursor = page["next_cursor"]
        time.sleep(0.25 if page["has_more"] else 60)
```

`save` stores the accesses by `id` and the cursor in the same transaction.

## Cursor rules

* **`next_cursor` is always present.** Always store the latest one, even when the page is empty. The cursor can advance without returning accesses, for example when nothing matches your filters.
* **Only use cursors from the API.** The cursor is opaque: don't build or change it. An invalid cursor answers `400 invalid_parameter`.
* **Keep the same filters.** The cursor doesn't remember your filters. Send the same `occurred_from`, `occurred_to`, `site_ids[]`, `direction`, and `visitor_type` for the whole traversal. If you change the filters, start a new traversal without a `cursor`.

## Accesses that arrive late

If you request a date range without a cursor, you can miss accesses. For example, a report for yesterday built at 00:05 with `occurred_from` and `occurred_to` misses an access from yesterday that arrives at 00:10.

For reports by date:

1. Sync with the cursor, as in this guide.
2. Build the report from your copy, filtering by `occurred_at`.
3. When an access arrives with an `occurred_at` on a day you already reported, recompute that day.

The `occurred_from` and `occurred_to` filters form a half-open range `[from, to)`. A date or a time without a time zone is read in Chile's time zone (America/Santiago).

## Deleted accesses

The list only includes current accesses. If an access is deleted after you synced it, the list doesn't tell you. `GET /accesses/{id}` answers `404` for a deleted access.

## Reference

* [List accesses](https://docs.federalaccess.cl/en/api-reference/accesses/list-accesses.md)
* [Get an access](https://docs.federalaccess.cl/en/api-reference/accesses/get-access.md)


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