← Back to Table of Contents

API Documentation

OpenSite Analytics provides a RESTful API for managing sites, tracking analytics, and user authentication.

Base URL Authentication Endpoints Error Handling Rate Limiting

Base URL

http://localhost:8000

Authentication

All API endpoints (except login and register) require JWT authentication.

Headers

Authorization: Bearer <your_jwt_token>
Content-Type: application/json

Endpoints

Authentication

POST
/api/auth/login

Login user and return JWT token.

POST
/api/auth/register

Register new user account.

POST
/api/auth/refresh

Refresh JWT token.

Sites

GET
/api/sites

Get all sites for authenticated user.

POST
/api/sites

Create new site.

GET
/api/sites/{id}

Get site by ID.

PUT
/api/sites/{id}

Update site.

DELETE
/api/sites/{id}

Delete site.

Analytics

GET
/api/analytics/overview/{site_id}

Get analytics overview for site.

GET
/api/analytics/pageviews/{site_id}

Get page view analytics.

GET
/api/analytics/visitors/{site_id}

Get visitor analytics.

GET
/api/analytics/realtime/{site_id}

Get real-time analytics.

Events

POST
/api/events/track

Track custom event.

GET
/api/events/{site_id}

Get events for site.

Users

GET
/api/users/profile

Get user profile.

PUT
/api/users/profile

Update user profile.

GET
/api/users/settings

Get user settings.

PUT
/api/users/settings

Update user settings.

Error Handling

API returns appropriate HTTP status codes and error messages.

Status Codes

Error Response Format

{
  "error": "Error message",
  "code": "ERROR_CODE",
  "details": {}
}

Rate Limiting

API endpoints are rate limited to prevent abuse.

Limits

Headers

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1640995200