🛍️ E-Commerce API Documentation

Complete API reference for the Laravel E-Commerce Platform

Base URL: http://127.0.0.1:8000/api

🚀 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.

GET /api/products
Get all active products with pagination and basic relationships (category, brands, tags)

Query Parameters:

ParameterTypeRequiredDescription
pageintegerNoPage number for pagination (default: 1)
per_pageintegerNoItems 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"
}
GET /api/products/featured
Get featured products (limited to 8 items)

Example Request:

GET /api/products/featured
GET /api/products/category/{slug}
Get products by category slug

URL Parameters:

ParameterTypeRequiredDescription
slugstringYesCategory slug (e.g., 'smartphones')

Example Request:

GET /api/products/category/smartphones
POST /api/products
Create a new product with brands, tags, and attributes

Request Body:

FieldTypeRequiredDescription
namestringYesProduct name (max 255 chars)
descriptionstringYesProduct description
pricenumericYesProduct price (min: 0)
original_pricenumericNoOriginal price before discount
discount_percentageintegerNoDiscount percentage (0-100)
image_urlstringYesMain product image URL
gallery_imagesarrayNoAdditional product images
category_slugstringYesCategory slug (must exist)
subcategorystringNoProduct subcategory
stock_quantityintegerNoAvailable stock (min: 0)
is_featuredbooleanNoWhether product is featured
is_activebooleanNoWhether product is active
brand_idsarrayNoArray of brand IDs to attach
tag_idsarrayNoArray of tag IDs to attach
attributesarrayNoArray of product attributes

Attributes Array Structure:

FieldTypeRequiredDescription
attribute_idintegerYesID of the attribute (must exist)
valuestringYesAttribute value
display_valuestringNoDisplay value (defaults to value)
sort_orderintegerNoSort 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"
}
GET /api/products/{slug}
Get a specific product by slug with all relationships (category, brands, tags, attributes)

URL Parameters:

ParameterTypeRequiredDescription
slugstringYesProduct 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"
}
PUT /api/products/{slug}
Update a specific product with brands, tags, and attributes

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
    }
  ]
}
DELETE /api/products/{slug}
Delete a specific product by slug

Example Request:

DELETE /api/products/iphone-15-pro-max
POST /api/products/{slug}/tags
Attach tags to a product

URL Parameters:

ParameterTypeRequiredDescription
slugstringYesProduct slug (e.g., 'iphone-15-pro')

Request Body:

FieldTypeRequiredDescription
tag_idsarrayYesArray of tag IDs to attach

Example Request:

POST /api/products/iphone-15-pro/tags
Content-Type: application/json

{
  "tag_ids": [1, 2, 3]
}
DELETE /api/products/{slug}/tags/{tagId}
Remove a specific tag from a product

Example Request:

DELETE /api/products/iphone-15-pro/tags/2

📂 Categories API

Manage product categories for organizing your store inventory.

GET /api/categories
Get all active categories ordered by sort_order
POST /api/categories
Create a new category

Request Body:

FieldTypeRequiredDescription
namestringYesCategory name (max 255 chars)
descriptionstringNoCategory description
image_urlstringYesCategory image URL
slugstringNoURL slug (auto-generated if not provided)
is_activebooleanNoWhether category is active
sort_orderintegerNoSort order (min: 0)
GET /api/categories/{slug}
Get a specific category by slug

URL Parameters:

ParameterTypeRequiredDescription
slugstringYesCategory slug (e.g., 'smartphones')

Example Request:

GET /api/categories/smartphones
PUT /api/categories/{slug}
Update a specific category

Example Request:

PUT /api/categories/smartphones
DELETE /api/categories/{slug}
Delete a specific category by slug

Example Request:

DELETE /api/categories/smartphones

🎯 Banners API

Manage promotional banners and marketing content for your store.

GET /api/banners
Get all active banners ordered by sort_order
POST /api/banners
Create a new banner

Request Body:

FieldTypeRequiredDescription
titlestringYesBanner title (max 255 chars)
descriptionstringNoBanner description
image_urlstringYesBanner image URL
link_urlstringNoBanner click URL
is_activebooleanNoWhether banner is active
sort_orderintegerNoSort order (min: 0)
GET /api/banners/{id}
Get a specific banner by ID
PUT /api/banners/{id}
Update a specific banner
DELETE /api/banners/{id}
Delete a specific banner

🏷️ Brands API

Manage product brands with many-to-many relationships to products.

GET /api/brands
Get all active brands ordered by sort_order
POST /api/brands
Create a new brand

Request Body:

FieldTypeRequiredDescription
namestringYesBrand name (max 255 chars)
imagestringNoBrand logo/image URL
descriptionstringNoBrand description
is_activebooleanNoWhether brand is active
sort_orderintegerNoSort 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
}
GET /api/brands/{slug}
Get a specific brand by slug with associated products

URL Parameters:

ParameterTypeRequiredDescription
slugstringYesBrand slug (e.g., 'apple')

Example Request:

GET /api/brands/apple
PUT /api/brands/{slug}
Update a specific brand

Example Request:

PUT /api/brands/apple
DELETE /api/brands/{slug}
Delete a specific brand by slug

Example Request:

DELETE /api/brands/apple
GET /api/brands/{slug}/products
Get products by brand slug

URL Parameters:

ParameterTypeRequiredDescription
slugstringYesBrand slug (e.g., 'apple')

🔧 Services API

Manage repair, sell, exchange, and upgrade services offered by your store.

GET /api/services
Get all active services ordered by sort_order
GET /api/services/type/{type}
Get services by type

URL Parameters:

ParameterTypeRequiredDescription
typestringYesService type: repair, sell, exchange, upgrade
POST /api/services
Create a new service

Request Body:

FieldTypeRequiredDescription
namestringYesService name (max 255 chars)
descriptionstringYesService description
iconstringYesService icon (FontAwesome class)
image_urlstringYesService image URL
service_typestringYesType: repair, sell, exchange, upgrade
price_fromnumericNoStarting price (min: 0)
price_tonumericNoEnding price (min: 0)
durationstringNoService duration
is_activebooleanNoWhether service is active
sort_orderintegerNoSort order (min: 0)
featuresarrayNoService features array
GET /api/services/{id}
Get a specific service by ID
PUT /api/services/{id}
Update a specific service
DELETE /api/services/{id}
Delete a specific service

🏷️ Tags API

Manage product tags for flexible categorization and filtering.

GET /api/tags
Get all active tags ordered by sort_order
POST /api/tags
Create a new tag

Request Body:

FieldTypeRequiredDescription
namestringYesTag name (max 255 chars)
colorstringNoTag color (hex code, max 7 chars)
descriptionstringNoTag description
is_activebooleanNoWhether tag is active
sort_orderintegerNoSort 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
}
GET /api/tags/{slug}
Get a specific tag by slug with associated products

URL Parameters:

ParameterTypeRequiredDescription
slugstringYesTag slug (e.g., 'premium')

Example Request:

GET /api/tags/premium
PUT /api/tags/{slug}
Update a specific tag

Example Request:

PUT /api/tags/premium
DELETE /api/tags/{slug}
Delete a specific tag by slug

Example Request:

DELETE /api/tags/premium
GET /api/tags/{slug}/products
Get products by tag slug

URL Parameters:

ParameterTypeRequiredDescription
slugstringYesTag slug (e.g., 'premium')

⚙️ Product Attributes API

Manage dynamic product attributes like color, storage, RAM, etc. for flexible product specifications.

GET /api/product-attributes
Get all active product attributes ordered by sort_order
GET /api/product-attributes/filterable
Get only filterable attributes for product filtering
POST /api/product-attributes
Create a new product attribute

Request Body:

FieldTypeRequiredDescription
namestringYesAttribute name (max 255 chars)
typestringYesAttribute type: 'text' or 'image'
is_requiredbooleanNoWhether attribute is required
is_filterablebooleanNoWhether attribute can be used for filtering
sort_orderintegerNoSort order (min: 0)
is_activebooleanNoWhether 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
}
GET /api/product-attributes/{id}
Get a specific attribute by ID with associated values
PUT /api/product-attributes/{id}
Update a specific attribute
DELETE /api/product-attributes/{id}
Delete a specific attribute
GET /api/product-attributes/{slug}/products
Get products by attribute slug

URL Parameters:

ParameterTypeRequiredDescription
slugstringYesAttribute slug (e.g., 'color')

🔗 Linked Variations API

Connect separate products as variations with attribute selection and multiple display types (color swatches, buttons, dropdowns).

GET /api/linked-variations/product/{id}
Get linked variations and variation attributes for a product

URL Parameters:

ParameterTypeRequiredDescription
idintegerYesProduct 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"
}
GET /api/linked-variations/groups
Get all product groups

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"
}
POST /api/linked-variations/groups
Create a new product group

Request Body:

FieldTypeRequiredDescription
namestringYesGroup name (max 255 chars)
descriptionstringNoGroup description
attribute_configobjectNoAttribute display configuration
is_activebooleanNoWhether group is active
sort_orderintegerNoSort 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
}
POST /api/linked-variations/groups/{groupId}/link-products
Link products to a group with attribute values

URL Parameters:

ParameterTypeRequiredDescription
groupIdintegerYesProduct group ID

Request Body:

FieldTypeRequiredDescription
productsarrayYesArray of products to link
products.*.product_idintegerYesProduct ID to link
products.*.attribute_valuesobjectYesAttribute values for this product
products.*.sort_orderintegerNoSort order (min: 0)
products.*.is_activebooleanNoWhether 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
    }
  ]
}
GET /api/linked-variations/groups/{groupId}/products
Get products by attribute values within a group

URL Parameters:

ParameterTypeRequiredDescription
groupIdintegerYesProduct group ID

Query Parameters:

ParameterTypeRequiredDescription
attribute_valuesobjectYesAttribute values to filter by

Example Request:

GET /api/linked-variations/groups/1/products?attribute_values[1]=Black&attribute_values[2]=M
GET /api/linked-variations/groups/{groupId}/attribute-values
Get available attribute values for a group

URL Parameters:

ParameterTypeRequiredDescription
groupIdintegerYesProduct 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.

GET /api/frequently-bought-together/product/{id}
Get frequently bought together products for a specific product

URL Parameters:

ParameterTypeRequiredDescription
idintegerYesProduct 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"
}
GET /api/frequently-bought-together/bought-with/{id}
Get products that are frequently bought with the specified product (reverse relationship)

URL Parameters:

ParameterTypeRequiredDescription
idintegerYesProduct 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"
}
POST /api/frequently-bought-together/add
Add a frequently bought together relationship (Admin only)

Request Body:

FieldTypeRequiredDescription
product_idintegerYesMain product ID
related_product_idintegerYesRelated product ID (must be different from product_id)
sort_orderintegerNoDisplay 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"
}
DELETE /api/frequently-bought-together/remove
Remove a frequently bought together relationship (Admin only)

Request Body:

FieldTypeRequiredDescription
product_idintegerYesMain product ID
related_product_idintegerYesRelated 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 successfully

Client Error Responses:

404 Not Found - Resource not found 422 Unprocessable Entity - Validation failed

Server 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