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
Headers
| Header | Value | Description |
|---|---|---|
Content-Type | application/json | Specifies that the request body is in JSON format |
Authorization | Bearer {token} | Authentication token (replace {token} with your actual token) |
x-store-id | {storeId} | StoreId (replace {storeId} with your actual storeId) |
Request Body Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
customerId | String | Yes | - | 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)
| Field | Type | Description |
|---|---|---|
message | String | Status message indicating the result of the cart creation |
data | Cart | Contains all details about the cart |
source | String | Source of the order data (e.g., "db") |
Cart 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 |
Examples
cURL
curl -X POST "https://dev-sfapi.unisouk.com/cart" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <TOKEN>" \
-H "x-store-id: <STORE_ID>" \
-d '{
"customerId": "customer_123"
}'
Javascript (React)
import axios from "axios";
const createCart = async () => {
try {
const response = await axios.post(
"https://dev-sfapi.unisouk.com/cart",
{
customerId: "customer_123",
},
{
headers: {
"Content-Type": "application/json",
Authorization: "Bearer <TOKEN>",
"x-store-id": "<STORE_ID>",
},
}
);
console.log("Cart Created Successfully:", response.data);
} catch (error) {
console.error("Error creating cart:", error.response?.data || error.message);
}
};
Error Responses
| Status Code | Description |
|---|---|
| 400 | Bad Request - Invalid customer ID format |
| 401 | Unauthorized - Authentication token is missing or invalid |
| 403 | Forbidden - Access to carts not allowed |
| 404 | Not Found - No carts found for the specified customer |
| 500 | Internal Server Error - Something went wrong on the server |