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​

Headers​

HeaderValueDescription
Content-Typeapplication/jsonSpecifies that the request body is in JSON format
AuthorizationBearer {token}Authentication token (replace {token} with your actual token)
x-store-id{storeId}StoreId (replace {storeId} with your actual storeId)

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​

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 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