GET /products
Retrieve all products.
Requires authentication. Include Bearer token in Authorization header.
Response
curl -X GET https://api.yourdomain.com/products \
-H "Authorization: Bearer YOUR_TOKEN"
{
"products": [
{
"id": "prod_123",
"name": "Laptop Dell XPS 15",
"price": 1299.99,
"stock": 15,
"category": "Electronics",
"image": "https://cdn.example.com/laptop.jpg",
"description": "High-performance laptop",
"createdAt": "2026-03-01T10:00:00Z"
},
{
"id": "prod_124",
"name": "Wireless Mouse",
"price": 29.99,
"stock": 50,
"category": "Accessories",
"image": "https://cdn.example.com/mouse.jpg",
"description": "Ergonomic wireless mouse",
"createdAt": "2026-03-02T14:30:00Z"
}
]
}
GET /products/stock
Retrieve only products that are currently in stock.
Response
Array of products with stock > 0
curl -X GET https://api.yourdomain.com/products/stock \
-H "Authorization: Bearer YOUR_TOKEN"
{
"products": [
{
"id": "prod_123",
"name": "Laptop Dell XPS 15",
"price": 1299.99,
"stock": 15,
"category": "Electronics"
}
]
}
POST /products
Create a new product.
Requires authentication. Supports multipart/form-data for file uploads.
Request
Product image file (jpg, png, etc.)
Response
curl -X POST https://api.yourdomain.com/products \
-H "Authorization: Bearer YOUR_TOKEN" \
-F "name=New Laptop" \
-F "price=999.99" \
-F "stock=10" \
-F "category=cat_electronics" \
-F "description=High-performance laptop" \
-F "image=@/path/to/image.jpg"
{
"product": {
"id": "prod_125",
"name": "New Laptop",
"price": 999.99,
"stock": 10,
"category": "cat_electronics",
"description": "High-performance laptop",
"image": "https://cdn.example.com/prod_125.jpg",
"createdAt": "2026-03-07T12:00:00Z"
}
}
PUT /products/:id
Update an existing product.
Path Parameters
Request Body
Response
curl -X PUT https://api.yourdomain.com/products/prod_123 \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Laptop Dell XPS 15 Updated",
"price": 1199.99,
"stock": 20
}'
{
"product": {
"id": "prod_123",
"name": "Laptop Dell XPS 15 Updated",
"price": 1199.99,
"stock": 20,
"category": "Electronics",
"updatedAt": "2026-03-07T12:30:00Z"
}
}
DELETE /products/:id
Delete a product.
Path Parameters
Response
Whether deletion was successful
ID of the deleted product
curl -X DELETE https://api.yourdomain.com/products/prod_123 \
-H "Authorization: Bearer YOUR_TOKEN"
{
"success": true,
"deletedId": "prod_123"
}
POST /category
Create a new product category.
Request
Response
curl -X POST https://api.yourdomain.com/category \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Electronics"
}'
{
"category": {
"id": "cat_123",
"name": "Electronics",
"createdAt": "2026-03-07T10:00:00Z"
}
}
GET /category/all
Retrieve all product categories.
Response
Array of category objects
curl -X GET https://api.yourdomain.com/category/all \
-H "Authorization: Bearer YOUR_TOKEN"
{
"categories": [
{
"id": "cat_123",
"name": "Electronics",
"productCount": 45
},
{
"id": "cat_124",
"name": "Accessories",
"productCount": 120
},
{
"id": "cat_125",
"name": "Office Supplies",
"productCount": 78
}
]
}
Common Workflows
Creating a Product with Category
// Step 1: Get or create category
const categories = await getCategories();
let categoryId = categories.find(c => c.name === 'Electronics')?.id;
if (!categoryId) {
const newCategory = await createCategory('Electronics');
categoryId = newCategory.id;
}
// Step 2: Create product
const formData = new FormData();
formData.append('name', 'New Product');
formData.append('price', 99.99);
formData.append('stock', 50);
formData.append('category', categoryId);
formData.append('image', imageFile);
const product = await createProduct(formData);
Updating Product Stock
// Fetch current product
const products = await getProducts();
const product = products.find(p => p.id === 'prod_123');
// Update stock
const updated = await updateProduct(product.id, {
stock: product.stock - 5 // Decrease by 5
});
Error Codes
| Status | Description |
|---|
200 | Success |
201 | Product/Category created |
400 | Invalid request data |
401 | Unauthorized |
404 | Product not found |
500 | Server error |