Complete API reference for the Inventory Management System backend.
http://localhost:8000/api
All endpoints require authentication via Bearer token in the Authorization header:
Authorization: Bearer <token>
Login and get authentication token.
Request Body:
{
"email": "admin@inventory.com",
"password": "admin123"
}Response:
{
"success": true,
"user": {
"id": 1,
"email": "admin@inventory.com",
"name": "Super Admin",
"role": "super_admin",
"location_id": null
},
"token": "jwt_token_here",
"refreshToken": "refresh_token_here"
}Get current authenticated user information.
Response:
{
"user": {
"id": 1,
"email": "admin@inventory.com",
"name": "Super Admin",
"role": "super_admin",
"location_id": null
}
}Get all products with optional filters.
Query Parameters:
status(optional): Filter by status (active,inactive)category(optional): Filter by category
Response:
{
"products": [
{
"id": 1,
"name": "Product Name",
"sku": "SKU123",
"category": "Category",
"unit_price": 29.99,
"description": "Product description",
"status": "active",
"low_stock_threshold": 10,
"created_at": "2024-01-01T00:00:00.000Z",
"updated_at": "2024-01-01T00:00:00.000Z"
}
]
}Create a new product.
Request Body:
{
"name": "Product Name",
"sku": "SKU123",
"category": "Category",
"unit_price": 29.99,
"description": "Product description",
"status": "active"
}Get a specific product by ID.
Update a product.
Request Body: (all fields optional)
{
"name": "Updated Name",
"unit_price": 39.99,
"status": "inactive"
}Delete a product.
Get inventory items. Automatically filtered by user's location for non-admin users.
Query Parameters:
location_id(optional): Filter by location (admin only)
Response:
{
"inventory": [
{
"id": 1,
"location_id": 1,
"product_id": 1,
"quantity": 100,
"unit_price": 29.99,
"product_name": "Product Name",
"category": "Category",
"sku": "SKU123",
"location_name": "Main Warehouse",
"created_at": "2024-01-01T00:00:00.000Z",
"updated_at": "2024-01-01T00:00:00.000Z"
}
]
}Update inventory (add or subtract stock).
Request Body:
{
"location_id": 1,
"product_id": 1,
"quantity": 10,
"unit_price": 29.99
}Note: Positive quantity adds stock, negative subtracts.
Add initial stock to a warehouse. Only available to warehouse managers and super admins.
Request Body:
{
"location_id": 1,
"product_id": 1,
"quantity": 100,
"unit_price": 29.99
}Requirements:
- Location must be a warehouse
- User must be warehouse manager or super admin
- Non-admin users can only add to their own warehouse
Get all stock movements. Automatically filtered by user's location for non-admin users.
Query Parameters:
status(optional): Filter by status (pending,approved,received,cancelled)from_location_id(optional): Filter by source locationto_location_id(optional): Filter by destination location
Response:
{
"movements": [
{
"id": 1,
"from_location_id": 1,
"to_location_id": 2,
"status": "pending",
"notes": "Transfer notes",
"created_by": 1,
"from_location_name": "Main Warehouse",
"to_location_name": "Distributor A",
"created_by_name": "Super Admin",
"created_at": "2024-01-01T00:00:00.000Z",
"updated_at": "2024-01-01T00:00:00.000Z",
"items": [
{
"id": 1,
"movement_id": 1,
"product_id": 1,
"quantity": 10,
"unit_price": 29.99,
"product_name": "Product Name"
}
]
}
]
}Create a new stock movement.
Request Body:
{
"from_location_id": 1,
"to_location_id": 2,
"items": [
{
"product_id": 1,
"quantity": 10,
"unit_price": 29.99
}
],
"notes": "Optional notes"
}Validation:
- Location hierarchy must be valid (warehouse → distributor → sales_agent → store)
- Source location must have sufficient stock
- Non-admin users can only send from their own location
- Source and destination must be different
Get a specific movement with full details including activities.
Response:
{
"movement": {
"id": 1,
"from_location_id": 1,
"to_location_id": 2,
"status": "pending",
"items": [...],
"activities": [
{
"id": 1,
"movement_id": 1,
"action": "Created",
"description": "Movement created",
"user_id": 1,
"user_name": "Super Admin",
"created_at": "2024-01-01T00:00:00.000Z"
}
]
}
}Update movement status.
Request Body:
{
"status": "approved",
"action": "Approved",
"description": "Movement approved by manager"
}Status Values:
pending- Initial statusapproved- Approved by managerreceived- Stock received at destination (automatically updates inventory)cancelled- Movement cancelled
Note: When status is set to received, inventory is automatically:
- Deducted from source location
- Added to destination location
Get all locations.
Query Parameters:
type(optional): Filter by type (warehouse,distributor,sales_agent,store)
Response:
{
"locations": [
{
"id": 1,
"name": "Main Warehouse",
"type": "warehouse",
"role": "warehouse_manager",
"created_at": "2024-01-01T00:00:00.000Z",
"updated_at": "2024-01-01T00:00:00.000Z"
}
]
}Get activity logs.
Query Parameters:
limit(optional): Maximum number of logs to return (default: 100)
Response:
{
"logs": [
{
"id": 1,
"user_id": 1,
"action": "Product Created",
"description": "Created product: Product Name",
"entity_type": "product",
"entity_id": 1,
"user_name": "Super Admin",
"user_email": "admin@inventory.com",
"created_at": "2024-01-01T00:00:00.000Z"
}
]
}Create an activity log entry.
Request Body:
{
"action": "Product Created",
"description": "Created product: Product Name",
"entity_type": "product",
"entity_id": 1
}Get dashboard statistics.
Response:
{
"stats": {
"totalProducts": 50,
"totalInventory": 1000,
"pendingMovements": 5,
"activityLogs": 150,
"totalValue": 29990.00,
"avgValue": 29.99,
"uniqueProducts": 25
}
}Note: Statistics are automatically filtered by user's location for non-admin users.
Get all users. Only accessible to super admin.
Response:
{
"users": [
{
"id": 1,
"email": "admin@inventory.com",
"name": "Super Admin",
"role": "super_admin",
"location_id": null,
"location_name": null,
"created_at": "2024-01-01T00:00:00.000Z"
}
]
}Create a new user. Only accessible to super admin.
Request Body:
{
"email": "newuser@inventory.com",
"password": "password123",
"name": "New User",
"role": "sales_agent",
"location_id": 4
}Get a specific user. Users can view their own profile, super admin can view any.
Update a user. Users can update their own profile, super admin can update any.
Request Body: (all fields optional)
{
"email": "updated@inventory.com",
"name": "Updated Name",
"password": "newpassword",
"role": "distributor",
"location_id": 2
}Note: Only super admin can change role.
Delete a user. Only accessible to super admin. Cannot delete your own account.
All endpoints return standard error responses:
401 Unauthorized:
{
"error": "Unauthorized"
}403 Forbidden:
{
"error": "Forbidden"
}400 Bad Request:
{
"error": "Error message describing what went wrong"
}404 Not Found:
{
"error": "Resource not found"
}500 Internal Server Error:
{
"error": "Internal server error"
}The system enforces a strict location hierarchy for stock movements:
- Warehouse → can send to: Distributor
- Distributor → can send to: Sales Agent
- Sales Agent → can send to: Store
- Store → cannot send to anyone
Attempts to create movements that violate this hierarchy will return a 400 error.
- Full access to all endpoints
- Can manage users
- Can view all locations and inventory
- Can add initial stock to their warehouse
- Can create movements from their warehouse
- Can view their warehouse inventory
- Can create movements from their location
- Can view their location inventory
- Can create movements from their location
- Can view their location inventory
- Can view their location inventory
- Cannot create movements (receives stock only)