Skip to main content

List Products

Get a list of products with filtering by category and search term.Authentication Required: YesRoles: admin, manager, cashier

Query Parameters

page
integer
Page number
limit
integer
Number of products per page
Search products by name
category_id
integer
Filter by category ID

Response

message
string
Success message
data
object
products
array
id
string
Product ID (UUID)
name
string
Product name
price
number
Product price
stock
integer
Available stock
category_id
integer
Category ID
category_name
string
Category name
image_url
string
Product image URL
deleted_at
string
Soft delete timestamp (null if active)
pagination
object
Pagination information

Example

curl -X GET "https://localhost:8080/api/v1/products?page=1&limit=10&search=coffee" \
  -H "Cookie: access_token=YOUR_TOKEN"
{
  "message": "Products retrieved successfully",
  "data": {
    "products": [
      {
        "id": "123e4567-e89b-12d3-a456-426614174000",
        "name": "Espresso Coffee",
        "price": 25000,
        "stock": 100,
        "category_id": 1,
        "category_name": "Beverages",
        "image_url": "https://storage.example.com/products/espresso.jpg",
        "deleted_at": null
      }
    ],
    "pagination": {
      "current_page": 1,
      "per_page": 10,
      "total_data": 1,
      "total_page": 1
    }
  }
}

Get Product by ID

Retrieve detailed information of a specific product by its ID.Authentication Required: YesRoles: admin, manager, cashier

Path Parameters

id
string
required
Product ID (UUID format)

Response

message
string
Success message
data
object
id
string
Product ID
name
string
Product name
price
number
Product price
cost_price
number
Cost price
stock
integer
Available stock
category_id
integer
Category ID
category_name
string
Category name
image_url
string
Product image URL
options
array
Product options/variants
created_at
string
Creation timestamp
updated_at
string
Last update timestamp

Example

curl -X GET https://localhost:8080/api/v1/products/123e4567-e89b-12d3-a456-426614174000 \
  -H "Cookie: access_token=YOUR_TOKEN"

Create Product

Create a new product with multiple options.Authentication Required: YesRoles: admin, manager

Request Body

name
string
required
Product name (3-100 characters)
price
number
required
Product price
cost_price
number
required
Cost price (minimum 0)
stock
integer
required
Initial stock (minimum 0)
category_id
integer
required
Category ID
options
array
Array of product options
name
string
required
Option name (1-100 characters)
additional_price
number
Additional price for this option (minimum 0)

Response

message
string
Success message
data
object
Created product information

Example

curl -X POST https://localhost:8080/api/v1/products \
  -H "Content-Type: application/json" \
  -H "Cookie: access_token=YOUR_TOKEN" \
  -d '{
    "name": "Cappuccino",
    "price": 30000,
    "cost_price": 15000,
    "stock": 50,
    "category_id": 1,
    "options": [
      {
        "name": "Extra Shot",
        "additional_price": 5000
      },
      {
        "name": "Oat Milk",
        "additional_price": 8000
      }
    ]
  }'
{
  "message": "Product created successfully",
  "data": {
    "id": "223e4567-e89b-12d3-a456-426614174001",
    "name": "Cappuccino",
    "price": 30000,
    "cost_price": 15000,
    "stock": 50,
    "category_id": 1,
    "category_name": "Beverages",
    "options": [
      {
        "id": "323e4567-e89b-12d3-a456-426614174002",
        "name": "Extra Shot",
        "additional_price": 5000
      },
      {
        "id": "423e4567-e89b-12d3-a456-426614174003",
        "name": "Oat Milk",
        "additional_price": 8000
      }
    ],
    "created_at": "2024-03-03T12:00:00Z"
  }
}

Update Product

Update details of a specific product by its ID.Authentication Required: YesRoles: admin, manager

Path Parameters

id
string
required
Product ID (UUID format)

Request Body

name
string
Product name (3-100 characters)
price
number
Product price
cost_price
number
Cost price (minimum 0)
stock
integer
Stock quantity (minimum 0)
category_id
integer
Category ID
change_type
string
Stock change type: sale, restock, correction, return, or damage
note
string
Stock change note (max 255 characters)

Response

message
string
Success message
data
object
Updated product information

Example

curl -X PATCH https://localhost:8080/api/v1/products/223e4567-e89b-12d3-a456-426614174001 \
  -H "Content-Type: application/json" \
  -H "Cookie: access_token=YOUR_TOKEN" \
  -d '{
    "price": 32000,
    "stock": 75,
    "change_type": "restock",
    "note": "Weekly restock"
  }'

Delete Product

Soft delete a product by its ID.Authentication Required: YesRoles: admin

Path Parameters

id
string
required
Product ID (UUID format)

Response

message
string
Success message

Example

curl -X DELETE https://localhost:8080/api/v1/products/223e4567-e89b-12d3-a456-426614174001 \
  -H "Cookie: access_token=YOUR_TOKEN"

Upload Product Image

Upload an image for a product by ID.Authentication Required: YesRoles: admin, manager

Path Parameters

id
string
required
Product ID (UUID format)

Request Body (multipart/form-data)

image
file
required
Image file

Response

message
string
Success message
data
object
Updated product information with image URL

Example

curl -X POST https://localhost:8080/api/v1/products/223e4567-e89b-12d3-a456-426614174001/image \
  -H "Cookie: access_token=YOUR_TOKEN" \
  -F "image=@/path/to/product.jpg"

Get Stock History

Get stock history for a specific product with pagination.Authentication Required: YesRoles: admin, manager

Path Parameters

id
string
required
Product ID (UUID format)

Query Parameters

page
integer
Page number
limit
integer
Number of records per page

Response

message
string
Success message
data
object
history
array
id
string
History record ID
product_id
string
Product ID
change_type
string
Type of stock change
change_amount
integer
Amount changed
previous_stock
integer
Stock before change
current_stock
integer
Stock after change
note
string
Change note
created_by
string
User who made the change
created_at
string
Change timestamp
pagination
object
Pagination information

Example

curl -X GET "https://localhost:8080/api/v1/products/223e4567-e89b-12d3-a456-426614174001/stock-history?page=1&limit=10" \
  -H "Cookie: access_token=YOUR_TOKEN"

Build docs developers (and LLMs) love