API Reference
Complete API documentation for TikShip
API Documentation
TikShip provides a comprehensive RESTful API for all platform features.
Interactive API Documentation
For interactive API documentation with live testing:
Visit locally: http://localhost:3000/api-docs
Authentication
User Authentication
User endpoints use NextAuth session-based authentication:
const response = await fetch('/api/user/profile', {
credentials: 'include',
})Admin Authentication
Admin endpoints use cookie-based JWT authentication. First call the login endpoint — it sets an admin-token httpOnly cookie automatically:
// Step 1: Login (sets admin-token cookie)
const loginRes = await fetch('/api/admin/auth/login', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username: 'admin', password: 'password' }),
})
// Step 2: Subsequent requests include the cookie automatically
const response = await fetch('/api/admin/users', {
credentials: 'include',
})The server reads the admin-token cookie and resolves the admin user ID via requireAdminAuth(). No manual Authorization header is needed.
API Endpoints
Authentication
POST /api/auth/register- Register new userPOST /api/auth/login- User loginPOST /api/admin/auth/login- Admin login
Users
GET /api/user/profile- Get current user profilePATCH /api/user/profile- Update user profilePOST /api/user/change-password- Change password
Admin - Users
GET /api/admin/users- List all usersGET /api/admin/users/:id- Get user detailsPATCH /api/admin/users/:id- Update userDELETE /api/admin/users/:id- Delete user
Posts
GET /api/posts- List published postsGET /api/posts/:slug- Get post by slugPOST /api/admin/posts- Create post (admin)PATCH /api/admin/posts/:id- Update post (admin)
Products
GET /api/products- List active productsGET /api/products/:id- Get product detailsPOST /api/admin/products- Create product (admin)
Orders
GET /api/user/orders- Get user's ordersGET /api/admin/orders- List all orders (admin)
Payments
POST /api/payments/stripe/checkout- Create Stripe checkoutPOST /api/payments/paypal/create-order- Create PayPal orderPOST /api/webhooks/stripe- Stripe webhook handlerPOST /api/webhooks/paypal- PayPal webhook handler
Response Format
Success Response
{
"success": true,
"data": {},
"message": "Operation successful"
}Error Response
{
"success": false,
"error": "Error message",
"message": "User-friendly error message"
}Status Codes
200- Success201- Created400- Bad Request401- Unauthorized403- Forbidden404- Not Found500- Internal Server Error
Next Steps
- View locally Interactive API Docs
- Explore Components