create-cart-address
Method: POST
Path: /carts/{id}/address
Tags: Carts
Summary
Set cart address
Description
Sets billing and shipping addresses on a cart. Returns a fully updated Cart object. For registered users, pass billing_address_id and shipping_address_id. For guest checkout, pass inline billing_address and shipping_address objects.
Storefront SDK Usage
SDK Method: sdk.cart.updateCartAddress()
Example:
typescript
// For registered users with saved addresses
const { data, error } = await sdk.cart.updateCartAddress(
{ id: "01H9CART12345ABCDE" },
{
billing_address_id: "01H9ADDR12345BILL",
shipping_address_id: "01H9ADDR12345SHIP"
}
);
if (error) {
console.error("Failed to update cart address:", error.message);
} else {
console.log("Addresses updated:", data.cart);
}
// For guest checkout with new addresses
const { data: guestData, error: guestError } = await sdk.cart.updateCartAddress(
{ id: "01H9CART12345ABCDE" },
{
billing_address: {
first_name: "John",
last_name: "Doe",
email: "[email protected]",
phone: "9876543210",
country_code: "+91",
address_line1: "123 Main Street",
address_line2: "Apt 4B",
city: "Mumbai",
state: "Maharashtra",
pincode: "400001",
country: "India",
landmark: "Near Station",
tax_identification_number: null,
business_name: null
},
shipping_address: {
first_name: "John",
last_name: "Doe",
email: "[email protected]",
phone: "9876543210",
country_code: "+91",
address_line1: "456 Oak Avenue",
address_line2: null,
city: "Pune",
state: "Maharashtra",
pincode: "411001",
country: "India",
landmark: "Near Mall",
tax_identification_number: null,
business_name: null
}
}
);TypeScript Definition
typescript
"create-cart-address": {
parameters: {
query?: never;
header?: {
/** @description A ULID you propose as the `event_id` of the first entry this request returns in `events`. Used only when it is a valid ULID minted within a day of now and not already used; otherwise the server mints one. The `event_id` returned in `events` is the one to send. */
"X-CE-Event-ID"?: components["parameters"]["ProposedEventId"];
};
path: {
/** @description Cart ID */
id: string;
};
cookie?: never;
};
/** @description Update billing and shipping address during checkout */
requestBody: {
content: {
"application/json": {
billing_address_id: string;
shipping_address_id: string;
} | {
billing_address: components["schemas"]["CustomerAddress"];
shipping_address: components["schemas"]["CustomerAddress"];
};
};
};
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
/** @example Address updated successfully */
message: string;
success: boolean;
content: {
cart: components["schemas"]["Cart"];
};
/** @description Analytics events to emit for the change this request made, each with a server-issued `event_id`. Replay them to your analytics destinations so your client-side and server-side copies of the same action dedupe. Empty when the request produced no analytics event. */
events: components["schemas"]["StorefrontResponseEvent"][];
};
};
};
400: components["responses"]["BadRequest"];
401: components["responses"]["Unauthorized"];
404: components["responses"]["NotFound"];
};
};Component References
| Reference | Resolves To |
|---|---|
components["parameters"]["ProposedEventId"] | ProposedEventId |
components["schemas"]["CustomerAddress"] | CustomerAddress |
components["schemas"]["Cart"] | Cart |
components["schemas"]["StorefrontResponseEvent"] | StorefrontResponseEvent |
components["responses"]["BadRequest"] | BadRequest |
components["responses"]["Unauthorized"] | Unauthorized |
components["responses"]["NotFound"] | NotFound |
Parameters
- X-CE-Event-ID (header): A ULID you propose as the
event_idof the first entry this request returns inevents. Used only when it is a valid ULID minted within a day of now and not already used; otherwise the server mints one. Theevent_idreturned ineventsis the one to send.
Request Body
Update billing and shipping address during checkout
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-address",
"summary": "Set cart address",
"description": "Sets billing and shipping addresses on a cart. Returns a fully updated `Cart` object. For registered users, pass `billing_address_id` and `shipping_address_id`. For guest checkout, pass inline `billing_address` and `shipping_address` objects.",
"externalDocs": {
"url": "https://llm-docs.commercengine.io/storefront/operations/create-cart-address",
"description": "API reference for the create-cart-address operation"
},
"parameters": [
{
"$ref": "#/components/parameters/ProposedEventId"
}
],
"requestBody": {
"description": "Update billing and shipping address during checkout",
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"oneOf": [
{
"title": "Registered User",
"description": "For registered users where address is previously added",
"required": [
"billing_address_id",
"shipping_address_id"
],
"properties": {
"billing_address_id": {
"type": "string"
},
"shipping_address_id": {
"type": "string"
}
}
},
{
"title": "Guest User",
"description": "For guest checkout where address is not saved",
"required": [
"billing_address",
"shipping_address"
],
"properties": {
"billing_address": {
"$ref": "#/components/schemas/CustomerAddress"
},
"shipping_address": {
"$ref": "#/components/schemas/CustomerAddress"
}
}
}
]
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"message",
"success",
"content",
"events"
],
"properties": {
"message": {
"type": "string",
"examples": [
"Address updated successfully"
]
},
"success": {
"type": "boolean"
},
"content": {
"properties": {
"cart": {
"$ref": "#/components/schemas/Cart"
}
},
"required": [
"cart"
],
"type": "object"
},
"events": {
"description": "Analytics events to emit for the change this request made, each with a server-issued `event_id`. Replay them to your analytics destinations so your client-side and server-side copies of the same action dedupe. Empty when the request produced no analytics event.",
"type": "array",
"items": {
"$ref": "#/components/schemas/StorefrontResponseEvent"
}
}
}
}
}
},
"links": {
"GetFulfillmentOptions": {
"operationId": "get-fulfillment-options",
"requestBody": {
"cart_id": "$request.path.id"
},
"description": "Check available fulfillment options for this cart."
},
"SetFulfillmentPreference": {
"operationId": "update-fulfillment-preference",
"parameters": {
"id": "$request.path.id"
},
"description": "Set the fulfillment preference on this cart."
},
"CreateOrderFromCart": {
"operationId": "create-order",
"requestBody": {
"cart_id": "$request.path.id"
},
"description": "Create an order from this cart."
}
}
},
"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": "createCartAddress"
}Auto-generated from OpenAPI spec and TypeScript definitions