Build on the Partner API
View as MarkdownManaging the cart
Last updated
This guide is for builders of a website or app on the Partner API.
Groupon keeps a mirror of your shopper's cart, and that mirror is the one that gets paid for. A cart is created together with its first item.
Operations
| Operation | Endpoint | When |
|---|---|---|
| Create cart | POST /partner_storefront/carts | Shopper adds the first item |
| Read cart | GET /partner_storefront/carts/{cartId} | Your cart page loads, or before Buy now after a long idle |
| Add items | POST /partner_storefront/carts/{cartId}/items | Shopper adds another item |
| Change quantity | PATCH /partner_storefront/carts/{cartId}/items/{itemId} | Shopper changes a quantity |
| Remove item | DELETE /partner_storefront/carts/{cartId}/items/{itemId} | Shopper removes a line |
| Abandon cart | DELETE /partner_storefront/carts/{cartId} | Shopper empties the cart, or the session ends |
Every operation except Abandon returns the full cart with a fresh buyLink: overwrite your local
cart with each response. Only an ACTIVE cart carries one: a cart that is CHECKED_OUT or
ABANDONED answers buyLink: null. A cart holds at most 20 different options, and 1 to 100 of each; an option
can set a lower limit of its own. Store the cart id against the shopper's session on your server.
Creating a cart
curl -s -X POST "https://api-staging-core.livingsocial.com/partner_storefront/carts" \
-H "Authorization: Bearer $GROUPON_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"country": "US",
"clientReference": "user-8421",
"items": [{
"productId": "0b6f7a52-3c1d-4e8a-9f20-5d7c1a2b3c4d",
"optionId": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
"quantity": 2,
"expectedPrice": 4500
}]
}'expectedPrice is the per-unit retail price your site shows. When Groupon's live price differs,
the call fails with PRICE_MISMATCH and the live price in details.currentPrice: update your
price, ask the shopper to confirm, and send it again.
clientReference is your own reference for the cart, 1 to 128 characters: your user's id, or your
own order's. It is optional. Every read of the cart answers it back, and so do the order placed from
the cart and your order list, which you can filter by it
(GET /partner_storefront/bookings?clientReference=user-8421), so an order ties to your user without
a table of your own. It stays with LivingSocial for Agents and is never sent to Groupon. An empty or
longer value is refused with BAD_REQUEST.
Reading the response
buyLink: your Buy now button's href, verbatim, from the latest response. Open it in the shopper's browser. Never fetch it from your server and never rewrite it.available: false: the line cannot be bought. ShowunavailableReasonand remove the line before checkout.messages:price_unavailablemeans a line's live price could not be resolved, so the line is left out of the totals.item_declinedmeans Groupon declined an item although the call succeeded: it is not initems, so tell the shopper. When the message carries abookingUrl, the item is bought on that Groupon page instead: send the shopper there.totals.grandTotalexcludes tax and any promo code. The final amount is on Groupon's checkout page.
Retries, and a cart that is gone
- Send an
Idempotency-Keyheader with every add (8 to 200 characters, one per add you mean) and retry with the same key: the same key and items on the same cart, within 24 hours, answer the first answer and never add the items twice. The same key with other items answersIDEMPOTENCY_KEY_REUSED, and a retry while the first add still runsIDEMPOTENCY_KEY_IN_PROGRESS; nothing is added either way. - Without a key, adding items is not idempotent: a line for the same option grows by
quantity. On a timeout, read the cart and add only what is missing. - After you abandon a cart, it reads
ABANDONED, a second abandon answers 200 again, and adding, changing or removing a line answersCART_ABANDONED. Discard itscartId. - Once a cart names an order, it reads
CHECKED_OUTand answersbuyLink: null. Never add to it again. When that order readsREJECTEDorEXPIREDand the shopper is back on your site, create a new cart with the same lines and use itsbuyLink(Checkout and order confirmation). - The cart is gone when one you expect to hold items reads
itemCount: 0, when a change to a line answersINVALID_PRODUCT_ID, or when any call answersINVALID_CART_ID. Create a new cart from your local copy and use itsbuyLink.