Overview
The Admin API provides privileged endpoints for administrative operations such as creating categories and products, generating test data, and performing system maintenance tasks. These endpoints require special authentication and should only be used by authorized administrators.Authentication
Admin endpoints use a separate authentication mechanism from regular API endpoints. Instead of user API keys, admin operations require an admin-specific API key.Admin API Key Header
All admin requests must include the admin API key in the request headers:ADMIN_API_KEY environment variable.
Authentication Flow
- The
adminKeyAuthmiddleware validates thex-api-keyheader - The provided key is compared against the server’s
ADMIN_API_KEY - If invalid, the request is rejected with a 403 Forbidden status
- If valid, the request proceeds to the endpoint handler
The admin API key check is case-sensitive and must match exactly. Make sure to securely store and transmit your admin API key.
Available Endpoints
The Admin API provides the following endpoint categories:Content Management
POST /api/admin/category
Create a new product category with an image.- Requires multipart/form-data with an
imagefield - Uploads and processes category image
- Returns created category data
POST /api/admin/product
Create a new product with multiple images.- Requires multipart/form-data with an
imagesfield (multiple files) - Uploads and processes product images
- Returns created product data
Test Data Generation
POST /api/admin/review
Generate fake review data for all products in the system.- Automatically creates realistic review data
- Useful for testing and development environments
- Populates reviews across all existing products
System Maintenance & Migration
These endpoints are used for data fixes and migrations:POST /api/admin/category/slug
Add slugs to all existing categories that don’t have them.- Automatically generates URL-friendly slugs
- Useful for migrating legacy data
POST /api/admin/product/slug
Add slugs to all existing products that don’t have them.- Automatically generates URL-friendly slugs
- Useful for migrating legacy data
POST /api/admin/product/fix-images
Fix or update image references for all products.- Repairs broken image links
- Updates image paths to current format
POST /api/admin/category/fix-image
Fix or update image references for all categories.- Repairs broken image links
- Updates image paths to current format
Example Request
Here’s an example of creating a new category using the Admin API:Example with JavaScript
Error Responses
403 Forbidden
Returned when the admin API key is invalid or missing:Always verify that your admin API key is correctly configured and included in request headers. Check for typos and ensure the header name is exactly
X-Api-Key.Security Best Practices
- Never expose admin keys: Keep your admin API key secret and never commit it to version control
- Use environment variables: Store the admin key in secure environment variables
- Restrict network access: Consider IP whitelisting for admin endpoints
- Audit admin actions: Log all admin API calls for security auditing
- Rotate keys regularly: Change admin API keys periodically
- Use HTTPS only: Always use encrypted connections for admin requests