Skip to main content

Toggle Upvote

Add or remove a like/upvote on a note. Use the type parameter to specify whether to add or remove the like.

Headers

Authorization
string
required
Bearer token for authentication

Query Parameters

note_id
string
required
The ID of the note to like or unlike
type
string
required
Action to perform: add to like the note, remove to unlike

Response

message
string
Success message indicating like or unlike action
data
object
Updated note information
data.id
number
The note ID
data.likes
array
Array of users who have liked this note
data.likes[].likeId
number
User ID of the person who liked
data.likes[].userId
string
Email of the user who liked
curl -X POST "https://api.noteverse.com/api/notes/upvotes?note_id=123&type=add" \
  -H "Authorization: Bearer YOUR_TOKEN"

Response Examples

Like Added
{
  "message": "Note liked successfully",
  "data": {
    "id": 123,
    "likes": [
      {
        "likeId": 42,
        "userId": "[email protected]"
      },
      {
        "likeId": 43,
        "userId": "[email protected]"
      }
    ]
  }
}
Like Removed
{
  "message": "Note unliked successfully",
  "data": {
    "id": 123,
    "likes": [
      {
        "likeId": 43,
        "userId": "[email protected]"
      }
    ]
  }
}
The endpoint uses a many-to-many relationship between users and notes. When you add a like, the current user is connected to the note’s likes relation. When you remove a like, the user is disconnected.

Error Responses

error
string
Error message
statusCode
number
HTTP status code
400 Bad Request - Authentication failure or missing parameters
{
  "error": "Error deleting note",
  "statusCode": 400
}
The type parameter must be either add or remove. If the type is missing or invalid, the endpoint will not process the request.

Implementation Details

The upvote system uses Prisma’s connect and disconnect operations on the likes relation:
  • Add like: Connects the authenticated user to the note’s likes array
  • Remove like: Disconnects the authenticated user from the note’s likes array
This creates a many-to-many relationship where:
  • Each note can have multiple users who liked it
  • Each user can like multiple notes
  • The same user cannot like a note multiple times (enforced by Prisma)

Build docs developers (and LLMs) love