Favorites API
The Favorites API enables cross-device favorites synchronization using passwordless magic link authentication. For architectural details, see the Favorites Architecture explanation.
Endpoints
Section titled “Endpoints”Request Magic Link
Section titled “Request Magic Link”POST /api/v1/favorites/magic-link
Sends a magic link email to the specified address.
{ "email": "user@example.com"}Headers:
Content-Type: application/jsonX-Session-ID: {session_id}(optional, for session linking)
{ "success": true, "message": "Check your email for a magic link to sync your favorites!"}| Status | Detail |
|---|---|
| 400 | Brokerage not found |
| 429 | Too many magic link requests. Please check your email or wait 15 minutes. |
Rate Limiting: Maximum 3 pending magic links per email within 15 minutes.
Verify Magic Link
Section titled “Verify Magic Link”GET /api/v1/favorites/verify/{token}
Verifies a magic link token and returns authentication credentials.
{ "success": true, "client_id": 123, "auth_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "favorites": ["98970014", "98970015", "98970171"], "email": "user@example.com"}| Status | Detail |
|---|---|
| 400 | This magic link has already been used. Request a new one. |
| 400 | This magic link has expired. Request a new one. |
| 400 | Brokerage not found |
| 404 | Magic link not found |
Token Behavior:
- Expires after 15 minutes
- Can only be used once
- Links anonymous session to client if
X-Session-IDwas provided
Get Favorites
Section titled “Get Favorites”GET /api/v1/favorites
Returns the authenticated user’s synced favorites.
Headers:
Authorization: Bearer {auth_token}{ "favorites": ["98970014", "98970015", "98970171"]}| Status | Detail |
|---|---|
| 401 | Invalid or expired auth token. Request a new magic link. |
Sync Favorites
Section titled “Sync Favorites”POST /api/v1/favorites/sync
Syncs localStorage favorites to the server using a union merge strategy.
Headers:
Authorization: Bearer {auth_token}Content-Type: application/jsonBody:
{ "favorites": ["98970014", "98970015", "98970171", "98970200"]}{ "favorites": ["98970014", "98970015", "98970171", "98970200"]}Returns the merged set (server + request favorites combined).
| Status | Detail |
|---|---|
| 401 | Invalid or expired auth token. Request a new magic link. |
Remove Favorite
Section titled “Remove Favorite”DELETE /api/v1/favorites/{listing_id}
Removes a specific favorite from the user’s synced list.
Headers:
Authorization: Bearer {auth_token}{ "success": true, "message": "Favorite removed"}| Status | Detail |
|---|---|
| 401 | Invalid or expired auth token. Request a new magic link. |
Auth Token Structure
Section titled “Auth Token Structure”The auth_token is a signed JWT with the following claims:
{ "client_id": 123, "brokerage_id": 1, "email": "user@example.com", "exp": 1735689600, "iat": 1727913600, "type": "favorites_auth"}| Claim | Description |
|---|---|
client_id | Internal client/lead ID |
brokerage_id | Associated brokerage |
email | Verified email address |
exp | Expiration (90 days from issue) |
iat | Issued at timestamp |
type | Always "favorites_auth" |
Data Models
Section titled “Data Models”MagicLink
Section titled “MagicLink”| Column | Type | Description |
|---|---|---|
id | SERIAL | Primary key |
brokerage_id | INTEGER | Associated brokerage (FK) |
email | VARCHAR(255) | Recipient email |
token | VARCHAR(64) | Unique secure token |
session_id | VARCHAR(36) | Optional session to link |
expires_at | TIMESTAMPTZ | Token expiration time |
used_at | TIMESTAMPTZ | When token was used (null if unused) |
client_id | INTEGER | Client created on verification (FK) |
ClientFavorite
Section titled “ClientFavorite”| Column | Type | Description |
|---|---|---|
id | SERIAL | Primary key |
client_id | INTEGER | Associated client (FK) |
listing_id | VARCHAR(50) | MLS listing ID |
created_at | TIMESTAMPTZ | When favorite was added |
Unique Constraint: (client_id, listing_id) — prevents duplicates.
Related
Section titled “Related”- Favorites Architecture — How the system works
- Frontend Integration Guide — Implementation tutorial
- Properties API — Get property details for favorites