Skip to main content

Products API

Endpoints untuk mengelola products, variants, dan pricing.

GET /products

Get list of products dengan pagination dan filtering.

Request

GET /api/v1/products?page=1&limit=20&category=electronics&status=active
Authorization: Bearer {token}
X-Merchant-ID: merchant_abc

Query Parameters

ParameterTypeDescription
pageintegerPage number (default: 1)
limitintegerItems per page (default: 20, max: 100)
categorystringFilter by category
statusstringFilter by status (active, inactive)
searchstringSearch by name or SKU
sortstringSort fields (e.g., -created_at,name)

Response

{
  "success": true,
  "data": [
    {
      "id": "prod_123",
      "sku": "PROD-001",
      "name": "Product Name",
      "description": "Product description",
      "category": "electronics",
      "price": 100000,
      "cost": 75000,
      "stock": 50,
      "status": "active",
      "images": [
        "https://cdn.mstore.com/products/prod_123_1.jpg"
      ],
      "created_at": "2024-01-01T00:00:00Z",
      "updated_at": "2024-01-01T00:00:00Z"
    }
  ],
  "meta": {
    "page": 1,
    "limit": 20,
    "total": 150,
    "total_pages": 8
  }
}

GET /products/:id

Get product detail by ID.

Request

GET /api/v1/products/prod_123
Authorization: Bearer {token}
X-Merchant-ID: merchant_abc

Response

{
  "success": true,
  "data": {
    "id": "prod_123",
    "sku": "PROD-001",
    "name": "Product Name",
    "description": "Detailed product description",
    "category": "electronics",
    "price": 100000,
    "cost": 75000,
    "stock": 50,
    "status": "active",
    "variants": [
      {
        "id": "var_1",
        "name": "Size: L, Color: Red",
        "sku": "PROD-001-L-RED",
        "price": 100000,
        "stock": 20
      }
    ],
    "images": [
      "https://cdn.mstore.com/products/prod_123_1.jpg"
    ],
    "created_at": "2024-01-01T00:00:00Z",
    "updated_at": "2024-01-01T00:00:00Z"
  }
}

POST /products

Create new product.

Request

POST /api/v1/products
Authorization: Bearer {token}
X-Merchant-ID: merchant_abc
Content-Type: application/json

{
  "sku": "PROD-002",
  "name": "New Product",
  "description": "Product description",
  "category": "electronics",
  "price": 150000,
  "cost": 100000,
  "stock": 100,
  "status": "active"
}

Response

{
  "success": true,
  "data": {
    "id": "prod_456",
    "sku": "PROD-002",
    "name": "New Product",
    "created_at": "2024-01-01T00:00:00Z"
  }
}

PUT /products/:id

Update existing product.

Request

PUT /api/v1/products/prod_123
Authorization: Bearer {token}
X-Merchant-ID: merchant_abc
Content-Type: application/json

{
  "name": "Updated Product Name",
  "price": 120000,
  "stock": 75
}

Response

{
  "success": true,
  "data": {
    "id": "prod_123",
    "name": "Updated Product Name",
    "price": 120000,
    "stock": 75,
    "updated_at": "2024-01-01T00:00:00Z"
  }
}

DELETE /products/:id

Delete product (soft delete).

Request

DELETE /api/v1/products/prod_123
Authorization: Bearer {token}
X-Merchant-ID: merchant_abc

Response

{
  "success": true,
  "message": "Product deleted successfully"
}

POST /products/:id/variants

Add product variant.

Request

POST /api/v1/products/prod_123/variants
Authorization: Bearer {token}
X-Merchant-ID: merchant_abc
Content-Type: application/json

{
  "name": "Size: XL, Color: Blue",
  "sku": "PROD-001-XL-BLUE",
  "price": 110000,
  "stock": 30
}

Response

{
  "success": true,
  "data": {
    "id": "var_2",
    "product_id": "prod_123",
    "name": "Size: XL, Color: Blue",
    "sku": "PROD-001-XL-BLUE",
    "price": 110000,
    "stock": 30
  }
}