Add to Cart

Endpoint: POST /api/v1/store/cart

Description: Add a product to the authenticated user's shopping cart.

Headers:

  • Content-Type: application/json

  • Authorization: Bearer <access_token> (Authentication required)

Request Body:

{
  "productId": "string (required, MongoDB ObjectId)",
  "quantity": "number (optional, 1-50, default: 1)",
  "selectedSize": "string (optional, 1-20 chars)",
  "selectedColor": "string (optional, 1-50 chars)"
}

Success Response (200):

{
    "success": true,
    "message": "Product added to cart successfully",
    "data": {
        "cart": {
            "_id": "6854b117e5a90aa4b840c509",
            "items": [
                {
                    "product": {
                        "_id": "6854298f028e9678dd8f9bbe",
                        "product_name": "Tall Narrow Bathroom Storage Cabinet With 3 Drawers And 2 Shelves, Free Standing Kitchen Pantry Organizer With Open Compartment, Water-Resistant Finish",
                        "final_price": 120.99,
                        "currency": "USD",
                        "in_stock": true,
                        "color": "Grey",
                        "main_image": "https://img.ltwebstatic.com/images3_spmp/2024/08/09/e4/17231883609d35f827fa9cc1016466bcd0d72748bd_square.png",
                        "all_available_sizes": [
                            "one-size"
                        ]
                    },
                    "quantity": 1,
                    "price": 120.99,
                    "_id": "6854b1cae5a90aa4b840c50f",
                    "subtotal": 120.99
                }
            ],
            "totalItems": 1,
            "totalAmount": 120.99,
            "currency": "USD",
            "updatedAt": "2025-06-20T00:56:43.114Z"
        }
    }
}

Error Responses:

401 Unauthorized:

{
  "success": false,
  "message": "Access token required"
}

422 Validation Error:

{
  "success": false,
  "message": "Validation failed",
  "errors": {
    "productId": "Product ID is required",
    "quantity": "Quantity must be between 1 and 50"
  }
}

404 Not Found:

{
  "success": false,
  "message": "Product not found"
}

400 Bad Request:

{
  "success": false,
  "message": "Product is out of stock"
}
Updated on