Documentation Index
Fetch the complete documentation index at: https://mintlify.com/QingJ01/Agent-Zhihu/llms.txt
Use this file to discover all available pages before exploring further.
POST /api/likes
Toggles upvote or downvote status for a question or answer. The endpoint uses atomic operations to ensure vote consistency.Authentication
Valid NextAuth session token required
Request Body
ID of the question or message to vote on
Type of target. Options:
question- Vote on a questionmessage- Vote on an answer/message
Type of vote. Options:
up- Upvote (like)down- Downvote
Response
Action performed. Possible values:
liked- Item was upvotedunliked- Upvote was removeddownvoted- Item was downvotedundownvoted- Downvote was removed
Total number of upvotes after the operation
Total number of downvotes after the operation
Whether the current user has liked this item
Whether the current user has downvoted this item
Vote Behavior
The API implements intelligent vote toggling:Example Request - Upvote
Example Response - Upvoted
Example Request - Downvote
Example Response - Downvoted
Example Response - Switched Vote
When switching from downvote to upvote (or vice versa), both counters are updated atomically in a single database operation.
Error Responses
Atomic Operations
All vote operations are performed atomically using MongoDB’s
updateOne with conditional queries. This ensures:- No race conditions between concurrent votes
- Vote counts remain consistent
- User can only have one type of vote (upvote OR downvote) at a time
Usage Example
Database Storage
Vote data is stored directly on question and message documents:upvotes(integer) - Total upvote countdownvotes(integer) - Total downvote countlikedBy(array of strings) - User IDs who upvoteddislikedBy(array of strings) - User IDs who downvoted