🛍️ E-Commerce API Documentation
Complete API reference for the Laravel E-Commerce Platform
🚀 API Overview
This RESTful API provides comprehensive functionality for managing an e-commerce platform including products, categories, banners, brands, services, tags, and product attributes. All endpoints return JSON responses and follow REST conventions.
🎯 What This API Does
• Product Management: Create, read, update, delete products with full specifications
• Category Organization: Organize products into hierarchical categories
• Brand Management: Manage product brands with many-to-many relationships
• Marketing Tools: Manage banners and promotional content
• Service Management: Handle repair, sell, exchange, and upgrade services
• Tagging System: Flexible product tagging for better organization
• Dynamic Attributes: Custom product attributes (color, storage, etc.)
• Linked Variations: Connect separate products as variations with attribute selection
• Frequently Bought Together: Cross-selling recommendations for related products
🔐 Authentication
Currently, the API does not require authentication for most endpoints. However, for production use, consider implementing Laravel Sanctum or similar authentication mechanisms.
Future Authentication Example:
Authorization: Bearer your-api-token-here
📦 Products API
Manage products in your e-commerce store with full CRUD operations and advanced features.
Query Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| page | integer | No | Page number for pagination (default: 1) |
| per_page | integer | No | Items per page (default: 20) |
Example Request:
GET /api/products?page=1&per_page=10
Success Response (200):
{
"success": true,
"data": {
"current_page": 1,
"data": [
{
"id": 1,
"name": "iPhone 15 Pro",
"description": "Latest iPhone with A17 Pro chip...",
"price": "134900.00",
"category": {...}
}
],
"total": 50
},
"message": "Products retrieved successfully"
}
Example Request:
GET /api/products/featured
URL Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| slug | string | Yes | Category slug (e.g., 'smartphones') |
Example Request:
GET /api/products/category/smartphones
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Product name (max 255 chars) |
| description | string | Yes | Product description |
| price | numeric | Yes | Product price (min: 0) |
| original_price | numeric | No | Original price before discount |
| discount_percentage | integer | No | Discount percentage (0-100) |
| image_url | string | Yes | Main product image URL |
| gallery_images | array | No | Additional product images |
| category_slug | string | Yes | Category slug (must exist) |
| subcategory | string | No | Product subcategory |
| stock_quantity | integer | No | Available stock (min: 0) |
| is_featured | boolean | No | Whether product is featured |
| is_active | boolean | No | Whether product is active |
| brand_ids | array | No | Array of brand IDs to attach |
| tag_ids | array | No | Array of tag IDs to attach |
| attributes | array | No | Array of product attributes |
Attributes Array Structure:
| Field | Type | Required | Description |
|---|---|---|---|
| attribute_id | integer | Yes | ID of the attribute (must exist) |
| value | string | Yes | Attribute value |
| display_value | string | No | Display value (defaults to value) |
| sort_order | integer | No | Sort order (defaults to 0) |
Note: rating and review_count are automatically calculated from reviews and should not be provided during product creation.
Example Request:
POST /api/products
Content-Type: application/json
{
"name": "iPhone 15 Pro Max",
"description": "Latest iPhone with advanced features",
"price": 129999.00,
"original_price": 139999.00,
"discount_percentage": 7,
"image_url": "https://example.com/iphone15.jpg",
"gallery_images": [
"https://example.com/iphone15-1.jpg",
"https://example.com/iphone15-2.jpg"
],
"category_slug": "smartphones",
"subcategory": "flagship-phones",
"stock_quantity": 50,
"is_featured": true,
"is_active": true,
"brand_ids": [1, 2],
"tag_ids": [1, 5, 8, 12],
"attributes": [
{
"attribute_id": 1,
"value": "Space Black",
"display_value": "Space Black",
"sort_order": 1
},
{
"attribute_id": 2,
"value": "256GB",
"display_value": "256GB Storage",
"sort_order": 2
}
]
}
Success Response (201):
{
"success": true,
"data": {
"id": 4,
"name": "iPhone 15 Pro Max",
"description": "Latest iPhone with advanced features",
"price": "129999.00",
"original_price": "139999.00",
"discount_percentage": 7,
"image_url": "https://example.com/iphone15.jpg",
"gallery_images": ["https://example.com/iphone15-1.jpg", "https://example.com/iphone15-2.jpg"],
"category_slug": "smartphones",
"subcategory": "flagship-phones",
"stock_quantity": 50,
"is_featured": true,
"is_active": true,
"rating": "0.00",
"review_count": 0,
"created_at": "2025-10-14T12:00:00.000000Z",
"updated_at": "2025-10-14T12:00:00.000000Z",
"category": {
"id": 1,
"name": "Smartphones",
"slug": "smartphones"
},
"brands": [
{"id": 1, "name": "Apple", "slug": "apple"},
{"id": 2, "name": "Premium", "slug": "premium"}
],
"tags": [
{"id": 1, "name": "Latest", "slug": "latest"},
{"id": 5, "name": "Flagship", "slug": "flagship"},
{"id": 8, "name": "5G", "slug": "5g"},
{"id": 12, "name": "Premium", "slug": "premium"}
],
"simple_attributes": [
{
"id": 1,
"attribute_id": 1,
"value": "Space Black",
"display_value": "Space Black",
"sort_order": 1,
"attribute": {"name": "Color", "slug": "color"}
},
{
"id": 2,
"attribute_id": 2,
"value": "256GB",
"display_value": "256GB Storage",
"sort_order": 2,
"attribute": {"name": "Storage", "slug": "storage"}
}
]
},
"message": "Product created successfully"
}
URL Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| slug | string | Yes | Product slug (e.g., 'iphone-15-pro-max') |
Example Request:
GET /api/products/iphone-15-pro-max
Success Response (200):
{
"success": true,
"data": {
"id": 4,
"name": "iPhone 15 Pro Max",
"slug": "iphone-15-pro-max",
"description": "Latest iPhone with advanced features",
"price": "129999.00",
"category": {...},
"brands": [...],
"tags": [...],
"simple_attributes": [...]
},
"message": "Product retrieved successfully"
}
Request Body:
Same fields as POST /api/products, but all fields are optional (use 'sometimes' validation). When updating relationships:
- brand_ids: Replaces all existing brand associations
- tag_ids: Replaces all existing tag associations
- attributes: Replaces all existing attribute values
Note: rating and review_count are automatically calculated from reviews and should not be provided during product updates.
Example Request:
PUT /api/products/iphone-15-pro-max
Content-Type: application/json
{
"name": "iPhone 15 Pro Max - Updated",
"price": 124999.00,
"brand_ids": [1, 3],
"tag_ids": [1, 6, 9],
"attributes": [
{
"attribute_id": 1,
"value": "Titanium Black",
"display_value": "Titanium Black",
"sort_order": 1
}
]
}
Example Request:
DELETE /api/products/iphone-15-pro-max
URL Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| slug | string | Yes | Product slug (e.g., 'iphone-15-pro') |
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
| tag_ids | array | Yes | Array of tag IDs to attach |
Example Request:
POST /api/products/iphone-15-pro/tags
Content-Type: application/json
{
"tag_ids": [1, 2, 3]
}
Example Request:
DELETE /api/products/iphone-15-pro/tags/2
📂 Categories API
Manage product categories for organizing your store inventory.
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Category name (max 255 chars) |
| description | string | No | Category description |
| image_url | string | Yes | Category image URL |
| slug | string | No | URL slug (auto-generated if not provided) |
| is_active | boolean | No | Whether category is active |
| sort_order | integer | No | Sort order (min: 0) |
URL Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| slug | string | Yes | Category slug (e.g., 'smartphones') |
Example Request:
GET /api/categories/smartphones
Example Request:
PUT /api/categories/smartphones
Example Request:
DELETE /api/categories/smartphones
🎯 Banners API
Manage promotional banners and marketing content for your store.
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
| title | string | Yes | Banner title (max 255 chars) |
| description | string | No | Banner description |
| image_url | string | Yes | Banner image URL |
| link_url | string | No | Banner click URL |
| is_active | boolean | No | Whether banner is active |
| sort_order | integer | No | Sort order (min: 0) |
🏷️ Brands API
Manage product brands with many-to-many relationships to products.
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Brand name (max 255 chars) |
| image | string | No | Brand logo/image URL |
| description | string | No | Brand description |
| is_active | boolean | No | Whether brand is active |
| sort_order | integer | No | Sort order (min: 0) |
Example Request:
POST /api/brands
Content-Type: application/json
{
"name": "Sony",
"image": "https://example.com/sony-logo.jpg",
"description": "Electronics and entertainment products",
"is_active": true,
"sort_order": 7
}
URL Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| slug | string | Yes | Brand slug (e.g., 'apple') |
Example Request:
GET /api/brands/apple
Example Request:
PUT /api/brands/apple
Example Request:
DELETE /api/brands/apple
URL Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| slug | string | Yes | Brand slug (e.g., 'apple') |
🔧 Services API
Manage repair, sell, exchange, and upgrade services offered by your store.
URL Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| type | string | Yes | Service type: repair, sell, exchange, upgrade |
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Service name (max 255 chars) |
| description | string | Yes | Service description |
| icon | string | Yes | Service icon (FontAwesome class) |
| image_url | string | Yes | Service image URL |
| service_type | string | Yes | Type: repair, sell, exchange, upgrade |
| price_from | numeric | No | Starting price (min: 0) |
| price_to | numeric | No | Ending price (min: 0) |
| duration | string | No | Service duration |
| is_active | boolean | No | Whether service is active |
| sort_order | integer | No | Sort order (min: 0) |
| features | array | No | Service features array |
🏷️ Tags API
Manage product tags for flexible categorization and filtering.
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Tag name (max 255 chars) |
| color | string | No | Tag color (hex code, max 7 chars) |
| description | string | No | Tag description |
| is_active | boolean | No | Whether tag is active |
| sort_order | integer | No | Sort order (min: 0) |
Example Request:
POST /api/tags
Content-Type: application/json
{
"name": "Premium",
"color": "#FF6B6B",
"description": "High-end premium products",
"is_active": true,
"sort_order": 1
}
URL Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| slug | string | Yes | Tag slug (e.g., 'premium') |
Example Request:
GET /api/tags/premium
Example Request:
PUT /api/tags/premium
Example Request:
DELETE /api/tags/premium
URL Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| slug | string | Yes | Tag slug (e.g., 'premium') |
⚙️ Product Attributes API
Manage dynamic product attributes like color, storage, RAM, etc. for flexible product specifications.
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Attribute name (max 255 chars) |
| type | string | Yes | Attribute type: 'text' or 'image' |
| is_required | boolean | No | Whether attribute is required |
| is_filterable | boolean | No | Whether attribute can be used for filtering |
| sort_order | integer | No | Sort order (min: 0) |
| is_active | boolean | No | Whether attribute is active |
Example Request:
POST /api/product-attributes
Content-Type: application/json
{
"name": "Screen Size",
"type": "text",
"is_required": false,
"is_filterable": true,
"sort_order": 3,
"is_active": true
}
URL Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| slug | string | Yes | Attribute slug (e.g., 'color') |
🔗 Linked Variations API
Connect separate products as variations with attribute selection and multiple display types (color swatches, buttons, dropdowns).
URL Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | integer | Yes | Product ID |
Example Request:
GET /api/linked-variations/product/1
Success Response (200):
{
"success": true,
"data": {
"product": {
"id": 1,
"name": "T-Shirt Black M",
"price": "29.99"
},
"linked_variations": [
{
"id": 2,
"name": "T-Shirt White M",
"price": "29.99"
},
{
"id": 3,
"name": "T-Shirt Blue L",
"price": "29.99"
}
],
"variation_attributes": [
{
"attribute": {
"id": 1,
"name": "Color",
"display_type": "color"
},
"values": ["Black", "White", "Blue"],
"display_type": "color"
},
{
"attribute": {
"id": 2,
"name": "Size",
"display_type": "button"
},
"values": ["S", "M", "L", "XL"],
"display_type": "button"
}
]
},
"message": "Linked variations retrieved successfully"
}
Success Response (200):
{
"success": true,
"data": [
{
"id": 1,
"name": "T-Shirt Collection",
"slug": "t-shirt-collection",
"description": "Linked variations for T-shirt products",
"attribute_config": {
"color": {"display_type": "color", "required": true},
"size": {"display_type": "button", "required": true}
},
"products": [...]
}
],
"message": "Product groups retrieved successfully"
}
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Group name (max 255 chars) |
| description | string | No | Group description |
| attribute_config | object | No | Attribute display configuration |
| is_active | boolean | No | Whether group is active |
| sort_order | integer | No | Sort order (min: 0) |
Example Request:
POST /api/linked-variations/groups
Content-Type: application/json
{
"name": "Smartphone Collection",
"description": "Linked variations for smartphone products",
"attribute_config": {
"color": {"display_type": "color", "required": true},
"storage": {"display_type": "dropdown", "required": true}
},
"is_active": true,
"sort_order": 1
}
URL Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| groupId | integer | Yes | Product group ID |
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
| products | array | Yes | Array of products to link |
| products.*.product_id | integer | Yes | Product ID to link |
| products.*.attribute_values | object | Yes | Attribute values for this product |
| products.*.sort_order | integer | No | Sort order (min: 0) |
| products.*.is_active | boolean | No | Whether link is active |
Example Request:
POST /api/linked-variations/groups/1/link-products
Content-Type: application/json
{
"products": [
{
"product_id": 1,
"attribute_values": {
"1": "Black", // color attribute
"2": "M" // size attribute
},
"sort_order": 1,
"is_active": true
},
{
"product_id": 2,
"attribute_values": {
"1": "White",
"2": "L"
},
"sort_order": 2,
"is_active": true
}
]
}
URL Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| groupId | integer | Yes | Product group ID |
Query Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| attribute_values | object | Yes | Attribute values to filter by |
Example Request:
GET /api/linked-variations/groups/1/products?attribute_values[1]=Black&attribute_values[2]=M
URL Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| groupId | integer | Yes | Product group ID |
Success Response (200):
{
"success": true,
"data": {
"group": {
"id": 1,
"name": "T-Shirt Collection"
},
"attributes": [
{
"id": 1,
"name": "Color",
"slug": "color",
"display_type": "color",
"values": ["Black", "White", "Blue", "Red"]
},
{
"id": 2,
"name": "Size",
"slug": "size",
"display_type": "button",
"values": ["S", "M", "L", "XL"]
}
]
},
"message": "Attribute values retrieved successfully"
}
🎨 Display Types Supported:
Color Swatches: display_type: "color" - Perfect for color selection like in the realme watch example
Button Groups: display_type: "button" - Great for sizes (S, M, L, XL)
Dropdowns: display_type: "dropdown" - Ideal for storage options (64GB, 128GB, 256GB)
Text Display: display_type: "text" - Simple text-based selection
Image Gallery: display_type: "image" - Image-based selection for visual variants
💡 Frontend Implementation Example:
Color Swatches (like realme watch):
// Based on display_type: "color"
<div class="color-swatches">
{variation_attributes.map(attr =>
attr.display_type === 'color' && (
<div key={attr.attribute.id} className="color-attribute">
<label>{attr.attribute.name}</label>
{attr.values.map(color => (
<button
key={color}
className="color-swatch"
style={{backgroundColor: getColorCode(color)}}
onClick={() => selectVariation(attr.attribute.id, color)}
/>
))}
</div>
)
)}
</div>
🛒 Frequently Bought Together API
Cross-selling recommendations system that suggests related products customers frequently buy together. Perfect for increasing average order value and improving customer experience.
URL Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | integer | Yes | Product ID |
Example Request:
GET /api/frequently-bought-together/product/1
Success Response (200):
{
"success": true,
"data": {
"product": {
"id": 1,
"name": "iPhone 15 Pro",
"price": "134900.00",
"formatted_price": "₹134,900"
},
"frequently_bought_together": [
{
"id": 2,
"name": "Samsung Galaxy S24 Ultra",
"description": "Premium Android smartphone with S Pen and advanced AI features",
"price": "124999.00",
"original_price": "139999.00",
"discount_percentage": 11,
"formatted_price": "₹124,999",
"formatted_original_price": "₹139,999",
"savings": 15000,
"image_url": "https://images.unsplash.com/photo-1511707171631-9ed0b8b4b0b5",
"gallery_images": null,
"rating": "4.70",
"review_count": 980,
"stock_quantity": 30,
"is_featured": true,
"is_in_stock": true,
"sort_order": 1
},
{
"id": 3,
"name": "OnePlus 12",
"description": "Flagship killer with Snapdragon 8 Gen 3 and 100W fast charging",
"price": "64999.00",
"original_price": "69999.00",
"discount_percentage": 7,
"formatted_price": "₹64,999",
"formatted_original_price": "₹69,999",
"savings": 5000,
"image_url": "https://images.unsplash.com/photo-1511707171631-9ed0b8b4b0b5",
"gallery_images": null,
"rating": "4.60",
"review_count": 650,
"stock_quantity": 75,
"is_featured": true,
"is_in_stock": true,
"sort_order": 2
}
],
"count": 2
},
"message": "Frequently bought together products retrieved successfully"
}
URL Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | integer | Yes | Product ID |
Example Request:
GET /api/frequently-bought-together/bought-with/2
Success Response (200):
{
"success": true,
"data": {
"product": {
"id": 2,
"name": "Samsung Galaxy S24 Ultra",
"price": "124999.00",
"formatted_price": "₹124,999"
},
"bought_with_products": [
{
"id": 1,
"name": "iPhone 15 Pro",
"price": "134900.00",
"formatted_price": "₹134,900",
"sort_order": 1
}
],
"count": 1
},
"message": "Products frequently bought with this product retrieved successfully"
}
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
| product_id | integer | Yes | Main product ID |
| related_product_id | integer | Yes | Related product ID (must be different from product_id) |
| sort_order | integer | No | Display order (default: 0) |
Example Request:
POST /api/frequently-bought-together/add
Content-Type: application/json
{
"product_id": 1,
"related_product_id": 2,
"sort_order": 1
}
Success Response (200):
{
"success": true,
"message": "Frequently bought together relationship added successfully"
}
Error Response (400):
{
"success": false,
"message": "This relationship already exists"
}
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
| product_id | integer | Yes | Main product ID |
| related_product_id | integer | Yes | Related product ID to remove |
Example Request:
DELETE /api/frequently-bought-together/remove
Content-Type: application/json
{
"product_id": 1,
"related_product_id": 2
}
Success Response (200):
{
"success": true,
"message": "Frequently bought together relationship removed successfully"
}
Error Response (404):
{
"success": false,
"message": "Relationship not found"
}
🎯 Key Features:
Many-to-Many Relationships: Each product can have multiple frequently bought together products
Manual Admin Control: Complete control over which products are suggested together
Full Product Details: Returns complete product information including prices, images, ratings
Sort Order Support: Control the display order of suggestions
Active Products Only: Only shows active, in-stock products
Bidirectional Relationships: Supports both forward and reverse relationship queries
💡 Frontend Implementation Example:
Product Detail Page:
// Fetch frequently bought together products
const response = await fetch('/api/frequently-bought-together/product/1');
const data = await response.json();
// Display suggestions
if (data.success && data.data.frequently_bought_together.length > 0) {
const suggestions = data.data.frequently_bought_together;
suggestions.forEach(product => {
// Create product card with:
// - Product image
// - Product name
// - Price (with discount if applicable)
// - Add to cart button
// - Quick view button
});
}
🛍️ Business Use Cases:
E-commerce Product Pages: Show "Customers who bought this also bought..." section
Cart Recommendations: Suggest complementary products during checkout
Category Pages: Display related products within categories
Email Marketing: Include product recommendations in promotional emails
Mobile Apps: Implement swipeable product suggestion carousels
Admin Dashboard: Manage cross-selling relationships and track performance
📊 Data Management:
Adding Relationships: Use POST /api/frequently-bought-together/add for each product pair
Bulk Import: Create scripts to import relationships from CSV or external systems
Analytics Integration: Track which relationships drive the most sales
Seasonal Updates: Update relationships based on seasonal trends and promotions
📊 HTTP Status Codes
Standard HTTP status codes used throughout the API.
Success Responses:
200 OK - Request successful 201 Created - Resource created successfullyClient Error Responses:
404 Not Found - Resource not found 422 Unprocessable Entity - Validation failedServer Error Responses:
500 Internal Server Error - Server error💡 Real-world Use Cases
Common scenarios and how to use the API effectively.
🛒 E-commerce Store Frontend
Scenario: Building a product catalog page
Steps:
1. Get categories: GET /api/categories
2. Get brands: GET /api/brands
3. Get featured products: GET /api/products/featured (includes brands, tags)
4. Get active banners: GET /api/banners
5. Get filterable attributes: GET /api/product-attributes/filterable
6. Get product details: GET /api/products/{id} (includes all relationships)
🔍 Product Search & Filtering
Scenario: Implementing product search with filters
Steps:
1. Get products by category: GET /api/products/category/smartphones
2. Get products by brand: GET /api/brands/apple/products
3. Get products by tag: GET /api/tags/premium/products
4. Get products by attribute: GET /api/product-attributes/color/products
5. Filter by specific attribute value (implement in frontend)
📱 Mobile App Integration
Scenario: Mobile app consuming the API
Steps:
1. Load initial data: Categories, brands, featured products, banners
2. Implement pagination for product lists
3. Use brands and tags for product recommendations
4. Display product details with attributes and brand info
🏷️ Brand Management
Scenario: Managing product brands and brand-product relationships
Steps:
1. Get all brands: GET /api/brands
2. Create new brand: POST /api/brands
3. Update brand info: PUT /api/brands/{id}
4. Get products by brand: GET /api/brands/{slug}/products
5. Manage brand-product relationships (implement in frontend)
🛠️ Admin Dashboard
Scenario: Managing store content
Steps:
1. CRUD operations for all entities (products, categories, brands, etc.)
2. Manage product tags and attributes
3. Update banners and promotional content
4. Monitor service offerings
📦 Product Management with Relationships
Scenario: Creating and managing products with brands, tags, and attributes
Steps:
1. Create product with relationships: POST /api/products (include brand_ids, tag_ids, attributes)
2. Update product relationships: PUT /api/products/{id} (replace all relationships)
3. Get product with all data: GET /api/products/{id}
4. Filter by brand: GET /api/brands/{slug}/products
5. Filter by tag: GET /api/tags/{slug}/products
6. Filter by attribute: GET /api/product-attributes/{slug}/products
🔗 Linked Variations Implementation
Scenario: Creating product variations like WooCommerce Linked Variations
Steps:
1. Create product group: POST /api/linked-variations/groups
2. Create individual products: POST /api/products (separate products for each variant)
3. Link products to group: POST /api/linked-variations/groups/{groupId}/link-products
4. Get linked variations: GET /api/linked-variations/product/{id}
5. Filter by attributes: GET /api/linked-variations/groups/{groupId}/products
6. Display with proper UI: Use display_type (color, button, dropdown) for frontend
🛒 Frequently Bought Together Implementation
Scenario: Implementing cross-selling recommendations on product pages
Steps:
1. Get product details: GET /api/products/{id}
2. Get frequently bought together: GET /api/frequently-bought-together/product/{id}
3. Display suggestions: Show related products with images, prices, and add-to-cart buttons
4. Track clicks: Monitor which suggestions are most effective
5. Manage relationships: POST /api/frequently-bought-together/add for new suggestions
6. Update relationships: DELETE /api/frequently-bought-together/remove for outdated suggestions
🔄 Third-party Integration
Scenario: Integrating with external systems
Steps:
1. Sync product data: GET /api/products
2. Update inventory: PUT /api/products/{id}
3. Manage categories: POST /api/categories
4. Handle webhooks for real-time updates
🚀 Getting Started
Ready to start using the API? Here's how to get started:
1. Test the API is running:
curl http://127.0.0.1:8000/api/products
2. Get your first product:
curl http://127.0.0.1:8000/api/products/1
3. Create a new product:
curl -X POST http://127.0.0.1:8000/api/products \
-H "Content-Type: application/json" \
-d '{"name":"Test Product","description":"A test product","price":99.99,"image_url":"https://example.com/image.jpg","category_slug":"smartphones","brand_ids":[1],"tag_ids":[1,2]}'
4. Create linked variations:
# Create product group
curl -X POST http://127.0.0.1:8000/api/linked-variations/groups \
-H "Content-Type: application/json" \
-d '{"name":"T-Shirt Collection","attribute_config":{"color":{"display_type":"color","required":true}}}'
# Link products to group
curl -X POST http://127.0.0.1:8000/api/linked-variations/groups/1/link-products \
-H "Content-Type: application/json" \
-d '{"products":[{"product_id":1,"attribute_values":{"1":"Black"}}]}'
5. Set up frequently bought together:
# Get frequently bought together products
curl http://127.0.0.1:8000/api/frequently-bought-together/product/1
# Add a relationship
curl -X POST http://127.0.0.1:8000/api/frequently-bought-together/add \
-H "Content-Type: application/json" \
-d '{"product_id":1,"related_product_id":2,"sort_order":1}'
# Remove a relationship
curl -X DELETE http://127.0.0.1:8000/api/frequently-bought-together/remove \
-H "Content-Type: application/json" \
-d '{"product_id":1,"related_product_id":2}'
📚 Next Steps
• Explore all endpoints using the examples above
• Implement error handling in your application
• Add authentication for production use
• Set up rate limiting for API protection
• Monitor API usage and performance
📞 Support
Need help with the API? Here are some resources:
🔧 Troubleshooting
• Check that the Laravel server is running: php artisan serve
• Verify database connection and migrations
• Check Laravel logs in storage/logs/
• Ensure all required fields are provided in requests