# Links API

A link is read-only access to one version of one file. For the ideas behind it, see [Public and private links](concepts-links.md).

## Create a link

`POST /files/{name}/share`. With no body you get a public link; `?ttl=1h` shortens its life.

```sh {tab="Public"}
curl -H "Authorization: Bearer $FUZZY_KEY" -X POST "https://fuzzyshare.com/files/report.pdf/share?ttl=1h"
```

```sh {tab="Private"}
curl -H "Authorization: Bearer $FUZZY_KEY" -X POST https://fuzzyshare.com/files/report.pdf/share \
  -d '{"access":"private","passphrase":"correct horse battery","max_downloads":1,"ttl":"1h","label":"for Sam"}'
```

The JSON body (all fields optional, unknown fields rejected):

```json
{"ttl":"1h","access":"public|private","label":"for Sam",
 "passphrase":"...","allow":["sha256:9f2c4ab01d3e7f58"],"max_downloads":1}
```

- `access` defaults to `public`, which takes no `passphrase` or `allow`. `private` needs a passphrase (8 to 200 characters), at least one fingerprint in `allow` (max 20), or both.
- `ttl` can only shorten the file's remaining life. `max_downloads` is 1 to 1000. `label` is up to 60 characters.
- At most 20 active links per file and 200 per person (`409`). `403` for a public link when the server has turned them off.

The response is `201`:

```json
{"id":"l_6f1be9c8a665","file":"a.txt","access":"private","label":"for Sam","has_passphrase":true,
 "allow":[],"downloads":0,"max_downloads":2,"created_at":"...","expires_at":"...",
 "created_by":{"id":"k_...","name":"default"},
 "url":"https://fuzzyshare.com/s/<token>","raw_url":"https://fuzzyshare.com/s/<token>/raw"}
```

A private link's `url` is shown only here.

## List and revoke

```sh
curl -H "Authorization: Bearer $FUZZY_KEY" https://fuzzyshare.com/links                 # all
curl -H "Authorization: Bearer $FUZZY_KEY" https://fuzzyshare.com/files/report.pdf/links  # one file
curl -H "Authorization: Bearer $FUZZY_KEY" -X DELETE https://fuzzyshare.com/links/l_6f1be9c8a665
```

Lists return `{"links":[...]}`. Each item has `id`, `file`, `access`, `label`, `has_passphrase`, `allow`, `downloads`, `max_downloads`, `created_at`, `expires_at`, `created_by`, `views`, `reads_logged`, and `url` and `raw_url` for public links. Revoking returns `{"revoked":"l_..."}`.

## Read a link

| URL | Returns |
|---|---|
| `GET /s/{token}` | A preview page for browsers, the bytes for programs |
| `GET /s/{token}/raw` | Always the bytes. `?download=1` forces a download |
| `GET /s/{token}/info` | Name, size, type, expiry, `access`, and `reads_left` for limited links |
| `POST /s/{token}/unlock` | Browsers: body `{"passphrase":"..."}` or an `Authorization` header. `204` and a 10-minute cookie |

Public links answer `GET` and `HEAD` only.

### Private links

Without proof, `/info` and `/raw` answer `401` and reveal nothing about the file:

```json
{"error":"this link is private","locked":true,"methods":["passphrase","key"]}
```

Programs prove access on the request itself:

```sh {tab="Passphrase"}
curl -H "X-Fuzzy-Passphrase: correct horse battery" https://fuzzyshare.com/s/TOKEN/raw -o report.pdf
```

```sh {tab="Allowed key"}
curl -H "Authorization: Bearer $FUZZY_KEY" https://fuzzyshare.com/s/TOKEN/raw -o report.pdf
```

For a key, its fingerprint must be on the allow-list and the key must still be live. Browsers call `/unlock` and carry the cookie `fuzzy_u` (`HttpOnly`, `SameSite=Strict`, `Path=/s/<token>`, 10 minutes). After 5 wrong passphrases from one address on one link, further attempts get `429` for 10 minutes.

### Limited reads

A request that serves bytes counts as one download; `/info`, the preview page and `HEAD` never do. When the limit is reached the link answers `404`.

## Link activity

`GET /links/{id}/activity?limit=200` (`limit` 1 to 500 events, default 200). Only the link's owner can read it: another person's link and an unknown id return `404`, and the admin key returns `403`.

```json
{"logging":"full",
 "link":{"id":"l_...","file":"a.txt","access":"public","...":"..."},
 "summary":{"views":4,"reads":2,"sessions":3,"visitors":2,"bots":1,"last_access":"2026-12-02T18:00:00Z","by_you":1},
 "sessions":[{"id":"9f2c4ab01d3e7f58","first_seen":"...","last_seen":"...","ip":"203.0.113.9",
   "device":"Chrome on macOS","bot":false,
   "user":{"name":"Sam Reader","organization":"Acme","member_since":"...","you":false,"deleted":false},
   "counts":{"view":1,"read":2,"locked":0,"unlock_ok":0,"unlock_fail":0,"throttled":0},
   "events":[{"at":"...","kind":"read","count":2,"last":"..."}]}],
 "truncated":false,"proxy_hint":false}
```

- **Events:** `view`, `read`, `locked`, `unlock_ok`, `unlock_fail`, `throttled`. Identical events from one session within 60 seconds merge into one with a `count`.
- **Sessions:** the id is an HMAC of link, IP and user agent. A session splits after 30 minutes of silence. Bots and crawlers have `bot: true` and are left out of `views`, `reads` and `visitors`.
- **`user`** is present only when the visitor presented their own valid key on that request. It has only `name`, `organization`, `member_since`, `you` and `deleted`. There is no `key` field: the log never records which key a visitor used. A removed account shows `deleted: true` with the name logged at the time.
- **`logging`** is the server's `FUZZY_ACCESS_LOG`: `full`, `anonymous` or `off` (nothing recorded, `sessions` empty). `proxy_hint` is true when every IP is loopback or private. `truncated` means older events are not shown.

See [Access activity and privacy](concepts-activity.md).
