---
title: "Add Favorite"
method: POST
path: "/teacher-favorites"
tags: ["teacher_favorites"]
---

# Add Favorite

`POST /teacher-favorites`

## Request

- Base URL: `https://api.excellence-ai.com` (the document declares no server; this is the origin it was published from)
- URL: `https://api.excellence-ai.com/teacher-favorites`
- Auth: OAuth 2 (password, token URL `api/login`)

Add a favorite. Resolves the target per SPEC §5 origin rule.

409 if this teacher has already favorited the same target (the partial
unique indexes enforce this at the DB level too).

## Request body

- TeacherFavoriteCreate
  - `exercise_id` string, required
  - `exercise_type` 'public' | 'teacher', required

## Response `201`

Successful Response

- TeacherFavoriteOut: Favorite document, with origin already resolved. `target_type` indicates which of the two FK fields is populated so the frontend doesn't have to re-check both.
  - `id` string, required
  - `teacher_id` string, required
  - `subject` 'maths' | 'physique-chimie'
  - `public_exercise_id` string, nullable
  - `teacher_exercise_id` string, nullable
  - `target_type` 'public' | 'teacher', required
  - `added_at` string, date-time, required

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/excellence-ai/apis/excellence-learning.md) - [All operations](https://skmtc.dev/excellence-ai/apis/excellence-learning/llms.txt) - [OpenAPI document](https://skmtc.dev/excellence-ai/apis/excellence-learning/revisions/379e4a57dee8?raw)
