API Reference

Authentication

Learn how to authenticate your requests to our Knowledge Base API.

GET /api/v1/auth/status

Checks the current authentication status.

Parameters:

  • Authorization (header, optional): Bearer token for authenticated requests.

Responses:

  • 200 OK: Authentication successful.
    
    {
      "authenticated": true,
      "user_id": "user_123",
      "scopes": ["read:content", "write:content"]
    }
                                    
  • 401 Unauthorized: Missing or invalid credentials.
    
    {
      "error": "Unauthorized",
      "message": "Authentication token is invalid or expired."
    }
                                    
POST /api/v1/auth/login

Logs in a user and returns an authentication token.

Request Body:


{
  "username": "string",
  "password": "string"
}
                    

Responses:

  • 200 OK: Login successful. Returns an authentication token.
    
    {
      "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
      "token_type": "Bearer",
      "expires_in": 3600
    }
                                    
  • 400 Bad Request: Invalid input.
    
    {
      "error": "Bad Request",
      "message": "Username and password are required."
    }
                                    
  • 401 Unauthorized: Invalid credentials.
    
    {
      "error": "Unauthorized",
      "message": "Invalid username or password."
    }
                                    

Users

Endpoints for managing user accounts and profiles.

GET /api/v1/users/{user_id}

Retrieves details for a specific user.

Parameters:

  • user_id (path, required): The unique identifier of the user.
  • Authorization (header, required): Bearer token for authenticated requests.

Responses:

  • 200 OK: User details returned.
    
    {
      "user_id": "user_123",
      "username": "alice_wonder",
      "email": "alice@example.com",
      "full_name": "Alice Wonderland",
      "created_at": "2023-10-27T10:00:00Z",
      "updated_at": "2023-10-27T10:00:00Z"
    }
                                    
  • 404 Not Found: User not found.
  • 401 Unauthorized: Authentication required.
GET /api/v1/users

Retrieves a list of all users. Supports pagination.

Parameters:

  • page (query, optional): The page number to retrieve (default: 1).
  • limit (query, optional): The number of items per page (default: 20).
  • Authorization (header, required): Bearer token for authenticated requests (admin scope).

Responses:

  • 200 OK: List of users.
    
    {
      "users": [
        {"user_id": "user_123", "username": "alice_wonder", "email": "alice@example.com"},
        {"user_id": "user_456", "username": "bob_builder", "email": "bob@example.com"}
      ],
      "pagination": {
        "current_page": 1,
        "total_pages": 5,
        "total_items": 100,
        "items_per_page": 20
      }
    }
                                    
  • 401 Unauthorized: Authentication required.
  • 403 Forbidden: User does not have permission.

Content Management

Endpoints for creating, retrieving, updating, and deleting knowledge base articles.

POST /api/v1/articles

Creates a new knowledge base article.

Request Body:


{
  "title": "string",
  "content": "string (markdown)",
  "category_id": "string",
  "tags": ["string"]
}
                    

Responses:

  • 201 Created: Article successfully created.
    
    {
      "article_id": "art_abc123",
      "title": "New Article Title",
      "created_at": "2023-10-27T11:00:00Z",
      "updated_at": "2023-10-27T11:00:00Z"
    }
                                    
  • 400 Bad Request: Invalid input.
  • 401 Unauthorized: Authentication required.
GET /api/v1/articles/{article_id}

Retrieves a specific knowledge base article by its ID.

Parameters:

  • article_id (path, required): The unique identifier of the article.
  • Authorization (header, optional): Bearer token for authenticated requests.

Responses:

  • 200 OK: Article found.
    
    {
      "article_id": "art_abc123",
      "title": "Existing Article",
      "content": "# Markdown Content\n\nThis is the **body** of the article.",
      "category_id": "cat_tech",
      "tags": ["api", "reference"],
      "created_at": "2023-10-27T11:00:00Z",
      "updated_at": "2023-10-27T12:30:00Z"
    }
                                    
  • 404 Not Found: Article not found.

Analytics

Insights into article usage and user engagement.

GET /api/v1/analytics/articles/popular

Retrieves a list of the most viewed articles.

Parameters:

  • limit (query, optional): Number of top articles to retrieve (default: 10).
  • Authorization (header, required): Bearer token for authenticated requests (analytics scope).

Responses:

  • 200 OK: Popular articles.
    
    {
      "articles": [
        {"article_id": "art_xyz789", "title": "Getting Started with the KB API", "views": 5000},
        {"article_id": "art_abc123", "title": "Advanced API Usage", "views": 4500}
      ]
    }
                                    
  • 401 Unauthorized: Authentication required.
  • 403 Forbidden: User lacks necessary permissions.