Merge a guest cart into the signed-in shopper's cart
const url = 'https://apibase.ecomweb.app/api/v1/stores/example/cart/merge';const options = { method: 'POST', headers: { 'x-storefront-api-key': '<x-storefront-api-key>', Authorization: 'Bearer <token>' }};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://apibase.ecomweb.app/api/v1/stores/example/cart/merge \ --header 'Authorization: Bearer <token>' \ --header 'x-storefront-api-key: <x-storefront-api-key>'Call this right after a visitor signs in, with the x-session-id they used for the guest cart. The guest cart’s lines are added to the shopper’s cart, summing quantities for the same product and variant, and the guest cart is retired. When the shopper has no cart, the guest cart becomes theirs. Without the header, or when the guest cart is gone, the shopper’s existing cart is returned as it is; when there is no cart at all the response is { "merged": false }. The cart returned here carries stored lines without prices: read the cart for priced lines.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”The store’s ref, as returned by GET /stores.
Header Parameters
Section titled “Header Parameters”The guest session ID the visitor used with the guest cart routes.
Responses
Section titled “Responses”The shopper’s cart after the merge, or { "merged": false } when there is nothing to merge.
object
Cart status.
The cart’s lines.
object
Cart line ID.
ID of the cart the line belongs to.
ID of the product.
ID of the variant, or null when the line has none.
Units in the line.
When the line was added, as an ISO 8601 timestamp.
When the line last changed, as an ISO 8601 timestamp.
Cart ID.
ID of the signed-in shopper who owns the cart, or null for a guest cart.
The guest session ID that owns the cart, or null once a shopper owns it.
When the cart expires, as an ISO 8601 timestamp, or null when it does not.
When the cart was created, as an ISO 8601 timestamp.
When the cart last changed, as an ISO 8601 timestamp.
object
Always false: the shopper has no cart and sent no guest cart to merge.
Example
{ "status": "ACTIVE"}The key is missing, invalid, revoked or expired.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}The key may not do this: a missing scope, a readonly key, a publishable key on a Store API route, or a disallowed origin.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}