Skip to main content

Version: v1

Create Cart

Create a new empty cart. Returns a unique cartId which you’ll use in all subsequent cart operations.


HTTP Method & Endpoint​

POST | /cart


Request​

Request Body Parameters​

ParameterTypeRequiredDefaultDescription
customerIdStringYes-Unique identifier of the customer. This is available in the customer object (specifically the id field) returned upon successful login.

Example Request​

{
"customerId": "customer_123"
}

Response Format​

Example Response​

{
"message": "Cart Created Successfully",
"data": {
"id": "cart_PhIidALwQ8JFCBOU",
"storeId": "store_Vc3PvYOQrna9GOF7",
"customerId": "customer_123",
"totalAmount": 0
},
"source": "db"
}

Success Response (200 OK)​

FieldTypeDescription
messageStringStatus message indicating the result of the cart creation
dataCartContains all details about the cart
sourceStringSource of the order data (e.g., "db")

Cart Object Properties​

FieldTypeDescription
idStringUnique identifier for the cart
storeIdStringStore ID for which the cart was created
customerIdStringCustomer's unique identifier
totalAmountNumberTotal amount payable for the items in the cart

Examples​

Javascript (React)​

import axios from "axios";
import { api } from "../constant";

const createCart = async () => {
try {
const customerId = localStorage.get("customerId");
const response = await api.post("/cart", {
customerId: customerId,
});

console.log("Cart Created Successfully:", response.data);
const data = response.data.data;
const cartId = data.cartId;
return cartId;
} catch (error) {
console.error("Error creating cart:", error.response?.data || error.message);
}
};

Error Responses​

Status CodeDescription
400Bad Request - Invalid customer ID format
401Unauthorized - Authentication token is missing or invalid
403Forbidden - Access to carts not allowed
404Not Found - No carts found for the specified customer
500Internal Server Error - Something went wrong on the server