Skip to content

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: "john@example.com",
      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: "john@example.com",
      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": {
                    shipping_address_id: string;
                    billing_address_id?: string;
                    shipping_address?: components["schemas"]["CartAddressRequest"];
                    billing_address?: components["schemas"]["CartAddressRequest"];
                } | {
                    shipping_address_id?: string;
                    billing_address_id?: string;
                    shipping_address: components["schemas"]["CartAddressRequest"];
                    billing_address?: components["schemas"]["CartAddressRequest"];
                };
            };
        };
        responses: {
            /** @description OK */
            200: {
                headers: {
                    [name: string]: unknown;
                };
                content: {
                    "application/json": {
                        /** @example Address updated successfully */
                        message: string;
                        success: boolean;
                        content: {
                            cart: components["schemas"]["CartRead"];
                        };
                        /** @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"];
            403: components["responses"]["Forbidden"];
            404: components["responses"]["NotFound"];
            500: components["responses"]["InternalServerError"];
            504: components["responses"]["GatewayTimeout"];
        };
    };

Component References ​

ReferenceResolves To
components["parameters"]["ProposedEventId"]ProposedEventId
components["schemas"]["CartAddressRequest"]CartAddressRequest
components["schemas"]["CartRead"]CartRead
components["schemas"]["StorefrontResponseEvent"]StorefrontResponseEvent
components["responses"]["BadRequest"]BadRequest
components["responses"]["Unauthorized"]Unauthorized
components["responses"]["Forbidden"]Forbidden
components["responses"]["NotFound"]NotFound
components["responses"]["InternalServerError"]InternalServerError
components["responses"]["GatewayTimeout"]GatewayTimeout

Parameters ​

  • X-CE-Event-ID (header): 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.

Request Body ​

Update billing and shipping address during checkout

Content Types: application/json

Responses ​

200 ​

OK

400 ​

Bad request

401 ​

Authentication failed. Codes include token-required, token-expired and token_not_valid for an invalid or expired token.

403 ​

Access denied. token-required requires an authenticated session; permission-denied means the caller cannot access this resource. On POS, session-expired requires signing in again.

404 ​

Requested resource not found

500 ​

The request failed because of an unexpected error.

504 ​

The request timed out.

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": {
          "description": "Provide a shipping address or saved shipping address ID. Billing defaults to shipping; saved IDs and inline addresses can be mixed.",
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "shipping_address_id": {
                  "type": "string"
                },
                "billing_address_id": {
                  "type": "string"
                },
                "shipping_address": {
                  "$ref": "#/components/schemas/CartAddressRequest"
                },
                "billing_address": {
                  "$ref": "#/components/schemas/CartAddressRequest"
                }
              },
              "required": [
                "shipping_address_id"
              ]
            },
            {
              "type": "object",
              "properties": {
                "shipping_address_id": {
                  "type": "string"
                },
                "billing_address_id": {
                  "type": "string"
                },
                "shipping_address": {
                  "$ref": "#/components/schemas/CartAddressRequest"
                },
                "billing_address": {
                  "$ref": "#/components/schemas/CartAddressRequest"
                }
              },
              "required": [
                "shipping_address"
              ]
            }
          ]
        }
      }
    }
  },
  "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/CartRead"
                  }
                },
                "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"
    },
    "403": {
      "$ref": "#/components/responses/Forbidden"
    },
    "404": {
      "$ref": "#/components/responses/NotFound"
    },
    "500": {
      "$ref": "#/components/responses/InternalServerError"
    },
    "504": {
      "$ref": "#/components/responses/GatewayTimeout"
    }
  },
  "security": [
    {
      "Authorization": []
    }
  ],
  "x-speakeasy-group": "carts",
  "x-speakeasy-ignore": false,
  "x-speakeasy-name-override": "createCartAddress"
}

Auto-generated from OpenAPI spec and TypeScript definitions

Last updated: