This document describes the v2 Favorites API of Fess. For the common response envelope, error model, and CSRF, see API Overview.
The base URL is http://<Server Name>/api/v2/ (local environment example: http://localhost:8080/api/v2).
Note
To use the favorites feature, the user.favorite setting must be enabled (disabled by default).
Fetching Favorite Documents List
Request
| HTTP Method | GET |
| Endpoint | /api/v2/favorites |
Returns the IDs of documents that the calling user has previously added to favorites, among search results identified by query_id. query_id is the opaque identifier (query_id field) returned by the search API (/search).
An anonymous caller (no user code associated with the session) results in auth_required (401). When the user.favorite feature is disabled, it returns invalid_request (400). When query_id does not match a cached result set in the session, it returns 200 with an empty data array.
Request Parameters
query_id | The opaque query_id returned by the search API (/search) (query, required, str). |
Table: Request Parameters
Response
On success (200), the following fields are returned directly under response in the common envelope.
Each field is described below.
record_count | Number of favorite documents in data (int). |
data | Array of favorite documents in the queried result set, preserving search result order. Each element is {doc_id}. |
Table: Response Fields
Error Response
For details on the error model, see API Overview. The HTTP statuses returned by this endpoint are as follows.
Table: Error Response
Fetching Favorite Status
Request
| HTTP Method | GET |
| Endpoint | /api/v2/documents/{docId}/favorite |
Retrieves the favorite status of the specified document.
Anonymous (unauthenticated) callers may also use this endpoint. In that case, favorite returns false, but count still reflects the stored favorite count (for this reason, this endpoint does not return 401).
When the favorites feature (user.favorite) is disabled, the endpoint responds with invalid_request (400).
Request Parameters
Table: Request Parameters
Response
On success (200), the following fields are returned directly under response in the common envelope.
Each field is described below.
doc_id | Document ID (str). |
favorite | Whether the calling user has favorited this document (bool). |
count | Total favorite count for this document (int64). |
Table: Response Fields
Error Response
For details on the error model, see API Overview. The HTTP statuses returned by this endpoint are as follows.
Table: Error Response
Adding a Favorite
Request
| HTTP Method | POST |
| Endpoint | /api/v2/documents/{docId}/favorite |
Adds the specified document to favorites. Since this is a state-changing request, the X-Fess-CSRF-Token header is required (see API Overview). In addition, the calling user must be authenticated; anonymous callers receive auth_required (401).
The query_id is used to confirm that the target document belongs to a recent search result. When query_id matches no cached result set in the session, the endpoint responds with invalid_request (400); when docId is not contained in that result set, it responds with not_found (404).
Request Parameters
Table: Request Parameters
Request Body
Send a JSON (FavoritePostRequest) with Content-Type: application/json (charset UTF-8) containing the following fields. The maximum request body size is 1 KiB (1024 bytes); exceeding this results in payload_too_large (413).
Table: Request Body
Response
On success (200), the following fields are returned directly under response in the common envelope.
Each field is described below. The example above is for a new registration; if the favorite was already recorded (an idempotent re-POST), the response additionally includes the already_existed field (set to true).
Table: Response Fields
Error Response
For details on the error model, see API Overview. The HTTP statuses returned by this endpoint are as follows.
Table: Error Response