> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://ecto.crisp.help/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Sync carts from a headless store or mobile app

The Ecto API lets your own server read and update the saved cart of a logged-in customer. It is built for headless storefronts and native mobile apps, whose cart changes Ecto cannot see from your theme.

Ecto never merges two carts. **The most recent version wins**, whether it comes from your theme or from the API. [How Ecto decides which cart to keep](https://ecto.crisp.help/en/article/how-ecto-decides-which-cart-to-keep-n79e9a/) explains this rule in detail.

### How it works

- Your app does a `GET` when it opens, and a `PUT` when the cart changes.
- The next time the customer loads your online store while logged in, on any device, Ecto restores the version saved through the API. The Ecto block must be enabled on your theme.
- When the customer changes their cart on your online store, your next `GET` returns that newer version.

The API only handles carts of **logged-in customers**. The customer must exist in your Shopify store.

The limits are 60 requests per minute per customer and 600 requests per minute per shop. If a customer can change their cart several times in a row, such as tapping "+" on a quantity, group these changes into one `PUT`.

### Authentication

Generate a key in the Ecto app: **API access** card at the bottom of the home page, then **Generate API key**. The key starts with `ecto_sk_` and is shown only once. A shop can have up to 5 active keys, and you can give each one a label to remember what it is for.

Send the key with every request:

```
Authorization: Bearer ecto_sk_your_key
```

**Keep your key on your server.** Never embed it in a mobile app, a website, or any code that runs on a customer's device. Your app talks to your server, and your server talks to Ecto.

**Your server decides which customer the request is for**, based on the customer it has authenticated on its side. Never pass along a customer ID sent by the app as is: anyone could then read or replace another customer's cart.

**If a key leaks or needs replacing**, generate a new one, deploy it on your server, then click **Revoke** on the old one. A revoked key stops working immediately.

A key only ever reaches the carts of the shop it belongs to. If you uninstall Ecto, your keys are revoked.

### Base URL

```
https://app-cross-cart.frb.io
```

All endpoints start with `/v1`. In the paths below, `{id}` is the Shopify customer ID, either numeric (`123456789`) or as a GID (`gid://shopify/Customer/123456789`).

### Read a saved cart

```
GET /v1/customers/{id}/cart
```

A customer with no saved cart returns `200` with an empty cart.

```json
{
  "customer_id": "123456789",
  "lines": [
    {
      "variant_id": "44119131406611",
      "product_id": "8011223344",
      "title": "Classic Tee - Medium",
      "sku": "TEE-M",
      "quantity": 2,
      "properties": [{ "key": "Gift note", "value": "Happy birthday" }]
    }
  ],
  "item_count": 2,
  "updated_at": "2026-11-09T10:15:00Z",
  "cart_token": "Z2NwLWV1cm9wZS13ZXN0MQ"
}
```

The response has no prices. `cart_token` is the token you sent with your last `PUT`. It is `null` if you did not send one, or if the latest version comes from your online store.

### Replace a saved cart

```
PUT /v1/customers/{id}/cart
```

Send the **complete** cart every time. There is no add or remove call: what you send replaces what was saved, and becomes the latest version.

```bash
curl -X PUT "https://app-cross-cart.frb.io/v1/customers/123456789/cart" \
  -H "Authorization: Bearer ecto_sk_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "lines": [
      {
        "variant_id": "gid://shopify/ProductVariant/44119131406611",
        "quantity": 2,
        "properties": [{ "key": "Gift note", "value": "Happy birthday" }]
      }
    ],
    "cart_token": "Z2NwLWV1cm9wZS13ZXN0MQ",
    "client_label": "iOS app",
    "expected_updated_at": "2026-11-09T10:15:00Z"
  }'
```

The response has the same format as `GET`.

| Field | Required | Description |
|---|---|---|
| `lines` | Yes | The full cart, 500 lines at most. Each line has `variant_id` (numeric or GID), `quantity`, and optional `properties`. |
| `lines[].properties` | No | A list of `{ "key", "value" }`, up to 50 per line and 8 KB per line. A key can have up to 255 characters and a value up to 2,000. |
| `cart_token` | No | The token of your Storefront API cart, **without its `?key=` part**. The key is secret: a token that contains it is refused. Sending the token lets Ecto recognize the order placed from this cart. |
| `client_label` | No | Up to 64 characters, such as `iOS app`. Shown in the customer's cart history. |
| `expected_updated_at` | No | The `updated_at` you last read. If the cart was saved since, by your theme or another call, you get a `409` and nothing is written. |

To get `cart_token`, take the ID of your Storefront API cart, `gid://shopify/Cart/<token>?key=<secret>`, and send only `<token>`.

**Prices are never accepted.** Ecto reads each variant's price from Shopify, in your store's currency. Each line must be a variant of your store.

**A `PUT` replaces the whole saved cart.** Besides the lines, it removes the cart attributes and the cart discounts saved from your online store. A bundle read with `GET` comes back as its parent line only, so sending it back drops its components.

Sending an empty `lines` array saves an empty cart. If the Ecto block on your theme has "Doesn't replace cart if new one is empty" turned on, browsers keep their items. To empty the cart everywhere, use `DELETE`.

### Empty a saved cart

```
DELETE /v1/customers/{id}/cart
```

The cart is emptied on every device, even with "Doesn't replace cart if new one is empty" turned on, just like after an order. You can send `expected_updated_at` and `client_label` in the body. The response has the same format as `GET`.

### Errors

Errors are JSON, with a stable `code` and a readable `message`.

```json
{ "code": "unknown_variant", "message": "Some variants do not belong to this shop.", "variant_ids": ["123"] }
```

| Status | Meaning |
|---|---|
| `401` | The key is missing, invalid, or revoked. |
| `403` | The key is not allowed to do this, or the shop is uninstalled or frozen. |
| `409` | `cart_changed`: the cart was saved since `expected_updated_at`. Read it again, then retry. |
| `422` | The request is invalid: `invalid_payload`, `invalid_customer_id`, `invalid_variant_id`, `unknown_customer`, `unknown_variant`, `properties_too_large`, `invalid_cart_token`, or `secret_cart_key` (remove `?key=` from `cart_token`). |
| `429` | `rate_limited`: more than 60 requests per minute for one customer, or 600 for the shop. Wait for the time given in the `Retry-After` header. |
| `503` | `shopify_unavailable`: Shopify could not be reached. Retry a bit later. |

### Orders placed in your app

By default, Ecto only listens to orders from the standard checkout. If your app places orders with another source, **contact our support** so we can set up your order source together. We will ask you for the JSON of a sample order.

Once it is set up, these orders empty the saved cart, count toward your Ecto revenue when the cart travelled between your store and your app, and appear as "App" in **How orders travel**.