Files
bookhoard/docs/developer/api/book-matching/link_book.md
T
John O'Keefe 18084de7a6 docs(book-matching,collections): Beam batch 10 — 15 endpoints
WO3 sync internals resolved: the book-matching docs ARE the sync surface
(books/query, link-book, bulk/auto-link, unlinked-books, suggestions,
file-alias CRUD) + collections rule/test/bulk-assign/shelf-mapping
surface.

Dedupe resolved (Claude call): search_books.md declared
GET /api/books/match but its BODY documents POST /api/sync/books/query —
both routes exist and are distinct (query-param device protocol vs JSON
body plugin protocol). Repointed search_books.md frontmatter to the POST
route; get_book_matches.md keeps the GET.

Claude registry: 15 entries (one pre-existing link-book entry deduped).
Drift fixed by gate: auto-link request {confidence_threshold, limit} not
{device_id, threshold}; bulk-link link objects {unlinked_book_id,
media_item_id, confidence_score} not {device_id, book_id, ...};
responses {results,total,successful,failed}/{auto_linked,results}; added
missing example-responses (bare delete, remove-rule is_smart-after
semantics, bulk-assign per-book results). make test 9/9.
2026-10-24 17:59:27 -04:00

127 lines
2.8 KiB
Markdown

---
method: POST
path: /api/devices/:deviceId/sync/link-book
auth: jwt
area: book-matching
---
<!-- source: internal/handlers/matching.go:57 MatchingHandler.LinkBook -->
# Link Book
Link a device book to a Bookhoard media item. Supports bulk linking.
## Example request
```json example-request
{
"device_file": {
"file_path": "/books/hobbit.epub",
"sha256": "abc123...",
"title": "The Hobbit"
},
"media_item_id": "550e8400-e29b-41d4-a716-446655440000",
"confidence_score": 1.0
}
```
## Example response
```json example-response
{
"status": "linked",
"device_file_alias": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"media_item_id": "550e8400-e29b-41d4-a716-446655440000",
"device_id": "550e8400-e29b-41d4-a716-446655440000",
"file_path": "/books/hobbit.epub",
"file_sha256": "abc123...",
"confidence_score": 1.0
}
}
```
**Endpoint**: `POST /api/sync/bulk-link-books` or `POST /api/sync/auto-link-books`
**Auth**: Required
**Content-Type**: `application/json`
## Manual Link Request Body
| Field | Type | Required | Description |
| ------------------------ | ------ | -------- | ------------------------- |
| links | array | Yes | List of book links |
| links[].unlinked_book_id | string | Yes | Device book UUID |
| links[].media_item_id | string | Yes | Bookhoard media item UUID |
| links[].confidence_score | float | No | Match confidence (0-1) |
### Example Manual Link Request
```json
{
"links": [
{
"unlinked_book_id": "uuid-1",
"media_item_id": "uuid-2",
"confidence_score": 1.0
}
]
}
```
## Auto-Link Request Body
| Field | Type | Required | Description |
| -------------------- | ------- | -------- | ----------------------------------------------- |
| confidence_threshold | float | No | Minimum confidence for auto-link (default: 0.8) |
| limit | integer | No | Maximum books to auto-link (default: 50) |
### Example Auto-Link Request
```json
{
"confidence_threshold": 0.8,
"limit": 50
}
```
## Response (200 OK) - Manual Link
```json
{
"results": [
{
"unlinked_book_id": "uuid-1",
"status": "success",
"media_item_id": "uuid-2"
}
],
"total": 1,
"successful": 1,
"failed": 0
}
```
## Response (200 OK) - Auto-Link
```json
{
"auto_linked": 15,
"results": [
{
"unlinked_book_id": "uuid-1",
"title": "The Hobbit",
"matched_media_item_id": "uuid-2",
"confidence": 0.95,
"match_method": "sha256_match"
}
]
}
```
## Error Responses
| Code | Description |
| ---- | ------------------------ |
| 400 | Invalid link data |
| 401 | Invalid or expired token |
| 404 | Media item not found |