Back to API Reference

Practice Sessions API

Save and retrieve chess practice sessions with complete move history and analysis data.

Authentication Required

All endpoints in this API require valid user authentication. Unauthenticated requests will receive 401 Unauthorized.

POST
/api/user/practice-sessions

Saves a new practice session for the authenticated user.

Request Body

{
  "openingId": "string (optional)",
  "moves": "string (required)",
  "finalFen": "string (required)",
  "movesCount": "number (required)"
}

Example Request

const response = await fetch('/api/user/practice-sessions', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    openingId: 'clk9x8d4q0001vq2o6q7q8r9s',
    moves: 'e4 e5 Nf3 Nc6 Bb5',
    finalFen: 'r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R',
    movesCount: 5
  })
});

Responses

200 OK - Success
{
  "success": true,
  "practiceSession": {
    "id": "string",
    "movesCount": 5,
    "createdAt": "2024-01-15T10:30:00.000Z"
  }
}
400 Bad Request - Validation Error
{
  "error": "Missing required fields",
  "details": {
    "moves": false,
    "finalFen": true,
    "movesCount": true
  }
}
GET
/api/user/practice-sessions

Retrieves a paginated list of the authenticated user's practice sessions.

Query Parameters

page
number (optional, default: 1)
limit
number (optional, default: 20)

Example Request

// Fetch practice sessions with pagination
const response = await fetch('/api/user/practice-sessions?page=1&limit=10');
const data = await response.json();

console.log(data.practiceSessions); // Array of session objects
console.log(data.total);            // Total number of sessions
console.log(data.page);             // Current page number
console.log(data.totalPages);       // Total number of pages

Success Response

{
  "practiceSessions": [
    {
      "id": "string",
      "userId": "string",
      "openingId": "string",
      "moves": "string",
      "finalFen": "string",
      "movesCount": 15,
      "createdAt": "2024-01-15T10:30:00.000Z",
      "opening": {
        "id": "string",
        "name": "Ruy Lopez",
        "eco": "C60",
        "fen": "string",
        "pgn": "string",
        "totalVisits": 150,
        "totalFavorites": 25,
        "totalPracticeSessions": 75
      }
    }
  ],
  "total": 45,
  "page": 1,
  "totalPages": 3
}

Field Specifications

Moves Format

  • Type: String
  • Format: Standard chess notation (e.g., "e4 e5 Nf3 Nc6 Bb5")
  • Purpose: Records the sequence of moves played during practice

Final FEN

  • Type: String
  • Format: Valid FEN position string
  • Purpose: Captures the final board state for analysis and replay

Moves Count

  • Type: Integer
  • Purpose: Tracks the length of the practice session