Managing Guest Carts
  • 04 Sep 2020
  • 13 Minutes To Read
  • Print
  • Share
  • Dark
    Light

Managing Guest Carts

  • Print
  • Share
  • Dark
    Light

Creating a Guest Cart

Creating a new guest cart for an unauthenticated user implies adding items to a new guest cart. To do that, send the request:


POST /guest-cart-items


Guest cart ID

Guest users have one guest cart by default. If you already have a guest cart, you can optionally specify its ID when adding items. To do that, use the following endpoint. The information in this section is valid for both of the endpoints.

POST /guest-carts/{{guestCartId}}/guest-cart-items

Path Parameter Description
guestCartId Unique identifier of the guest cart in the system. You can get it when retrieving the guest carts.

Request

HEADER KEY HEADER VALUE EXAMPLE REQUIRED DESCRIPTION
X-Anonymous-Customer-Unique-Id 164b-5708-8530 A hyphenated alphanumeric value that is the user's unique identifier.
STRING PARAMETER DESCRIPTION EXEMPLARY VALUES
include Adds resource relationships to the request.
  • concrete-products
  • sales-units
  • cart-rules
Request sample

POST https://glue.mysprykershop.com/guest-cart-items

{
    "data": {
        "type": "guest-cart-items",
        "attributes": {
            "sku": "022_21994751",
            "quantity": 1
        }
    }
}
Request sample with product measurement units and sales units

POST https://glue.mysprykershop.com/guest-cart-items?include=sales-units

{
    "data": {
        "type": "guest-cart-items",
        "attributes": {
            "sku": "cable-vga-1-2",
            "quantity": 3,
            "salesUnit": {
                "id": 33,
                "amount": 4.5
            }
        }
    }
}
ATTRIBUTE* TYPE REQUIRED DESCRIPTION
sku String Specifies the SKU part number of the item to place on the new guest cart. To use promotions, specify the SKU of one of a product being promoted. Concrete product SKU required.
quantity Integer Specifies the number of items to place on the guest cart. If you add a promotional item and the number of products exceeds the number of promotions, the exceeding items will be added without promotional benefits.
salesUnit Object List of attributes defining the sales unit to be used for item amount calculation.
salesUnit.id Integer A unique identifier of the sales units to calculate the item amount in.
salesUnit.amount Decimal Amount of the product in the defined sales units.
Conversion

When defining product amount in sales units, make sure that the correlation between amount and quantity corresponds to the conversion of the defined sales unit. See Measurement Units Feature Overview to learn more.

Response

Response sample
{
    "data": {
        "type": "guest-carts",
        "id": "380e4a19-6faa-5053-89ff-81a1b5a3dd8a",
        "attributes": {
            "priceMode": "GROSS_MODE",
            "currency": "EUR",
            "store": "DE",
            "name": "Shopping cart",
            "isDefault": true,
            "totals": {
                "expenseTotal": 0,
                "discountTotal": 2600,
                "taxTotal": 3736,
                "subtotal": 26000,
                "grandTotal": 23400
            },
            "discounts": [
                {
                    "displayName": "10% Discount for all orders above",
                    "amount": 2600,
                    "code": null
                }
            ]
        },
        "links": {
            "self": "https://glue.mysprykershop.com/guest-carts/380e4a19-6faa-5053-89ff-81a1b5a3dd8a"
        }
    },
    "included": [
        {
            "type": "guest-cart-items",
            "id": "022_21994751",
            "attributes": {
                "sku": "022_21994751",
                "quantity": 1,
                "groupKey": "022_21994751",
                "abstractSku": "022",
                "amount": null,
                "calculations": {
                    "unitPrice": 26000,
                    "sumPrice": 26000,
                    "taxRate": 19,
                    "unitNetPrice": 0,
                    "sumNetPrice": 0,
                    "unitGrossPrice": 26000,
                    "sumGrossPrice": 26000,
                    "unitTaxAmountFullAggregation": 3736,
                    "sumTaxAmountFullAggregation": 3736,
                    "sumSubtotalAggregation": 26000,
                    "unitSubtotalAggregation": 26000,
                    "unitProductOptionPriceAggregation": 0,
                    "sumProductOptionPriceAggregation": 0,
                    "unitDiscountAmountAggregation": 2600,
                    "sumDiscountAmountAggregation": 2600,
                    "unitDiscountAmountFullAggregation": 2600,
                    "sumDiscountAmountFullAggregation": 2600,
                    "unitPriceToPayAggregation": 23400,
                    "sumPriceToPayAggregation": 23400
                },
                "salesUnit": null,
                "selectedProductOptions": []
            },
            "links": {
                "self": "https://glue.mysprykershop.com/guest-carts/380e4a19-6faa-5053-89ff-81a1b5a3dd8a/guest-cart-items/022_21994751"
            }
        }
    ]
}

General Cart Information

Attribute* TYPE DESCRIPTION
priceMode String Price mode that was active when the cart was created.
currency String Currency that was selected when the cart was created.
store String Store for which the cart was created.
name String Name of the shopping cart.
isDefault Boolean Defines whether the cart is default or not.

Totals Information

Attribute* TYPE DESCRIPTION
expenseTotal String Total amount of expenses (including e.g. shipping costs).
discountTotal Integer Total amount of discounts applied to the cart.
taxTotal String Total amount of taxes to be paid.
subTotal Integer Subtotal of the cart.
grandTotal Integer Grand total of the cart.

Discount Information

Attribute* TYPE DESCRIPTION
displayName String Discount name.
code String Discount code applied to the cart.
amount Integer Discount amount applied to the cart.

*Type and ID attributes are not mentioned.

For the details of the included resource, see Guest Cart Items.

Response sample with product measurement units and sales units
{
    "data": {
        "type": "guest-carts",
        "id": "5b598c79-8024-50ec-b682-c0b219387294",
        "attributes": {
            "priceMode": "GROSS_MODE",
            "currency": "EUR",
            "store": "DE",
            "name": "Shopping cart",
            "isDefault": true,
            "totals": {
                "expenseTotal": 0,
                "discountTotal": 0,
                "taxTotal": 1437,
                "subtotal": 9000,
                "grandTotal": 9000
            },
            "discounts": []
        },
        "links": {
            "self": "https://glue.mysprykershop.com/guest-carts/5b598c79-8024-50ec-b682-c0b219387294"
        }
    },
    "included": [
        {
            "type": "product-measurement-units",
            "id": "METR",
            "attributes": {
                "name": "Meter",
                "defaultPrecision": 100
            },
            "links": {
                "self": "https://glue.mysprykershop.com/product-measurement-units/METR"
            }
        },
        {
            "type": "sales-units",
            "id": "33",
            "attributes": {
                "conversion": 1,
                "precision": 100,
                "isDisplayed": true,
                "isDefault": true,
                "productMeasurementUnitCode": "METR"
            },
            "links": {
                "self": "https://glue.mysprykershop.com/concrete-products/cable-vga-1-2/sales-units/33"
            },
            "relationships": {
                "product-measurement-units": {
                    "data": [
                        {
                            "type": "product-measurement-units",
                            "id": "METR"
                        }
                    ]
                }
            }
        },
        {
            "type": "guest-cart-items",
            "id": "cable-vga-1-2_quantity_sales_unit_id_33_amount_1.5_sales_unit_id_33",
            "attributes": {
                "sku": "cable-vga-1-2",
                "quantity": 6,
                "groupKey": "cable-vga-1-2_quantity_sales_unit_id_33_amount_1.5_sales_unit_id_33",
                "abstractSku": "cable-vga-1",
                "amount": "9.0",
                "calculations": {
                    "unitPrice": 1500,
                    "sumPrice": 9000,
                    "taxRate": 19,
                    "unitNetPrice": 0,
                    "sumNetPrice": 0,
                    "unitGrossPrice": 1500,
                    "sumGrossPrice": 9000,
                    "unitTaxAmountFullAggregation": 239,
                    "sumTaxAmountFullAggregation": 1437,
                    "sumSubtotalAggregation": 9000,
                    "unitSubtotalAggregation": 1500,
                    "unitProductOptionPriceAggregation": 0,
                    "sumProductOptionPriceAggregation": 0,
                    "unitDiscountAmountAggregation": 0,
                    "sumDiscountAmountAggregation": 0,
                    "unitDiscountAmountFullAggregation": 0,
                    "sumDiscountAmountFullAggregation": 0,
                    "unitPriceToPayAggregation": 1500,
                    "sumPriceToPayAggregation": 9000
                },
                "salesUnit": {
                    "id": 33,
                    "amount": "9.0"
                },
                "selectedProductOptions": []
            },
            "links": {
                "self": "https://glue.mysprykershop.com/guest-carts/5b598c79-8024-50ec-b682-c0b219387294/guest-cart-items/cable-vga-1-2_quantity_sales_unit_id_33_amount_1.5_sales_unit_id_33"
            },
            "relationships": {
                "sales-units": {
                    "data": [
                        {
                            "type": "sales-units",
                            "id": "33"
                        }
                    ]
                }
            }
        }
    ]
}

For the details of the included resource, see Retrieving Measurement Units.

Response sample: adding a promotional item with the cart-rules relationship
{
    "data": {
        "type": "guest-carts",
        "id": "1ce91011-8d60-59ef-9fe0-4493ef3628b2",
        "attributes": {
            "priceMode": "GROSS_MODE",
            "currency": "EUR",
            "store": "DE",
            "name": "My Cart",
            "isDefault": true,
            "totals": {
                "expenseTotal": 0,
                "discountTotal": 13192,
                "taxTotal": 15107,
                "subtotal": 113207,
                "grandTotal": 100015
            },
            "discounts": [
                {
                    "displayName": "For every purchase above certain value depending on the currency and net/gross price. you get this promotional product for free",
                    "amount": 2079,
                    "code": null
                },
                {
                    "displayName": "10% Discount for all orders above",
                    "amount": 11113,
                    "code": null
                }
            ]
        },
        "links": {
            "self": "https://glue.mysprykershop.com/guest-carts/1ce91011-8d60-59ef-9fe0-4493ef3628b2"
        },
        "relationships": {
            "cart-rules": {
                "data": [
                    {
                        "type": "cart-rules",
                        "id": "6"
                    },
                    {
                        "type": "cart-rules",
                        "id": "1"
                    }
                ]
            }
        }
    },
    "included": [
        {
            "type": "guest-cart-items",
            "id": "134_29759322",
            "attributes": {
                "sku": "134_29759322",
                "quantity": "1",
                "groupKey": "134_29759322",
                "abstractSku": "134",
                "amount": null,
                "calculations": {
                    "unitPrice": 1879,
                    "sumPrice": 1879,
                    "taxRate": 19,
                    "unitNetPrice": 0,
                    "sumNetPrice": 0,
                    "unitGrossPrice": 1879,
                    "sumGrossPrice": 1879,
                    "unitTaxAmountFullAggregation": 270,
                    "sumTaxAmountFullAggregation": 270,
                    "sumSubtotalAggregation": 1879,
                    "unitSubtotalAggregation": 1879,
                    "unitProductOptionPriceAggregation": 0,
                    "sumProductOptionPriceAggregation": 0,
                    "unitDiscountAmountAggregation": 188,
                    "sumDiscountAmountAggregation": 188,
                    "unitDiscountAmountFullAggregation": 188,
                    "sumDiscountAmountFullAggregation": 188,
                    "unitPriceToPayAggregation": 1691,
                    "sumPriceToPayAggregation": 1691
                },
                "salesUnit": null,
                "selectedProductOptions": []
            },
            "links": {
                "self": "https://glue.mysprykershop.com/guest-carts/1ce91011-8d60-59ef-9fe0-4493ef3628b2/guest-cart-items/134_29759322"
            }
        },
        {
            "type": "guest-cart-items",
            "id": "118_29804739",
            "attributes": {
                "sku": "118_29804739",
                "quantity": "1",
                "groupKey": "118_29804739",
                "abstractSku": "118",
                "amount": null,
                "calculations": {
                    "unitPrice": 6000,
                    "sumPrice": 6000,
                    "taxRate": 0,
                    "unitNetPrice": 0,
                    "sumNetPrice": 0,
                    "unitGrossPrice": 6000,
                    "sumGrossPrice": 6000,
                    "unitTaxAmountFullAggregation": 0,
                    "sumTaxAmountFullAggregation": 0,
                    "sumSubtotalAggregation": 6000,
                    "unitSubtotalAggregation": 6000,
                    "unitProductOptionPriceAggregation": 0,
                    "sumProductOptionPriceAggregation": 0,
                    "unitDiscountAmountAggregation": 600,
                    "sumDiscountAmountAggregation": 600,
                    "unitDiscountAmountFullAggregation": 600,
                    "sumDiscountAmountFullAggregation": 600,
                    "unitPriceToPayAggregation": 5400,
                    "sumPriceToPayAggregation": 5400
                },
                "salesUnit": null,
                "selectedProductOptions": []
            },
            "links": {
                "self": "https://glue.mysprykershop.com/guest-carts/1ce91011-8d60-59ef-9fe0-4493ef3628b2/guest-cart-items/118_29804739"
            }
        },
        {
            "type": "guest-cart-items",
            "id": "139_24699831",
            "attributes": {
                "sku": "139_24699831",
                "quantity": "1",
                "groupKey": "139_24699831",
                "abstractSku": "139",
                "amount": null,
                "calculations": {
                    "unitPrice": 3454,
                    "sumPrice": 3454,
                    "taxRate": 19,
                    "unitNetPrice": 0,
                    "sumNetPrice": 0,
                    "unitGrossPrice": 3454,
                    "sumGrossPrice": 3454,
                    "unitTaxAmountFullAggregation": 496,
                    "sumTaxAmountFullAggregation": 496,
                    "sumSubtotalAggregation": 3454,
                    "unitSubtotalAggregation": 3454,
                    "unitProductOptionPriceAggregation": 0,
                    "sumProductOptionPriceAggregation": 0,
                    "unitDiscountAmountAggregation": 345,
                    "sumDiscountAmountAggregation": 345,
                    "unitDiscountAmountFullAggregation": 345,
                    "sumDiscountAmountFullAggregation": 345,
                    "unitPriceToPayAggregation": 3109,
                    "sumPriceToPayAggregation": 3109
                },
                "salesUnit": null,
                "selectedProductOptions": []
            },
            "links": {
                "self": "https://glue.mysprykershop.com/guest-carts/1ce91011-8d60-59ef-9fe0-4493ef3628b2/guest-cart-items/139_24699831"
            }
        },
        {
            "type": "guest-cart-items",
            "id": "136_24425591",
            "attributes": {
                "sku": "136_24425591",
                "quantity": 3,
                "groupKey": "136_24425591",
                "abstractSku": "136",
                "amount": null,
                "calculations": {
                    "unitPrice": 33265,
                    "sumPrice": 99795,
                    "taxRate": 19,
                    "unitNetPrice": 0,
                    "sumNetPrice": 0,
                    "unitGrossPrice": 33265,
                    "sumGrossPrice": 99795,
                    "unitTaxAmountFullAggregation": 4780,
                    "sumTaxAmountFullAggregation": 14341,
                    "sumSubtotalAggregation": 99795,
                    "unitSubtotalAggregation": 33265,
                    "unitProductOptionPriceAggregation": 0,
                    "sumProductOptionPriceAggregation": 0,
                    "unitDiscountAmountAggregation": 3327,
                    "sumDiscountAmountAggregation": 9980,
                    "unitDiscountAmountFullAggregation": 3327,
                    "sumDiscountAmountFullAggregation": 9980,
                    "unitPriceToPayAggregation": 29938,
                    "sumPriceToPayAggregation": 89815
                },
                "salesUnit": null,
                "selectedProductOptions": []
            },
            "links": {
                "self": "https://glue.mysprykershop.com/guest-carts/1ce91011-8d60-59ef-9fe0-4493ef3628b2/guest-cart-items/136_24425591"
            }
        },
        {
            "type": "guest-cart-items",
            "id": "112_306918001-promotion-1",
            "attributes": {
                "sku": "112_306918001",
                "quantity": "1",
                "groupKey": "112_306918001-promotion-1",
                "abstractSku": "112",
                "amount": null,
                "calculations": {
                    "unitPrice": 2079,
                    "sumPrice": 2079,
                    "taxRate": 0,
                    "unitNetPrice": 0,
                    "sumNetPrice": 0,
                    "unitGrossPrice": 2079,
                    "sumGrossPrice": 2079,
                    "unitTaxAmountFullAggregation": 0,
                    "sumTaxAmountFullAggregation": 0,
                    "sumSubtotalAggregation": 2079,
                    "unitSubtotalAggregation": 2079,
                    "unitProductOptionPriceAggregation": 0,
                    "sumProductOptionPriceAggregation": 0,
                    "unitDiscountAmountAggregation": 2079,
                    "sumDiscountAmountAggregation": 2079,
                    "unitDiscountAmountFullAggregation": 2079,
                    "sumDiscountAmountFullAggregation": 2079,
                    "unitPriceToPayAggregation": 0,
                    "sumPriceToPayAggregation": 0
                },
                "salesUnit": null,
                "selectedProductOptions": []
            },
            "links": {
                "self": "https://glue.mysprykershop.com/guest-carts/1ce91011-8d60-59ef-9fe0-4493ef3628b2/guest-cart-items/112_306918001-promotion-1"
            }
        },
        {
            "type": "cart-rules",
            "id": "6",
            "attributes": {
                "amount": 2079,
                "code": null,
                "discountType": "cart_rule",
                "displayName": "For every purchase above certain value depending on the currency and net/gross price. you get this promotional product for free",
                "isExclusive": false,
                "expirationDateTime": "2020-12-31 00:00:00.000000",
                "discountPromotionAbstractSku": "112",
                "discountPromotionQuantity": 2
            },
            "links": {
                "self": "https://glue.mysprykershop.com/cart-rules/6"
            }
        },
        {
            "type": "cart-rules",
            "id": "1",
            "attributes": {
                "amount": 11113,
                "code": null,
                "discountType": "cart_rule",
                "displayName": "10% Discount for all orders above",
                "isExclusive": false,
                "expirationDateTime": "2020-12-31 00:00:00.000000",
                "discountPromotionAbstractSku": null,
                "discountPromotionQuantity": null
            },
            "links": {
                "self": "https://glue.mysprykershop.com/cart-rules/1"
            }
        }
    ]
}

For the attributes of the included resources, see Viewing discounts applied to a purchase.

Retrieving a Guest Cart

To retrieve a guest cart with a guest user ID, send the request:


GET /guest-carts


Guest cart ID

Guest users have one guest cart by default. If you already have a guest cart, you can optionally specify its ID when adding items. To do that, use the following endpoint. The information in this section is valid for both of the endpoints.

GET /guest-carts/{{guestCartId}}

Path Parameter Description
guestCartId Unique identifier of the guest cart in the system. You can get it when retrieving the guest carts.
Note

When retrieving the cart with guestCartId, the response includes a single object, and when retrieving the resource without specifying it, you get an array containing a single object.

Request

HEADER KEY HEADER VALUE EXAMPLE REQUIRED DESCRIPTION
X-Anonymous-Customer-Unique-Id 164b-5708-8530 A hyphenated alphanumeric value that is the user's unique identifier. It is passed in the X-Anonymous-Customer-Unique-Id header when creating a guest cart.
STRING PARAMETER DESCRIPTION EXEMPLARY VALUES
include Adds resource relationships to the request.
  • guest-cart-items
  • cart-rules
  • promotional-items
  • gift-cards
  • vouchers
Request Usage
GET https://glue.mysprykershop.com/guest-carts Retrieve a guest cart.
GET https://glue.mysprykershop.com/guest-carts?include=guest-cart-items Retrieve information about a guest cart with the concrete products included.
GET https://glue.mysprykershop.com/guest-carts?include=cart-rules Retrieve a guest cart with information about the cart rules.
GET https://glue.mysprykershop.com/guest-carts?include=gift-cards,vouchers Retrieve a guest cart with information about the gift cards applied.

Response

Response sample
{
    "data": [
        {
            "type": "guest-carts",
            "id": "f8782b6c-848d-595e-b3f7-57374f1ff6d7",
            "attributes": {
                "priceMode": "GROSS_MODE",
                "currency": "EUR",
                "store": "DE",
                "name": "Shopping cart",
                "isDefault": true,
                "totals": {
                    "expenseTotal": 0,
                    "discountTotal": 10689,
                    "taxTotal": 15360,
                    "subtotal": 106892,
                    "grandTotal": 96203,
                    "priceToPay": 93203
                },
                "discounts": [
                    {
                        "displayName": "10% Discount for all orders above",
                        "amount": 10689,
                        "code": null
                    }
                ]
            },
            "links": {
                "self": "https://glue.mysprykershop.com/guest-carts/f8782b6c-848d-595e-b3f7-57374f1ff6d7"
            }
        }
    ],
    "links": {
        "self": "https://glue.mysprykershop.com/cart-codes"
    }
}

General Cart Information

Attribute* TYPE DESCRIPTION
priceMode String Price mode that was active when the cart was created.
currency String Currency that was selected when the cart was created.
store String Store for which the cart was created.
name String Name of the shopping cart.
isDefault Boolean Defines whether the cart is default or not.

Totals Information

Attribute* TYPE DESCRIPTION
expenseTotal String Total amount of expenses (including e.g. shipping costs).
discountTotal Integer Total amount of discounts applied to the cart.
taxTotal String Total amount of taxes to be paid.
subTotal Integer Subtotal of the cart.
grandTotal Integer Grand total of the cart.

Discount Information

Attribute* TYPE DESCRIPTION
displayName String Discount name.
code String Discount code applied to the cart.
amount Integer Discount amount applied to the cart.

*Type and ID attributes are not mentioned.

Response sample with guest cart items
{
    "data": [
        {
            "type": "guest-carts",
            "id": "f8782b6c-848d-595e-b3f7-57374f1ff6d7",
            "attributes": {
                "priceMode": "GROSS_MODE",
                "currency": "EUR",
                "store": "DE",
                "name": "Shopping cart",
                "isDefault": true,
                "totals": {
                    "expenseTotal": 0,
                    "discountTotal": 10689,
                    "taxTotal": 15360,
                    "subtotal": 106892,
                    "grandTotal": 96203,
                    "priceToPay": 96203
                },
                "discounts": [
                    {
                        "displayName": "10% Discount for all orders above",
                        "amount": 10689,
                        "code": null
                    }
                ]
            },
            "links": {
                "self": "https://glue.mysprykershop.com/guest-carts/f8782b6c-848d-595e-b3f7-57374f1ff6d7"
            },
            "relationships": {
                "guest-cart-items": {
                    "data": [
                        {
                            "type": "guest-cart-items",
                            "id": "023_21758366"
                        }
                    ]
                }
            }
        }
    ],
    "links": {
        "self": "https://glue.mysprykershop.com/cart-codes?include=guest-cart-items"
    },
    "included": [
        {
            "type": "guest-cart-items",
            "id": "023_21758366",
            "attributes": {
                "sku": "023_21758366",
                "quantity": "4",
                "groupKey": "023_21758366",
                "abstractSku": "023",
                "amount": null,
                "productOfferReference": null,
                "merchantReference": null,
                "calculations": {
                    "unitPrice": 26723,
                    "sumPrice": 106892,
                    "taxRate": 19,
                    "unitNetPrice": 0,
                    "sumNetPrice": 0,
                    "unitGrossPrice": 26723,
                    "sumGrossPrice": 106892,
                    "unitTaxAmountFullAggregation": 3840,
                    "sumTaxAmountFullAggregation": 15360,
                    "sumSubtotalAggregation": 106892,
                    "unitSubtotalAggregation": 26723,
                    "unitProductOptionPriceAggregation": 0,
                    "sumProductOptionPriceAggregation": 0,
                    "unitDiscountAmountAggregation": 2672,
                    "sumDiscountAmountAggregation": 10689,
                    "unitDiscountAmountFullAggregation": 2672,
                    "sumDiscountAmountFullAggregation": 10689,
                    "unitPriceToPayAggregation": 24051,
                    "sumPriceToPayAggregation": 96203
                },
                "salesUnit": null,
                "selectedProductOptions": []
            },
            "links": {
                "self": "https://glue.mysprykershop.com/guest-carts/f8782b6c-848d-595e-b3f7-57374f1ff6d7/guest-cart-items/023_21758366"
            }
        }
    ]
}

For the attributes of the included resources, see Managing Guest Cart Items.

Response sample with cart rules
{
    "data": [
        {
            "type": "guest-carts",
            "id": "f8782b6c-848d-595e-b3f7-57374f1ff6d7",
            "attributes": {
                "priceMode": "GROSS_MODE",
                "currency": "EUR",
                "store": "DE",
                "name": "Shopping cart",
                "isDefault": true,
                "totals": {
                    "expenseTotal": 0,
                    "discountTotal": 10689,
                    "taxTotal": 15360,
                    "subtotal": 106892,
                    "grandTotal": 96203,
                    "priceToPay": 96203
                },
                "discounts": [
                    {
                        "displayName": "10% Discount for all orders above",
                        "amount": 10689,
                        "code": null
                    }
                ]
            },
            "links": {
                "self": "https://glue.mysprykershop.com/guest-carts/f8782b6c-848d-595e-b3f7-57374f1ff6d7"
            },
            "relationships": {
                "cart-rules": {
                    "data": [
                        {
                            "type": "cart-rules",
                            "id": "1"
                        }
                    ]
                }
            }
        }
    ],
    "links": {
        "self": "https://glue.mysprykershop.com/cart-codes?include=cart-rules"
    },
    "included": [
        {
            "type": "cart-rules",
            "id": "1",
            "attributes": {
                "amount": 10689,
                "code": null,
                "discountType": "cart_rule",
                "displayName": "10% Discount for all orders above",
                "isExclusive": false,
                "expirationDateTime": "2020-12-31 00:00:00.000000",
                "discountPromotionAbstractSku": null,
                "discountPromotionQuantity": null
            },
            "links": {
                "self": "https://glue.mysprykershop.com/cart-rules/1"
            }
        }
    ]
}

For the attributes of the included resources, see Adding Items to Guest Carts.

Response sample with gift cards
{
    "data": [
        {
            "type": "guest-carts",
            "id": "f8782b6c-848d-595e-b3f7-57374f1ff6d7",
            "attributes": {
                "priceMode": "GROSS_MODE",
                "currency": "EUR",
                "store": "DE",
                "name": "Shopping cart",
                "isDefault": true,
                "totals": {
                    "expenseTotal": 0,
                    "discountTotal": 10689,
                    "taxTotal": 15360,
                    "subtotal": 106892,
                    "grandTotal": 96203,
                    "priceToPay": 93203
                },
                "discounts": [
                    {
                        "displayName": "10% Discount for all orders above",
                        "amount": 10689,
                        "code": null
                    }
                ]
            },
            "links": {
                "self": "https://glue.mysprykershop.com/guest-carts/f8782b6c-848d-595e-b3f7-57374f1ff6d7"
            },
            "relationships": {
                "gift-cards": {
                    "data": [
                        {
                            "type": "gift-cards",
                            "id": "GC-Z9FYJRK3-20"
                        }
                    ]
                }
            }
        }
    ],
    "links": {
        "self": "https://glue.mysprykershop.com/cart-codes?include=gift-cards"
    },
    "included": [
        {
            "type": "gift-cards",
            "id": "GC-Z9FYJRK3-20",
            "attributes": {
                "code": "GC-Z9FYJRK3-20",
                "name": "Gift Card 30",
                "value": 3000,
                "currencyIsoCode": "EUR",
                "actualValue": 3000,
                "isActive": true
            },
            "links": {
                "self": "https://glue.mysprykershop.com/guest-carts/f8782b6c-848d-595e-b3f7-57374f1ff6d7/cart-codes/GC-Z9FYJRK3-20"
            }
        }
    ]
}

For the attributes of the included resources, see Gift Cards of Guest Users.

Assign a Guest Cart to a Registered Customer

Guest carts are anonymous as they are not related to any user. If a user registers or logs in, the guest cart is automatically assigned to their account.

To assign a guest cart to a customer, i.e. merge the carts, include the unique identifier associated with the customer in the X-Anonymous-Customer-Unique-Id header of the authentication request if it is an existing customer, or request to create a customer account if it is a new one.

Upon login, the behavior depends on whether your project is a single cart or multiple cart environment:

  • In a single cart environment, the products in the guest cart are added to the customers' own cart;
  • In a multiple cart environment, the guest cart is converted to a regular user cart and added to the list of the customers' own carts.

The workflow is displayed in the diagram below:
Assign cart

Below, you can see an exemplary workflow for converting a guest cart into a regular cart:

  1. The customer adds items to a guest cart.

Request sample: POST https://glue.myspsrykershop.com/guest-cart-items

{
    "data": {
        "type": "guest-cart-items",
        "attributes": {
            "sku": "022_21994751",
            "quantity": 5
        }
    }
}
HEADER KEY HEADER VALUE DESCRIPTION
X-Anonymous-Customer-Unique-Id guest-user-001 A hyphenated alphanumeric value that is the user's unique identifier.

Response sample

{
    "data": {
        "type": "guest-carts",
        "id": "9183f604-9b2c-53d9-acbf-cf59b9b2ff9f",
        "attributes": {...},
        "links": {...}
    },
    "included": [...]
}
  1. The customer logs in.

Request sample: POST https://glue.myspsrykershop.com/access-tokens

{
    "data": {
        "type": "access-tokens",
        "attributes": {
            "username": "[email protected]",
            "password": "qwerty"
        }
    }
}
HEADER KEY HEADER VALUE DESCRIPTION
X-Anonymous-Customer-Unique-Id guest-user-001 A hyphenated alphanumeric value that is the user's unique identifier.

Response sample

{
    "data": {
        "type": "access-tokens",
        "id": null,
        "attributes": {
            "tokenType": "Bearer",
            "expiresIn": 28800,
            "accessToken": "eyJ0eXAiOiJKV1QiLC...",
            "refreshToken": "def50200ae2d0...",
            "idCompanyUser": "94d58692-c117-5466-8b9f-2ba32dd87c43"
        },
        "links": {...}
    }
}
  1. The customer requests a list of his own carts.

Request sample: GET https://glue.myspsrykershop.com/carts

HEADER KEY HEADER VALUE DESCRIPTION
Authorization Bearer eyJ0eXAiOiJKV1QiLC... Authorization token. See Authentication and Authorization for more details about authorization.

In the multi-cart environment, the guest cart has been converted to a regular cart. You can see it in the list of carts with the id 9183f604-9b2c-53d9-acbf-cf59b9b2ff9f.

Response sample

{
    "data": [
        {
            "type": "carts",
            "id": "1ce91011-8d60-59ef-9fe0-4493ef3628b2",
            "attributes": {...},
            "links": {...}
        },
        {
            "type": "carts",
            "id": "9183f604-9b2c-53d9-acbf-cf59b9b2ff9f",
            "attributes": {...},
            "links": {...}
        }
    ],
    "links": {...}
}

In a single cart environment, items from the guest cart have been added to the user's own cart.

Response body

{
    "data": [
        {
            "type": "carts",
            "id": "1ce91011-8d60-59ef-9fe0-4493ef3628b2",
            "attributes": {
                "priceMode": "GROSS_MODE",
                "currency": "EUR",
                "store": "DE",
                "isDefault": true,
                "totals": {
                    "expenseTotal": 0,
                    "discountTotal": 13000,
                    "taxTotal": 18681,
                    "subtotal": 130000,
                    "grandTotal": 117000
                },
                "discounts": [...]
            },
            "links": {...}
        },

Possible Errors

Code Reason
101 Cart with given uuid not found.
102 Failed to add an item to cart.
103 Item with the given group key not found in the cart.
104 Cart uuid is missing.
105 Cart could not be deleted.
106 Cart item could not be deleted.
107 Failed to create cart.
109 Anonymous customer unique id is empty.
111 Can’t switch price mode when there are items in the cart.
112 Store data is invalid.
113 Cart item could not be added.
114 Cart item could not be updated.
115 Unauthorized cart action.
116 Currency is missing.
117 Currency is incorrect.
118 Price mode is missing.
119 Price mode is incorrect.
Was This Article Helpful?