Skip to main content
POST
/
api
/
v1
/
users
/
{userId}
/
books
/
{bookId}
Add Book to User
curl --request POST \
  --url https://api.example.com/api/v1/users/{userId}/books/{bookId}
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "userName": "jsmith",
  "name": "John Smith",
  "birthDate": "1990-05-15",
  "bookIds": [
    "9f3e4a56-2c1d-4b8e-8f6d-5a3c2b1d4e5f",
    "7c9e6679-7425-40de-944b-e07fc1f90ae7"
  ]
}
This endpoint creates an association between a user and a book, adding the book to the user’s personal collection.

Authentication

This endpoint requires JWT authentication. Include a valid JWT token in the Authorization header.
Authorization: Bearer <your_jwt_token>

Path Parameters

userId
string
required
The unique identifier (UUID) of the user
bookId
string
required
The unique identifier (UUID) of the book to add to the user’s collection

Response

id
string
Unique identifier of the user (UUID format)
userName
string
Username for the user’s account
name
string
Full name of the user
birthDate
string
Date of birth in ISO 8601 format (YYYY-MM-DD)
bookIds
array
Updated array of book UUIDs associated with this user (includes the newly added book)

Example Request

cURL
curl -X POST "https://api.library.com/api/v1/users/550e8400-e29b-41d4-a716-446655440000/books/7c9e6679-7425-40de-944b-e07fc1f90ae7" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Example Response

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "userName": "jsmith",
  "name": "John Smith",
  "birthDate": "1990-05-15",
  "bookIds": [
    "9f3e4a56-2c1d-4b8e-8f6d-5a3c2b1d4e5f",
    "7c9e6679-7425-40de-944b-e07fc1f90ae7"
  ]
}

Status Codes

CodeDescription
200Successfully added book to user’s collection
400Bad request - Invalid UUID format
401Unauthorized - Invalid or missing JWT token
404User or book not found
500Internal server error

Notes

  • This endpoint establishes a many-to-many relationship between users and books
  • If the book is already in the user’s collection, the operation is idempotent (no duplicate added)
  • The response includes the complete updated user object with all associated book IDs
  • Both the user and the book must exist in the system

Build docs developers (and LLMs) love