Add Item to Cart
Add a product item to an existing cart. Updates the cart with the specified product variant and quantity.
HTTP Method & Endpoint
POST | /cart/item
Request
Request Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
cartId | String | Yes | Unique identifier of the cart to add the item to |
variantId | String | Yes | ID of the product variant to add |
quantity | Number | Yes | Number of units to add to the cart |
price | Number | Yes | Price per unit of the product variant (in paise) |
Response Format
Success Response (200 OK)
| Field | Type | Description |
|---|---|---|
message | String | Status message indicating the result of the operation |
data | Data | Contains all details about the updated cart |
source | String | Source of the order data (e.g., "db") |
Data Object Properties
| Field | Type | Description |
|---|---|---|
id | String | Unique identifier for the cart |
storeId | String | Store ID for which the cart was created |
customerId | String | Customer's unique identifier |
totalAmount | Number | Total amount payable for the items in the cart |
items | Array(Items) | List of all items in the cart |
Items Array Properties
| Field | Type | Description |
|---|---|---|
variantId | String | ID of the product variant |
quantity | Number | Number of units in the cart |
price | Number | Price per unit (in paise) |
Sample Response
{
"message": "Cart Updated Successfully",
"data": {
"id": "43863324215067648",
"storeId": "23863324215067648",
"customerId": "13863324215067648",
"totalAmount": 5000,
"items": [
{
"variantId": "322863324215067648",
"quantity": 50,
"price": 100
}
]
},
"source": "db"
}
Examples
Javascript (React)
import axios from "axios";
import { api } from "../constant";
const addItemToCart = async (cartId, variantId, quantity, price) => {
try {
const response = await api.post("/cart/item", {
cartId: cartId
variantId:variantId
quantity: quantity,
price: price,
});
console.log("Item added to cart:", response.data);
} catch (error) {
console.error("Error adding item to cart:", error.response?.data || error.message);
}
};
Error Responses
| Status Code | Description |
|---|---|
| 400 | Bad Request - Invalid parameters or validation failed |
| 401 | Unauthorized - Authentication token is missing or invalid |
| 404 | Not Found - Cart with the specified ID was not found |
| 500 | Internal Server Error - Something went wrong on the server |