Introduction
The Sales Management System API is a REST API built with Node.js and Express that enables you to manage sales orders, products, categories, and clients. The API provides comprehensive CRUD (Create, Read, Update, Delete) operations for all resources with automatic stock management for sales transactions.Base URL
All API endpoints are relative to the base URL:Request Format
The API accepts and returns JSON-formatted data. All request bodies should be sent as JSON.Required Headers
Include the following header in all requests with a body:Response Format
All API responses follow a consistent JSON structure:Success Response
Error Response
Error Responses
The API returns descriptive error messages when operations fail. Here are common error scenarios:Category Constraint Error
When attempting to delete a category that has associated products:Product Constraint Error
When attempting to delete a product that exists in sales orders:Client Constraint Error
When attempting to delete a client with existing sales orders:Authentication
The API currently does not require authentication. Authentication may be added in future versions.
Rate Limiting
There are currently no rate limits enforced on the API.
API Resources
The API is organized around four main resources:Categories
Manage product categories with create, read, and delete operations
Products
Full CRUD operations for product management including stock tracking
Clients
Manage customer information with full CRUD capabilities
Sales
Create and manage sales orders with automatic stock updates
Available Endpoints
Categories (3 endpoints)
POST /categories- Create a new categoryGET /categories- List all categoriesGET /categories/:id- Get a specific categoryDELETE /categories/:id- Delete a category
Products (5 endpoints)
POST /products- Create a new productGET /products- List all productsGET /products/:id- Get a specific productPATCH /products/:id- Update a productDELETE /products/:id- Delete a product
Clients (5 endpoints)
POST /clients- Create a new clientGET /clients- List all clientsGET /clients/:id- Get a specific clientPATCH /clients/:id- Update a clientDELETE /clients/:id- Delete a client
Sales (5 endpoints)
POST /sales- Create a new sale (automatically updates stock)GET /sales- List all sales with detailsGET /sales/:id- Get a specific sale with all itemsPATCH /sales/:id- Update a sale detailDELETE /sales/:id- Delete a complete sale order
Data Validation
The API uses Zod for request validation. Common validation rules include:- Category names: Minimum 3 characters
- Product names: Minimum 3 characters
- Product descriptions: Minimum 10 characters
- Email addresses: Must be valid email format
- Stock quantities: Must be positive integers
- Prices: Must be positive numbers
Next Steps
Categories API
Learn about category management
Products API
Explore product endpoints
Clients API
Manage client data
Sales API
Create and track sales orders