# Set up a store affiliate program

> For AI agents: the index of these docs is at https://referalli.com/guides/llms.txt (every page it lists has a Markdown version like this one).

Connect a Shopify, WooCommerce or BigCommerce store in one API call: webhooks, tracking script, product catalog and a starter rate card.

If you sell products through Shopify, WooCommerce or BigCommerce, one call connects the store to a program. You use your own store credentials: Referalli has no app keys of its own and never needs a platform app install.

A listed Shopify App Store app (one-click install) would need a Shopify Partner account and Referalli app credentials. That is not available yet, so the steps below use a token you create in your own store.

## 1. Create a token in your store

:::stepper
::step{title="Shopify"}
In the Shopify admin, open **Settings, Apps and sales channels, Develop apps** and create an app. Grant these Admin API scopes: `read_orders`, `read_products` and `write_script_tags`. Install it, then copy the **Admin API access token** (`shpat_…`) and the app's **client secret**, which signs the webhooks.
::
::step{title="WooCommerce"}
In **WooCommerce, Settings, Advanced, REST API** add a key with **Read/Write** permission. Copy the consumer key (`ck_…`) and consumer secret (`cs_…`). The store must be served over `https://`.
::
::step{title="BigCommerce"}
In **Settings, API, Store-level API accounts** create an account with Orders read-only, Products read-only, Content modify and Information and settings read-only. Copy the API token. The store hash is the part of the API path after `stores/`.
::
:::

## 2. Make the call

Create the program first (or use an existing one), then call store setup with an API key:

```bash
curl -X POST https://referalli.com/v1/programs/$PROGRAM_ID/store-setup \
  -H "Authorization: Bearer $REFERALLI_KEY" -H "Content-Type: application/json" \
  -d '{
    "provider": "shopify",
    "shop": "your-store.myshopify.com",
    "credentials": { "accessToken": "shpat_…", "apiSecret": "…" }
  }'
```

For WooCommerce send `"shop": "https://your-store.com"` with `consumerKey` and `consumerSecret`. For BigCommerce send the store hash as `shop` with `apiToken`. Your credentials are used for this call only (BigCommerce's token is kept, sealed, so orders can be read).

The call is safe to repeat. It reuses the connection and webhooks, finds the script already added, refreshes the catalog and never replaces an existing commission rule.

## 3. Read the checklist

The answer lists each step with `ok` and a `detail`. `GET /v1/programs/{id}/store-setup` shows the same list from the current state.

| Step | What it did |
| --- | --- |
| `connection` | Created or reused the store's billing connection for this program. |
| `webhooks` | Registered the order and refund webhooks, so paid orders become commissions and refunds reverse them. |
| `tracking_script` | Added `aff.js` to the storefront (Shopify and BigCommerce). WooCommerce has no script API: the detail gives the one `<script>` line to paste into your theme header. |
| `catalog` | Pulled your products so partners can search them and get product links. |
| `rate_card` | Published a starter rate card as a draft. |

A step with `ok: false` never stops the others. It says what to fix, usually a missing token scope. Fix it and call again.

## 4. Review the rate card

The `general_retail` preset is a **draft**: it accrues nothing and is hidden from partners until you publish it. It pays 8% on apparel and beauty, 5% on home and toys, 4.5% on books, 3% on electronics, 2.5% on computers, 2% on grocery and 4% on any other category, holds commissions 30 days, and excludes gift cards. Items other than the linked product earn no indirect rate.

Edit the rates to fit your margins, then publish them without `draft`:

```bash
curl -X PUT https://referalli.com/v1/programs/$PROGRAM_ID/commission-rule \
  -H "Authorization: Bearer $REFERALLI_KEY" -H "Content-Type: application/json" \
  -d '{ "config": { "base": { "kind": "percent", "bps": 400 }, "holdDays": 30,
        "rateCard": { "rates": { "apparel": 800, "electronics": 300 }, "defaultBps": 400, "exclude": ["gift_cards"] } } }'
```

Pass `"rateCardPreset": "none"` in step 2 to skip the preset. If the program already has a rule, setup leaves it alone. See [commission rules](/guides/02-programs/02-commission-rules) for every field.

---

## For AI agents

- This page for a human reader: https://referalli.com/guides/set-up-a-store-affiliate-program
- The whole space as one Markdown file: https://referalli.com/guides/llms-full.txt
- Live search + fetch over MCP: https://referalli.com/guides/_api/public/orgs/07f432f4-34b9-46a7-aaad-c0e395d2e4f9/spaces/2d18b3a7-6f85-4e83-b889-e1a361196ad4/mcp
  - Install (Claude CLI): `claude mcp add referalli --transport http https://referalli.com/guides/_api/public/orgs/07f432f4-34b9-46a7-aaad-c0e395d2e4f9/spaces/2d18b3a7-6f85-4e83-b889-e1a361196ad4/mcp`

This Markdown is the same content the page renders — safe to quote and to ground answers in.
