create-cart
Method: POST
Path: /carts
Tags: Carts
Summary
Create cart
Description
Create cart
Storefront SDK Usage
SDK Method: sdk.cart.createCart()
Example:
typescript
const { data, error } = await sdk.cart.createCart({
items: [
{
product_id: "01H9XYZ12345ABCDE",
variant_id: null,
quantity: 2
},
{
product_id: "01H9ABC67890FGHIJ",
variant_id: "01H9XYZ67890KLMNO",
quantity: 1
}
],
metadata: {
"source": "web",
"campaign": "summer_sale"
}
});
if (error) {
console.error("Failed to create cart:", error.message);
} else {
console.log("Cart created:", data.cart.id);
}TypeScript Definition
typescript
"create-cart": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody: {
content: {
"application/json": {
items: components["schemas"]["UpdateCartItem"][];
metadata?: {
[key: string]: string;
};
};
};
};
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
message: string;
success: boolean;
content: {
cart: components["schemas"]["Cart"];
};
};
};
};
400: components["responses"]["BadRequest"];
401: components["responses"]["Unauthorized"];
404: components["responses"]["NotFound"];
};
};Component References
| Reference | Resolves To |
|---|---|
components["schemas"]["UpdateCartItem"] | UpdateCartItem |
components["schemas"]["Cart"] | Cart |
components["responses"]["BadRequest"] | BadRequest |
components["responses"]["Unauthorized"] | Unauthorized |
components["responses"]["NotFound"] | NotFound |
Request Body
Content Types: application/json
Responses
200
OK
400
Bad request
401
Not authorized for given operation on the Resource
404
Requested resource not found
OpenAPI Definition
json
{
"tags": [
"Carts"
],
"operationId": "create-cart",
"summary": "Create cart",
"description": "Create cart",
"externalDocs": {
"url": "https://llm-docs.commercengine.io/storefront/operations/create-cart",
"description": "API reference for the create-cart operation"
},
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"items"
],
"properties": {
"items": {
"type": "array",
"items": {
"$ref": "#/components/schemas/UpdateCartItem"
}
},
"metadata": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"message",
"success",
"content"
],
"properties": {
"message": {
"type": "string"
},
"success": {
"type": "boolean"
},
"content": {
"properties": {
"cart": {
"$ref": "#/components/schemas/Cart"
}
},
"required": [
"cart"
],
"type": "object"
}
}
}
}
}
},
"400": {
"$ref": "#/components/responses/BadRequest"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"404": {
"$ref": "#/components/responses/NotFound"
}
},
"security": [
{
"Authorization": []
}
],
"x-speakeasy-group": "carts",
"x-speakeasy-ignore": false,
"x-speakeasy-name-override": "createCart"
}Auto-generated from OpenAPI spec and TypeScript definitions