STAGINGOpen PROD

Build on the Partner API

View as Markdown

Managing the cart

Last updated

Nobody reads documentation.

Here are the instructions for your agent. Give it this prompt: it reads the guides and the API contract, then walks you through the integration step by step, what to do, where and how.

Download agent instructions

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

OperationEndpointWhen
Create cartPOST /partner_storefront/cartsShopper adds the first item
Read cartGET /partner_storefront/carts/{cartId}Your cart page loads, or before Buy now after a long idle
Add itemsPOST /partner_storefront/carts/{cartId}/itemsShopper adds another item
Change quantityPATCH /partner_storefront/carts/{cartId}/items/{itemId}Shopper changes a quantity
Remove itemDELETE /partner_storefront/carts/{cartId}/items/{itemId}Shopper removes a line
Abandon cartDELETE /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

bash
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. Show unavailableReason and remove the line before checkout.
  • messages: price_unavailable means a line's live price could not be resolved, so the line is left out of the totals. item_declined means Groupon declined an item although the call succeeded: it is not in items, so tell the shopper. When the message carries a bookingUrl, the item is bought on that Groupon page instead: send the shopper there.
  • totals.grandTotal excludes tax and any promo code. The final amount is on Groupon's checkout page.

Retries, and a cart that is gone

  • Send an Idempotency-Key header 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 answers IDEMPOTENCY_KEY_REUSED, and a retry while the first add still runs IDEMPOTENCY_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 answers CART_ABANDONED. Discard its cartId.
  • Once a cart names an order, it reads CHECKED_OUT and answers buyLink: null. Never add to it again. When that order reads REJECTED or EXPIRED and the shopper is back on your site, create a new cart with the same lines and use its buyLink (Checkout and order confirmation).
  • The cart is gone when one you expect to hold items reads itemCount: 0, when a change to a line answers INVALID_PRODUCT_ID, or when any call answers INVALID_CART_ID. Create a new cart from your local copy and use its buyLink.