# Run your store from code

> Give buyers access from any checkout, pull every sale and customer, and make products with Eden's store API.

Store calls go to `https://api.eden.so/store-app/v1` with a key from **Settings → API** that has
**Full access**, or **Custom** with **Store** on **Edit**. A key with **Store** on **Read** can
only make `GET` calls. Store calls need Starter or above and don't spend credits.

## Give access when someone buys on another site

Selling on a checkout Eden doesn't connect to? Have it call Eden after each sale.

First, get your product's `id`:

```bash
curl https://api.eden.so/store-app/v1/products \
  -H "Authorization: Bearer $EDEN_API_KEY"
```

Then record each sale. Eden gives the buyer access and emails them their link:

```bash
curl https://api.eden.so/store-app/v1/sales \
  -H "Authorization: Bearer $EDEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"event":"sale","product":"<product id>","email":"buyer@example.com","order_id":"1001"}'
```

A good answer is `{ "ok": true, "status": "granted" }`. Send `"event":"refund"` with the same
`order_id` to take access away. The same order sent twice counts once. The product must be
published.

Not sure which store a key reaches? `GET /store-app/v1/me` answers with its `store`. A key works on
one store. If you run more than one, pick it when you make the key.

## Pull every sale, customer, or contact

Each list comes 25 rows at a time, newest first:

```bash
curl "https://api.eden.so/store-app/v1/sales?limit=100" \
  -H "Authorization: Bearer $EDEN_API_KEY"
```

While the answer says `"has_more": true`, ask again with `&starting_after=<next_cursor>`. Swap
`sales` for `customers`, `email-contacts`, or `products`.

## Make a product

```bash
curl -X POST "https://api.eden.so/store-app/v1/products" \
  -H "Authorization: Bearer $EDEN_API_KEY" -H "Content-Type: application/json" \
  -d '{"custom_ai_id":"<id>","title":"Hook Coach","price_cents":2900}'
```

It saves a draft. `GET /store-app/v1/custom-ais` lists the ids you can use. Put it live with
`POST /store-app/v1/products/<id>/publish`.

Memberships, renewals, cancels, filters, and every product field are in the
[Store API reference](https://eden.so/developers/store-reference/). To hear about sales as they happen, add a
[webhook](https://eden.so/developers/webhooks/).

## OpenAPI

The whole store API is in one OpenAPI file for Postman or a code generator:
`https://api.eden.so/store-app/v1/openapi.json`.

## Limits

- **60 sales a minute** and **2,000 new accesses a day**.
- Store calls and webhooks need Starter or above.

## If something's not working

| What you see                   | What to do                                                              |
| ------------------------------ | ----------------------------------------------------------------------- |
| `402`                          | Store calls need Starter or above. Upgrade in **Settings → Billing**.   |
| `403`                          | The key's access doesn't allow that call, or it can't reach that store. |
| `"reason": "product_not_live"` | Publish the product, then send the sale again.                          |
| `429`                          | More than 60 sales a minute. Wait a minute and try again.               |
