# Developer Integration API Reference

> Connect a custom storefront or an app to Refermate: the capture script, the server postback API for orders, refunds, and subscriptions, the app install events API, response codes, and how to verify tracking.

- Canonical URL: https://partners.refermate.com/developers
- Base URL: https://partners.refermate.com

## Start here

### Shopify or Stripe

Use Partners to connect your brand, choose rewards and manage creators. The Shopify and Stripe connections handle their supported purchase tracking; you do not need custom order postbacks for that setup.

[Open Partners](https://partners.refermate.com/dashboard)

### Work with your assistant

Connect your assistant through Partners MCP to manage supported setup, catalog, app and reward operations. Sign in with Refermate, approve access for the right brand, and confirm changes.

[Connect with MCP](https://partners.refermate.com/developers/partners-mcp)

### Connect your backend

Use the server APIs in this reference when your own system reports purchases, refunds, renewals, app installs or activations. Custom catalog imports can also come from your server. Keep these integration keys on your backend.

[Read API authentication](https://partners.refermate.com/developers/authentication)

## Connect your assistant with MCP

Connect your assistant to set up or manage your store. It handles the workflow and asks for your approval when needed.

Production endpoint: `https://mcp.refermate.com/merchant`

Copy these instructions into your assistant. It will check your store's progress and guide the next step.

You'll be asked to:

- Sign in with your Refermate account.
- Confirm which store your assistant should work on.
- Approve the access, provider connections and changes it requests.

These instructions connect to production. For development or staging, copy the instructions from Set up with your agent in Add a store there.

### Connection instructions

```text
Connect your coding assistant to Refermate Partners
Add this remote MCP server in your assistant: https://mcp.refermate.com/merchant
Use OAuth sign-in as the store owner. Do not use the shopper /api/mcp endpoint, ask for account passwords, paste tokens into chat, or treat identity sign-in as store approval.
Start with merchant_onboard_store action identify, following nextCursor as afterId when needed. Match an owned store to this project; never select the first result automatically. For a new store, infer its identity and checkout platform from the authorized project, confirm them with the owner, and ask only for missing facts. A public URL does not prove ownership.
For a new custom storefront, use createStore with its confirmed name and primaryDomain. For Shopify, use installShopify with the permanent shopDomain. For Stripe, use installStripe, then resumeStripe after the native approval; saveStripeIdentity and verifyStripeDomain continue its confirmed identity and public domain proof. These are actions of merchant_onboard_store. Follow the host's confirmation and the tool's nextAction. If confirmation is unsupported or owner_setup_required is returned, continue at its ownerSetupUrl.
Provider installation and Refermate account linking need the human owner's approval. Never handle provider passwords, connect tokens or private credentials in chat. Store creation or provider approval does not grant access to the resulting store.
For an existing or newly created store, use its current matching grant if it permits the next action. Otherwise call merchant_request_access for that advertiserId with only the setup operations needed. Give the returned consentUrl to the human owner. Never approve it yourself. Keep the returned grantId tied to that advertiserId; never upgrade another grant or request unrelated permissions.
Poll merchant_access_status with grantId no faster than every five seconds. Continue only when approved. For denied, expired, revoked, invalidated, or unavailable access, stop and ask the owner; never bypass consent or silently retry permissions.
Use merchant_onboard_store readStatus with advertiserId and a read_onboarding grant to resume store setup. prepareDomain uses prepare_integration to return the homepage tag and the DNS record that prove the domain; verifyDomain uses verify_integration to check the one published, with method homepage or dns. installExistingStripe uses submit_integration to begin native Stripe approval for the selected existing store. Use merchant_read_onboarding and merchant_prepare_integration for tracking status and backend instructions. Follow owner_setup_required or platform_managed handoffs. An installed connector or verified domain alone does not prove attribution or commercial readiness.
For custom backend postbacks, keep the first accepted customer_id and discount_code on every retry of a new conversion, including when they were omitted. Both values are trimmed for the retry fingerprint. Adding, changing or removing either, including code case, returns 409 duplicate_order_conflict and never changes its payee. Item refunds require a unique line_id on every original conversion line, 1 to 255 characters after trimming; empty or oversized IDs, mixed presence or duplicates return 400 invalid_payload. Amounts cover the whole line. Send cumulative refund_lines with refund_basis=line_items_v1; do not mix item and proportional partial-refund histories on one order, or it returns 422 unsupported_reversal_type. Both modes obey the frozen refund hold and collection finality. An amount-only full reversal remains available after the hold, before collection. For recurring relationships an unknown code does not replace a valid click_id; an unknown code without a click returns 404 unknown_referral_code. These are authenticated backend events, never MCP actions or a reason to expose the postback secret.
The owner handles billing and credential provisioning in Partners. A program activates only with at least one commission rule (readStatus reports commission_rules_missing until it has one): ask the owner what creators earn and set it with merchant_update_program commissionRules under a manage_commissions grant, which the owner confirms. Program activation, which accepts the commercial terms, needs the owner's confirmation: in Partners, or through merchant_update_program under a manage_program_lifecycle grant. Keep the postback secret in the merchant backend environment; never retrieve or share it through MCP or chat.
Only when the owner chooses a custom attribution test, use an approved verify_integration grant with merchant_start_verification. Carry its private test link through checkout, then let the backend send the authenticated test:true postback. Successful proof can enable serving for an already configured program. Do not run this test solely to check the MCP connection or domain proof.
After the backend test postback, poll merchant_read_onboarding for trackingStatus no faster than every five seconds and for at most two minutes. Stop on verified status, failed postback, degraded status, access denial or timeout. Report the actual result; never repeat a paid order or create more test links just to keep polling.
Keep an ongoing connection active unless the owner asks to revoke it. The owner manages store permissions in Partners Connected apps and can revoke temporary access when finished. If your assistant cannot connect to remote OAuth MCP, use the existing Partners setup continuation. Do not bypass authentication.
```

## How it works

1. You verify your storefront domain once, with a tag on your homepage or a TXT record in your DNS, and Refermate checks for it. Only then can you create the integration.
2. A creator shares a Refermate link. Refermate records the click and sends the shopper to your site with an `rm_click` query parameter.
3. The capture script stores that value in a first-party cookie on your site.
4. At checkout you save the click ID with the order.
5. When the order is paid, your server posts it to Refermate. Money moves only on these server postbacks, never on browser events.
6. Each conversion approves automatically when its refund hold ends, unless it was refunded, disputed, or rejected; you can approve or reject it in Partners sooner. Refermate then bills your saved payment method and pays the creator.

## Capture script

Add this to the `<head>` of every page a creator link can land on.

```html
<script src="https://partners.refermate.com/api/pn/sdk/v1.js" data-rm-consent-mode="explicit" data-rm-max-age-days="30" defer></script>
```

- Without a consent attribute, the script assumes your consent manager loaded it after consent. With `data-rm-consent-mode="explicit"`, it stores and reads nothing until you call `window.RefermateCapture.grantConsent()`, and that holds on every page: call it on each page load once the shopper has accepted, including checkout, or `getClick()` returns null. The click is captured only on the landing page, so it is lost if consent arrives after the shopper leaves it.
- A consent manager can decide before the deferred script loads. Keep the decision and call `grantConsent()` once `window.RefermateCapture` exists, for example from the script tag's `load` event.
- Save the complete result of `window.RefermateCapture.checkoutMetadata()` with the order: `rm_click` becomes `click_id` and `rm_soft_click` becomes `soft_click_id` in the paid-order postback. Send either or both when present. `getClick()` returns only the currently preferred click; keeping both lets Refermate apply the attribution window at payment time. Include an applied referral code as `discount_code`, even when there is no click.
- The cookie is `_refermate_click`, host-only and `SameSite=Lax`. `data-rm-max-age-days` asks for 1 to 365 days (default 30), and a landing's `rm_exp` cuts it to what is left of that click's attribution window. Browsers can expire it sooner: Safari keeps cookies set by scripts for at most 7 days. The last click wins.
- If your router rewrites the URL before deferred scripts run, drop `defer`.

## Authentication

Send your secret postback key as `Authorization: Bearer <key>` (or `X-Refermate-Postback-Key`). Bodies are JSON, up to 16 KiB. Call these endpoints only from your server; the key must never reach a browser.

## Endpoints

### POST /api/partner-network/postbacks/<public-tracking-key>/conversions

Report a paid one-time order that carries a Refermate click or a referrer's code. With a click, a code on the same order wins when it names another referrer. Without a click, the code alone attributes the order (codes only). An order with neither is rejected with 422 `missing_referral_click`, and a code that names no referrer of your program with 422 `unknown_referral_code`. A free order, whose `eligible_amount_cents` is 0, earns nobody anything: it answers 200 `zero_amount`, records nothing, and uses up no click or code.

| Field | Required | Description |
| --- | --- | --- |
| `order_id` | Yes | Your stable order ID, up to 500 characters. It is the idempotency key: resending the same order is safe. |
| `click_id` | No | The `rm_click` value the capture script stored for this shopper. Send it, `discount_code`, or both. |
| `soft_click_id` | No | The `rm_soft_click` value, when the capture script also stored one (the Refermate extension activating at your store). `checkoutMetadata()` returns both. Refermate credits it only when the `click_id` click's attribution window has ended; sent alone, it is the order's click. |
| `currency` | Yes | Three-letter currency code. Only `USD` is accepted. |
| `order_subtotal_cents` | Yes | Paid merchandise subtotal after discounts, excluding tax and shipping, in cents as a whole number of 0 or more. Use the same basis for cumulative refunds. |
| `occurred_at` | Yes | When it happened, in ISO 8601 with an explicit offset (`Z` or `±HH:MM`), for example `2026-09-28T17:05:00.000Z`. Any number of fractional digits is accepted; Refermate keeps milliseconds and drops the rest. JavaScript `toISOString()`, .NET `"o"`, Java `Instant.toString()`, and Python `isoformat()` on a timezone-aware datetime all qualify. A time without an offset is rejected. |
| `eligible_amount_cents` | No | The commissionable part of the subtotal, after discounts and without shipping or tax. Defaults to the subtotal and cannot exceed it. When it is 0 the order is not commissionable (`zero_amount`). |
| `line_items` | No | `[{ product_id, amount_minor_units, quantity, line_id }]`, summing to the eligible amount. Each amount covers the whole line, not one unit. Required when the program pays per product. A stable `line_id` on every line opts the conversion into item-refund support; otherwise omit it from every line. Line IDs are immutable on retries. |
| `line_items[].line_id` | No | An order-line ID, not a product ID. When supplied, it must be 1 to 255 characters after trimming, present on every line and unique within the order, including repeated products. Empty or oversized IDs, mixed presence or duplicate IDs return 400 `invalid_payload`. Use these same IDs in `refund_lines` for item refunds. |
| `order_name` | No | A customer-facing order number. |
| `customer_id` | No | Your stable customer ID. New conversions fingerprint the trimmed customer ID and `discount_code`. The first accepted values, including omitted values, stand: adding, changing or removing either on the same order returns 409 `duplicate_order_conflict` and never changes the original payee. |
| `discount_code` | No | The referral code used on the order: a referrer's creator code, or the token of their referral link (`/r/<token>`). Refermate looks for a creator code first, then a link token. Any other discount code is ignored for attribution when the order has a click. New conversions still include the submitted, trimmed code in the retry fingerprint, even if it did not select the payee. Keep the first accepted value on retries, including its absence. Adding, changing or removing the normalized code, including a change in case, returns 409 `duplicate_order_conflict`. |
| `metadata` | No | An object of your own data, up to 4 KiB. |
| `test` | No | `true` only for a verification order: with the `rmv_` click of your test link, or, for codes only, with your integration's test code (`RMTEST-…`) as `discount_code`. |

A paid order:

```json
{
  "click_id": "a1B2c3D4e5F6g7H8",
  "currency": "USD",
  "eligible_amount_cents": 10000,
  "line_items": [
    {
      "product_id": "SKU-1001",
      "line_id": "order-line-1",
      "amount_minor_units": 3000,
      "quantity": 2
    },
    {
      "product_id": "SKU-1002",
      "line_id": "order-line-2",
      "amount_minor_units": 7000,
      "quantity": 1
    }
  ],
  "occurred_at": "2026-09-28T17:05:00.000Z",
  "order_id": "ORDER-1001",
  "order_name": "#1001",
  "order_subtotal_cents": 10000
}
```

A paid order with a referral code and no click:

```json
{
  "currency": "USD",
  "discount_code": "JANE10",
  "occurred_at": "2026-09-28T17:05:00.000Z",
  "order_id": "ORDER-1002",
  "order_subtotal_cents": 10000
}
```

### POST /api/partner-network/postbacks/<public-tracking-key>/reversals

Report a refund or cancellation of a one-time order. Leave out `amount_refunded_cents`, or send the full subtotal, for an amount-only full reversal. Amount-only partial refunds reduce commission proportionally. For item refunds, opt in by posting the original conversion with stable `line_id` values on every line, then send `refund_basis: line_items_v1` with cumulative `refund_lines`. Do not mix item and proportional partial-refund histories on the same order; switching returns 422 `unsupported_reversal_type`. Both partial-refund modes obey the program's frozen refund hold. After it, partial refunds return 422 `partial_refund_not_adjusted`; an amount-only full reversal remains available. A new refund after Refermate has billed you for the commission returns 422 `paid_conversion_not_auto_reversed` and reverses nothing; contact support to settle it.

| Field | Required | Description |
| --- | --- | --- |
| `order_id` | Yes | The same order ID you sent to `conversions`. |
| `amount_refunded_cents` | No | Total refunded on this order so far, in cents, on the same basis as `order_subtotal_cents` (leave out refunded tax and shipping). Send the running total, not the latest refund. Resending a total already recorded returns that first answer, even after you are billed or the order is put on hold. Requires `occurred_at`. A new total lower than one already recorded returns 409 `refund_amount_conflict` unless its `occurred_at` is earlier. Above the subtotal returns 422 `invalid_amounts`. |
| `occurred_at` | No | When it happened, in the same format: ISO 8601 with an explicit offset. Defaults to when we receive the request; send it when you replay a late event. |
| `refund_basis` | No | `line_items_v1` opts into cumulative returned-item quantities. Requires refund_lines, amount_refunded_cents and occurred_at, and original conversion lines with stable line_id values. Without it, partial refunds retain whole-order proportional behavior. Do not mix line and proportional partial-refund histories on one order; that returns unsupported_reversal_type. |
| `refund_lines` | No | With refund_basis=line_items_v1, send the running returned quantities as `[{ line_id, quantity, amount_minor_units }]`. Each amount is original line amount minus floor(original line amount × remaining quantity / purchased quantity). Their sum must equal amount_refunded_cents. Unknown IDs, duplicate IDs, excess quantities or inconsistent line amounts are invalid_payload. Exclude tax/shipping refunds. This contract does not support price-only adjustments; reconcile those separately once line refunds have started, without inventing quantities or mixing refund modes. Reordered identical lines replay safely. A newer snapshot may increase quantities at the same total after rounding, but cannot move refunded quantities between lines. Old snapshots are ignored only when every returned line is covered by the applied snapshot. A refund that removes all eligible merchandise reverses the conversion within its frozen hold. A zero total is allowed only when valid returned lines sum to zero; legacy amount-only zero remains invalid. |
| `reason` | No | A short reason such as `refunded` or `cancelled`. |

A full refund:

```json
{
  "occurred_at": "2026-10-02T09:30:00.000Z",
  "order_id": "ORDER-1001",
  "reason": "refunded"
}
```

A cumulative item refund for an order with stable line IDs:

```json
{
  "order_id": "ORDER-1001",
  "occurred_at": "2026-10-02T09:30:00.000Z",
  "amount_refunded_cents": 1500,
  "refund_basis": "line_items_v1",
  "refund_lines": [
    {
      "line_id": "order-line-1",
      "quantity": 1,
      "amount_minor_units": 1500
    }
  ]
}
```

### POST /api/partner-network/postbacks/<public-tracking-key>/v2/recurring/relationships

Bind a referred customer to the Refermate click or the referral code that brought them. Send this once per customer, when they first sign up or subscribe; every later subscription and payment of that customer then belongs to the same relationship. The first bind wins: resending the same body returns `duplicate_relationship`, and a bind of the same customer with another click or code returns 409 `relationship_already_bound`. An unknown code does not replace a valid `click_id`: the relationship binds to that click. A code-only request with an unknown code returns 404 `unknown_referral_code`. Which payments earn is decided at each payment by the program's subscription commission rules.

| Field | Required | Description |
| --- | --- | --- |
| `event_id` | Yes | Your unique ID for this event; resending it is safe. |
| `customer_id` | Yes | Your stable customer ID. Send the same value on every billing event, reversal and end for this customer. |
| `click_id` | No | The `rm_click` value for this shopper. Send `click_id`, `code`, or both. An eligible code for another referrer wins over the click; an unknown code does not replace a valid click. |
| `code` | No | The referral code the customer gave: a referrer's creator code, or the token of their referral link (`/r/<token>`), looked up in that order. |
| `environment` | Yes | Always `live` for production traffic. |
| `occurred_at` | No | When it happened, in the same format: ISO 8601 with an explicit offset. Defaults to when we receive the request; send it when you replay a late event. |
| `test` | No | `true` with your integration's test code as `code` verifies a codes-only setup: it answers `test_verified` and binds nothing. |

A new referred customer:

```json
{
  "click_id": "a1B2c3D4e5F6g7H8",
  "customer_id": "cus-1001",
  "environment": "live",
  "event_id": "evt-cus-1001-bound",
  "occurred_at": "2026-09-28T17:05:00.000Z"
}
```

A customer who signed up with a referral code:

```json
{
  "code": "JANE10",
  "customer_id": "cus-1002",
  "environment": "live",
  "event_id": "evt-cus-1002-bound",
  "occurred_at": "2026-09-28T17:05:00.000Z"
}
```

### POST /api/partner-network/postbacks/<public-tracking-key>/v2/recurring/billing-events

Report each invoice of a bound customer, paid or not. Never send a click here: the relationship already names it. A customer with several subscriptions has one relationship; name the subscription on each invoice so its payments are ordered on their own. A paid invoice pays the customer's referrer (level 1) and, when your program pays deeper levels, the referrer's own referrers (levels 2 to 5), each at its level's rate and each held for the rule's own hold. A blocked referrer earns nothing and the levels above keep their numbers; when every level is blocked the invoice returns `no_paying_referrer`. Refermate's fee is charged once per invoice.

| Field | Required | Description |
| --- | --- | --- |
| `event_id` | Yes | Your unique ID for this event. |
| `customer_id` | Yes | The customer ID you bound. |
| `subscription_id` | No | Your subscription ID, when the invoice belongs to one. Payments of one subscription must arrive in order; different subscriptions do not wait for each other. |
| `invoice_id` | Yes | Your invoice ID. |
| `payment_state` | Yes | `paid`, `failed`, `open`, `void`, or `uncollectible`. Only `paid` can earn a reward. |
| `amount_paid_minor_units` | Yes | Amount paid, in cents. |
| `eligible_amount_minor_units` | No | The commissionable part. Defaults to the amount paid and cannot exceed it. |
| `product_id` | Yes | The billed product. The program's subscription rule for this product decides the reward; with no matching rule the payment returns `no_matching_subscription_rule` and earns nothing. |
| `price_id` | No | The billed price or plan. |
| `currency` | Yes | Only `USD` is accepted. |
| `environment` | Yes | Always `live` for production traffic. |
| `occurred_at` | Yes | When it happened, in ISO 8601 with an explicit offset (`Z` or `±HH:MM`), for example `2026-09-28T17:05:00.000Z`. Any number of fractional digits is accepted; Refermate keeps milliseconds and drops the rest. JavaScript `toISOString()`, .NET `"o"`, Java `Instant.toString()`, and Python `isoformat()` on a timezone-aware datetime all qualify. A time without an offset is rejected. |

A paid invoice:

```json
{
  "amount_paid_minor_units": 1999,
  "currency": "USD",
  "customer_id": "cus-1001",
  "environment": "live",
  "event_id": "evt-inv-1001-paid",
  "invoice_id": "inv-1001",
  "occurred_at": "2026-09-28T17:05:00.000Z",
  "payment_state": "paid",
  "product_id": "plan-pro",
  "subscription_id": "sub-1001"
}
```

### POST /api/partner-network/postbacks/<public-tracking-key>/v2/recurring/reversals

Report a full or cumulative partial refund of one invoice. Omitting the amount reverses it in full. It covers every level the invoice paid. A partial refund scales the original eligible amount and each level's reward within the hold; after the hold it returns `partial_refund_not_adjusted`. Collected commissions remain final: if any level's reward has been collected, the refund returns `paid_conversion_not_auto_reversed` for review. An active hold returns 423 `active_hold` for a later retry.

| Field | Required | Description |
| --- | --- | --- |
| `event_id` | Yes | Your unique ID for this event. |
| `customer_id` | Yes | The customer ID. |
| `invoice_id` | Yes | The refunded invoice. |
| `amount_refunded_minor_units` | No | Positive running refunded total on the original amount_paid_minor_units basis. Requires occurred_at. Above the paid amount returns invalid_amounts; equal to it reverses in full. Only this field and amountRefundedMinorUnits are supported; other amount aliases return unsupported_reversal_type. Reuse the same event_id and unchanged body on retries. A newer lower total conflicts; an older lower total is ignored. Each partial and subsequent full reversal uses the original reward without compounding rounding. |
| `reason` | No | A short reason. |
| `environment` | Yes | Always `live` for production traffic. |
| `occurred_at` | No | When it happened, in the same format: ISO 8601 with an explicit offset. Defaults to when we receive the request; send it when you replay a late event. |

A refunded invoice:

```json
{
  "customer_id": "cus-1001",
  "environment": "live",
  "event_id": "evt-inv-1001-refunded",
  "invoice_id": "inv-1001",
  "occurred_at": "2026-10-02T09:30:00.000Z",
  "reason": "refunded"
}
```

A partially refunded invoice:

```json
{
  "amount_refunded_minor_units": 500,
  "customer_id": "cus-1001",
  "environment": "live",
  "event_id": "evt-inv-1001-partial",
  "invoice_id": "inv-1001",
  "occurred_at": "2026-10-01T09:30:00.000Z",
  "reason": "partial_refund"
}
```

### POST /api/partner-network/postbacks/<public-tracking-key>/v2/recurring/relationships/end

Report that a subscription ended, or that the whole customer relationship did. With `subscription_id`, later invoices of that subscription are rejected and the customer's other subscriptions keep earning. Without it, every later invoice of the customer is rejected.

| Field | Required | Description |
| --- | --- | --- |
| `event_id` | Yes | Your unique ID for this event. |
| `customer_id` | Yes | The customer ID. |
| `subscription_id` | No | The subscription that ended. Leave it out only when the customer leaves for good. |
| `reason` | No | A short reason. |
| `environment` | Yes | Always `live` for production traffic. |
| `occurred_at` | No | When it happened, in the same format: ISO 8601 with an explicit offset. Defaults to when we receive the request; send it when you replay a late event. |

A canceled subscription:

```json
{
  "customer_id": "cus-1001",
  "environment": "live",
  "event_id": "evt-sub-1001-ended",
  "occurred_at": "2026-12-28T17:05:00.000Z",
  "reason": "canceled",
  "subscription_id": "sub-1001"
}
```

### POST /api/partner-network/postbacks/<public-tracking-key>/v2/referrers

Make one of your customers a referrer with a referral link of their own. Send it whenever the customer asks for their link; it is safe to resend and returns the same link (`already_enrolled`). The answer adds `membership_id`, `referral_link_token` and `referral_url`. Customers they refer bind to that link like any other click, or to its token as a `code`. Their rewards are paid into a Refermate balance: until the customer has a Refermate account, the answer also has `claim_url` and `claim_expires_at` (30 days). Show the customer that link; signing in there makes the rewards they earned, and every later one, theirs. Each call answers a new claim link and the previous one stops working.

| Field | Required | Description |
| --- | --- | --- |
| `customer_id` | Yes | The same customer ID your relationships and billing events use. |
| `email` | No | The customer's email. Refermate stores only its hash. An email already enrolled for another customer returns 409 `email_already_enrolled`. |
| `refermate_user_id` | No | Only for a program Refermate itself funds: the customer's own Refermate account, so no claim is needed. Any other program answers 422 `refermate_user_not_allowed`. An unknown account answers 422 `refermate_user_not_found`; an account or customer already enrolled under another one answers 409 `refermate_user_conflict`. |
| `environment` | Yes | Always `live` for production traffic. |

A customer who wants a referral link:

```json
{
  "customer_id": "cus-1001",
  "email": "customer@example.com",
  "environment": "live"
}
```

## Responses

Every response is JSON with `ok` and a machine-readable `reason`, for example `{"ok": true, "reason": "recorded", "transaction_id": 123}`. Created records add `transaction_id`, `conversion_id`, `binding_id`, `event_id`, or `membership_id`. Branch on the status and `reason`, never on wording.

| Status | Meaning |
| --- | --- |
| 200 | Accepted, including an exact replay of an earlier request (for example `duplicate_order`). A free order answers `zero_amount`: accepted, nothing recorded, do not retry. Check ok and reason too: a reversal's conversion_not_found is a no-op, not a completed refund. A replayed recurring event returns the first delivery's reason and status with replayed: true. |
| 400 | The body is not valid JSON, has invalid amounts, uses unsupported Content-Encoding, or is missing a required field (`invalid_payload`, `invalid_amounts`, `json_required`, `unexpected_click_id`, `unsupported_content_encoding`). Send uncompressed JSON and fix the request before retrying. |
| 401 | Missing or wrong postback key. |
| 403 | The integration is disabled or the store is archived. |
| 404 | The customer, invoice, click or code named in a recurring request does not exist (`unknown_referral_code` for a code). |
| 409 | The same ID was sent earlier with different content (`duplicate_order_conflict`, `duplicate_event_conflict`, `refund_amount_conflict`), a recurring invoice already paid under another customer was sent again (`duplicate_invoice_conflict`), or the environment does not match. |
| 410 | A verification test link expired. |
| 413 | The body is larger than 16 KiB (2 MiB for the product catalog endpoint). |
| 422 | The request is valid but cannot earn, for example `missing_referral_click`, `referral_click_already_converted`, `unsupported_pricing_currency`, `invalid_occurred_at`, `relationship_ended`, or `partial_refund_not_adjusted`. Do not retry. `pricing_history_ambiguous` means the purchase time falls within the same second (or millisecond) as a change to your commission rules, so Refermate cannot tell which rates applied; resending the same body gets the same answer, so resend `occurred_at` with milliseconds or contact support. `paid_conversion_not_auto_reversed` means a refund came after the commission was billed, so contact support. |
| 423 | `active_hold`: the order is under a dispute or review hold, so the refund changed nothing. Resend the same body after the `Retry-After` delay (one day, also in `retry_after_seconds`); it succeeds once the hold resolves. |
| 429 | `rate_limited`: the integration's shared postback budget is exhausted. Keep the original body queued and retry after `Retry-After: 60`; no event was consumed. |
| 5xx | Usually temporary: retry the same body with bounded backoff. `503 rate_limit_unavailable` means admission failed before body or event processing; `pricing_history_unavailable` means pricing history is briefly unavailable. |

## Retries and limits

- The initial budget is 3,000 requests per minute per authenticated integration and environment, shared across all seven postback endpoints. Rotating a key does not reset the allowance. Queue traffic in your backend and pace bursts. HTTP 429 rate_limited carries Retry-After: 60; wait at least 60 seconds, then retry the unchanged stored body with backoff and jitter. HTTP 503 rate_limit_unavailable means admission could not be checked; keep the event queued and retry the same body with bounded backoff. Neither response reads the body, consumes the order/event, or changes tracking health or financial records. Keep the bounded early-refund reconciliation policy below; do not mint new IDs to evade the budget.
- Retry 5xx responses and network errors with the same stored body and bounded backoff. Retry 423 active_hold after Retry-After. Use the ordered recovery below for conversion_not_found or invoice_not_found.
- A one-time refund can arrive before its paid order. HTTP 200 with ok:false and conversion_not_found means nothing was reversed or queued. Keep both original request bodies in your order database. Deliver the stored conversion first; after recorded or duplicate_order, retry the stored refund. Keep the conversion's HTTP status with its JSON result. When no HTTP response exists, leave conversion undefined in the example; do not invent an ok:false server response for a network failure. Retry that same conversion after a network failure, HTTP 429 or 5xx; send permanent, held or unknown refusals to reconciliation instead. Parse Retry-After seconds or its HTTP-date and persist the retry-at time; pass its remaining delay as retryAfterMs. Use exponential backoff with at most 8 attempts and a 24-hour deadline, persisted across worker restarts. If the conversion never arrives, either bound is reached or the next delay reaches the deadline, stop automatic retries and alert your reconciliation queue; do not mark the refund complete or create a replacement order/event ID. A recurring invoice_not_found needs the same ordered reconciliation against its original billing event.
- One-time retries must retain the original customer_id and discount_code as well as order ID, clicks, purchase time, currency, amounts and lines. New conversions fingerprint the trimmed customer ID and code; the first accepted values, including omitted values, stand. Adding, changing or removing either, including a change in code case, returns 409 duplicate_order_conflict. Referral link tokens are case-sensitive. Historical conversions without that fingerprint retain their earlier replay checks. A retry never changes the original payee.
- Custom recurring billing replays must keep product_id, price_id and occurred_at unchanged along with IDs, state, currency and amounts. If a historical rejected receipt lacks enough immutable evidence, the replay returns duplicate_event_conflict for review. A cancellation or full refund without occurred_at reuses its first accepted time on retry; an explicitly changed time conflicts. Send the original timestamp whenever possible.
- How many one-time orders one click backs is your program's orders-per-click setting (Affiliate settings). With every order in the attribution window (the default), each order inside the click's window earns. With first order only, a second order on the same click returns `referral_click_already_converted`. Each click keeps the setting it was made under. A code backs any number of orders.
- Only USD orders earn today.
- `occurred_at` may be at most 5 minutes in the future. A paid order may be at most the program's attribution window plus 7 days old; refunds and subscription events may be up to 372 days old.

The merchant persists attempts, elapsed time and both original bodies. This example decides the next action; it does not send a request or keep retry state:

```js
function nextRefundDelivery({ refund, conversion, attempts, elapsedMs }) {
  if (refund.ok) {
    const completed = ["reversed", "partially_reversed", "duplicate_reversal", "not_commissioned"];
    return { action: completed.includes(refund.reason) ? "complete" : "reconcile_and_alert" };
  }
  if (!["conversion_not_found", "invoice_not_found"].includes(refund.reason)) {
    return { action: "handle_other_error" };
  }
  if (attempts >= 8 || elapsedMs >= 24 * 60 * 60 * 1000) {
    return { action: "reconcile_and_alert" };
  }
  const accepted = conversion?.ok &&
    (conversion.httpStatus === undefined ||
      (conversion.httpStatus >= 200 && conversion.httpStatus < 300)) &&
    ["recorded", "duplicate_order", "duplicate_invoice"].includes(conversion.reason);
  const httpStatus = conversion?.httpStatus;
  const retryableConversion = httpStatus === 429 ||
    (typeof httpStatus === "number" && httpStatus >= 500 && httpStatus < 600);
  if (conversion && !accepted && (conversion.ok || !retryableConversion)) {
    return { action: "reconcile_and_alert" };
  }
  const remainingRetryDelay = conversion?.retryAfterMs;
  const retryAfterMs = !accepted && typeof remainingRetryDelay === "number" &&
    Number.isFinite(remainingRetryDelay) && remainingRetryDelay > 0
      ? remainingRetryDelay : 0;
  const delayMs = Math.max(
    Math.min(60 * 1000 * 2 ** attempts, 60 * 60 * 1000), retryAfterMs);
  if (elapsedMs + delayMs >= 24 * 60 * 60 * 1000) {
    return { action: "reconcile_and_alert" };
  }
  return {
    action: accepted ? "retry_stored_refund" : "deliver_stored_conversion",
    delayMs,
  };
}
```

## Verify your integration

Verify your domain first, one of two ways; your Developer Integration setup page shows both with your store's verification code. Homepage tag: add `<meta name="refermate-verification" content="<code>">` to your homepage `<head>` and choose "Check homepage". Refermate loads `https://<your-domain>/` over HTTPS, following up to three redirects on the same domain or its `www.` twin, and looks for that exact tag. DNS record: add a TXT record named `_refermate.<your-domain>` (without `www.`) with the value `refermate-verification=<code>` and choose "Check DNS". DNS changes can take a few minutes to show up. You can remove the tag or record once the domain is verified, and you can create the integration only after it passes. If neither works for you, an approved store claim for the exact domain also verifies it. Then choose "Create test link". Open the link on your site, place an order, and post it with `"test": true` and the `rmv_` click ID the script stored. A 200 `test_verified` response turns tracking on. Test orders never create money.

### Codes only

- No capture script is needed when your customers give a referral code instead of following a link. Every referrer has a code: their creator code when your program issues them, otherwise the token of their referral link (`/r/<token>`).
- Report a one-time order with the code as `discount_code` and no `click_id`. Bind a recurring customer with the code as `code` instead of `click_id`. Pricing, holds and refunds are the same as for a click.
- Verify the setup with your integration's test code, shown on your Developer Integration setup page (`RMTEST-` and the start of your public tracking key): post an order with `"test": true` and the test code as `discount_code`, or a relationship with `"test": true` and the test code as `code`. Either answers 200 `test_verified`, turns tracking on and creates no money.

## Product catalog

The product catalog is your store's private list of products in Partners (Partners › Products). Bring products in from Shopify, from Stripe, from a CSV file, or from your own server with the endpoint below. It is private to your store: it does not publish products to Refermate shoppers, create offers or change your commission rules.

- The catalog stores product-level items: a stable ID, title, availability, and optional image and product links. Variants, prices and inventory are not stored.
- Connected Shopify and Stripe catalogs sync automatically. Products shows the connection's sync status and any setup still needed. Your custom integration sends its catalog through this endpoint and sends updates when products change. To mark a custom product as no longer sold, send it again with `active` set to `false`. Leaving a product out of a batch never deletes or deactivates it.
- A product is identified by your store, where it came from and its ID. Sending the same ID again updates that product instead of adding another, so resending a batch is safe and changes nothing (`changed` is 0).
- In Partners, search the stored catalog and select products to organize into a product set or configure a reward policy. Syncing products does not create reward rules. Named product sets are shared with our Shopify app and need a reward rule to earn commission. A Stripe product ID starts with `prod_` and is never a Price ID. Shopify products use `gid://shopify/Product/<number>`; CSV also accepts the product's number, never a variant ID.
- In Claude or ChatGPT, `merchant_read_products` reads the catalog and supports `action: syncStatus`. `merchant_import_products` supports `source: sync` to request a background retry for Shopify or Stripe. Both need the store's separate `manage_catalog` consent. Imports and sync requests require confirmation; a confirmed sync request does not mean the sync has finished.

### Import a CSV

- A CSV holds at most 500 products and 2 MiB. Its first row names the columns: `external_id` and `title` are required; `image_url`, `product_url` and `active` are optional. Other columns are ignored.
- Choose the source the IDs come from (Shopify, Stripe or Custom) before you check the file: the IDs must be that source's product IDs. A check lists every row problem and imports nothing; a file with any problem imports nothing.
- `active` takes `true` or `false` (also `yes`, `no`, `1`, `0`); a blank cell means active. Quote a cell that holds a comma, quote or line break and double any quote inside it. A leading byte order mark and Windows line endings are fine.

### Push products from your server

Send your secret postback key exactly as for the other endpoints, as `Authorization: Bearer <key>` (or `X-Refermate-Postback-Key`), from your server only. The body is a JSON object of at most 2 MiB with `products` and nothing else: your store is the one the key belongs to, so a body that names a store, advertiser or integration is refused. A batch holds 1 to 500 products and is written all or nothing: if any product is invalid, none is saved and the answer lists each problem by its position. Catalog JSON uses camelCase: `externalId`, `imageUrl` and `productUrl`. CSV headers use snake_case. Snake_case aliases and other unknown fields in catalog JSON are rejected.

### POST /api/partner-network/postbacks/<public-tracking-key>/v2/catalog/products

Import products into your store's private catalog or revise existing entries. Products from this endpoint are `custom` products: the ID is yours to choose and stays the product's identity. The answer reports how many products the batch held (`imported`) and how many were added or changed (`changed`).

| Field | Required | Description |
| --- | --- | --- |
| `products` | Yes | The batch: 1 to 500 products. The same `externalId` twice in one batch is rejected. |
| `products[].externalId` | Yes | Your stable product ID, up to 255 characters and without control characters. It is the product's identity within your store: use the product's ID, not a variant, SKU variant or price ID. |
| `products[].title` | Yes | The product's name, up to 500 characters, on one line. |
| `products[].imageUrl` | No | An `https` link to the product's image, up to 2048 characters and without a username or password. Omit it or send `null` for none. |
| `products[].productUrl` | No | An `https` link to the product's page, with the same rules. Omit it or send `null` for none. |
| `products[].active` | No | Whether the product is currently sold. Defaults to `true`; send `false` to mark a product as no longer sold. Nothing is deleted. |

Two products, one with an image and a link:

```json
{
  "products": [
    {
      "externalId": "sku-1001",
      "title": "Trail Mug",
      "imageUrl": "https://cdn.example.com/images/trail-mug.jpg",
      "productUrl": "https://shop.example.com/products/trail-mug",
      "active": true
    },
    {
      "externalId": "sku-1002",
      "title": "Camp Kettle",
      "active": false
    }
  ]
}
```

```sh
curl -X POST "https://partners.refermate.com/api/partner-network/postbacks/<public-tracking-key>/v2/catalog/products" \
  -H "Authorization: Bearer <postback-key>" \
  -H "Content-Type: application/json" \
  -d '{"products":[{"externalId":"sku-1001","title":"Trail Mug","active":true}]}'
```

### Catalog answers

| Status | Reason | Meaning |
| --- | --- | --- |
| 200 | `imported` | Saved. `imported` is the batch size and `changed` how many products were added or changed; a replay answers `changed: 0`. |
| 400 | `invalid_payload` | The body is not exactly `{ "products": [...] }` with at least one product. Anything else in the body, such as a store or advertiser ID, is refused. |
| 400 | `invalid_json` | The body is not a JSON object. `json_required` and `unsupported_content_encoding` mean the request is not uncompressed `application/json`. |
| 401 | `unauthorized` | Missing or wrong postback key. |
| 403 | `advertiser_unavailable` | The store is archived or no longer has an owner. Nothing was saved. |
| 409 | `integration_changed` | The key was revoked or rotated, or the integration was replaced or uninstalled, while the request ran. Nothing was saved; send the batch again with the current key. |
| 413 | `payload_too_large` | The body is larger than 2 MiB. Split the batch. |
| 422 | `batch_too_large` | The batch has more than 500 products. Split it. |
| 422 | `validation_failed` | At least one product is invalid or repeated, so none was saved. `errors` lists up to 100 problems as `{ "index", "message" }`, where `index` is the product's position in `products`, starting at 0. Fix them and resend the whole batch. |
| 429 | `rate_limited` | This endpoint allows 60 requests a minute per integration, a budget of its own apart from the 3,000 a minute the seven postback endpoints share; rotating a key does not reset it. Retry after `Retry-After: 60`. Nothing was saved. |
| 503 | `rate_limit_unavailable` | The limit could not be checked, so the request was refused before it was read. Resend the same body. |
| 500 | `internal_error` | Nothing was saved. Resend the same body with bounded backoff: a batch is safe to repeat. |

## App installs

App installs pay creators when people install and use your browser extension or mobile app. Any brand on the Partner Network can use them, whether Shopify, Stripe or a Developer Integration connects its store. A brand with only an app needs no order postbacks.

1. In Partners, select your store and open "Rewards", then choose "Installs". Under "App installs", choose "Add your first app", or "Add rule" if you already have one. Its menu lists install and activation rewards for connected apps, plus mobile app and browser extension setup links. Use the setup links to add store listings and create the app's event key.
2. Under "App installs", set what you pay for each install or activation. These rewards belong to the same store as its purchase rules.
3. A creator shares their app link: their referral link with `to=app`. Refermate records the click and sends the person to your listing for their device.
4. Your extension or app passes the click back. An extension opens Refermate's install page once. A mobile app reads `rm_click`.
5. Your server reports each install and activation to the app events API. Money moves only on these server events.
6. Only verified listings get traffic. Verify each one with a private test link.

### What you pay

- You set one amount, in USD, for each install or activation of your extension, your iPhone and iPad app, and your Android app. An extension has one amount for every browser. Your program must be priced in USD.
- You pay exactly that amount. No fee is added on top.
- Refermate pays the creator, as an affiliate network does.
- One click pays at most one install and one activation, whatever the platform, plus a purchase through your order postback. An event no payout covers still uses its click's slot, so turning a payout on later never pays old clicks.
- App payouts sit beside your purchase commissions and never change them. They don't add to your sales totals.

### Holds and reversals

- Each payout has its own hold of 0 to 180 days. Each event keeps the hold that applied when it was recorded.
- Each event approves automatically when its hold ends, unless it was reversed or rejected; you can approve or reject it in Partners sooner. Refermate then bills you the way it bills your orders, and pays the creator.
- Report uninstalls, fraud and refunds to the reversals endpoint. An event can be reversed until you are billed for it. Reversing an install also ends that click's install, so nothing more on the click pays.

### Links and devices

A creator's app link is their referral link with `to=app` (`/r/<token>?to=app`). It sends each person to your verified listing for their device:

1. A social app's own browser (Facebook, Instagram, TikTok, LinkedIn, Snapchat): a page asking them to open the link in their usual browser.
2. Android, in any browser: Google Play, with the click in the install referrer.
3. iPhone and iPad: your iOS landing page with `?rm_click=<click id>`. With no landing page, the App Store, and the install can't be credited.
4. A computer: Edge to your Edge listing, else your Chrome one. Firefox to Firefox Add-ons. Safari to a page that asks whether it's a Mac or an iPad. Every other browser to the Chrome Web Store.
5. A device with no listing: a page naming the platforms your app is on.

Only a visit sent to a store records a click. Product links can't use `to=app`.

### Install window and cookie

- Each app has an install window of 1 to 30 days (7 by default). An install counts only within it. Each click keeps the window it was made with, so changing it later doesn't move old clicks.
- For extensions, Refermate keeps the click in a cookie on refermate.com: `rm_app_<app id>`, `HttpOnly`, `Secure`, `SameSite=Lax`, sent only to the install page and lasting the install window. It holds only the click ID. The last click wins.

## Install hooks

### Browser extensions

Have your extension open this Refermate page once, when it is installed:

```text
https://refermate.com/app-installed/<app-public-key>?install=<uuid>&v=<version>&b=<browser>
```

- `install`: a new ID from `crypto.randomUUID()`. Keep it, and send it to your own server, which reports the install with it as `install_id`.
- `v`: your extension's version, up to 32 letters, digits, dots, `+` and `-`. URL-encode it with `URLSearchParams` or `encodeURIComponent`: a bare `+` in a query string reads as a space, and the version is dropped.
- `b`: `chrome`, `edge`, `firefox` or `safari`, the store this build ships to.

```js
// Your extension's background service worker.
chrome.runtime.onInstalled.addListener(({ reason }) => {
  if (reason !== "install") return;
  const installId = crypto.randomUUID();
  // Keep installId and send it to your server, which reports the install.

  const page = new URL("https://refermate.com/app-installed/<app-public-key>");
  // searchParams encodes each value, so a + in the version stays a +.
  page.searchParams.set("install", installId);
  page.searchParams.set("v", chrome.runtime.getManifest().version);
  page.searchParams.set("b", "chrome"); // chrome, edge, firefox, safari
  void chrome.tabs.create({ url: page.href });
});
```

- Open the page from `runtime.onInstalled` when `reason` is `install`. Safari fires it only when the person turns your extension on in Safari's settings, which can be long after the download.
- Refermate reads its cookie, records a pending install for the click, clears the cookie, and sends the person to your welcome page, or shows "Installed". It records each click and each `install` ID once. The page never bills, and anything invalid is ignored.
- It records at most 20 installs per IP address per hour, and 5,000 per app every 5 minutes. Past that it records nothing, but the person still lands normally.

### Android

Google Play passes the click to your app in its install referrer, as `rm_click=<click id>`. On first launch, start a background job that reads the referrer with Google's Play Install Referrer library (`com.android.installreferrer:installreferrer`), takes `rm_click` from it and keeps it. The job sends it to your server until your server confirms it, then forgets it. Wait for Google Play's answer before sending: if Play can't answer yet or a send fails, the job tries again. Your server reports events with it as `click_id`.

### iPhone and iPad

The App Store passes nothing to your app, so you carry the click yourself. In Partners, add an iOS landing page on your site. It gets `rm_click` in its address. Carry it through your web sign-up, or a sign-in link that opens your app, to your server. Your server reports events with it as `click_id`. Without a landing page, iPhone and iPad installs can't be credited. SKAdNetwork and AdAttributionKit aren't supported.

## App events API

Send your app's event key as `Authorization: Bearer <event key>` (or `X-Refermate-Postback-Key`). It is a separate key from your postback key. Partners shows it once, to the store owner or a team member with Integrations access. A replaced key keeps working for 7 days. An archived app keeps its key and accepts reversals only. Bodies are JSON objects up to 16 KiB. Each field also takes its camelCase name (`installId`, `clickId`, `eventId`, `occurredAt`). Call these endpoints only from your server; the key must never reach your extension, your app or a browser.

### POST /api/partner-network/apps/<app-public-key>/events

Report an install or an activation. Extensions name it by `install_id`, for both events. Mobile apps name it by `click_id`. Any platform can instead name a referred customer you bound by `customer_id`: the event pays that customer's referrer, with no click. An install answer includes `click_id`: save it with the user's account, because a later purchase through your order postback uses the same click.

| Field | Required | Description |
| --- | --- | --- |
| `event` | Yes | `install` or `activation`. You decide what activation means, such as signing up or first use. |
| `install_id` | Yes, for extensions | The ID your extension made with `crypto.randomUUID()` and sent to the install page. Send exactly one of `install_id` and `click_id`. |
| `click_id` | Yes, for mobile apps | The `rm_click` value your app received (16 hex characters), or a test link's `rmv_` ID. Send it exactly as received. |
| `customer_id` | No | Instead of `install_id` or `click_id`: the customer ID of a relationship you bound through `v2/recurring/relationships`. It pays that customer's referrer (level 1), who needs a Refermate account. One install and one activation per customer earn. Send exactly one of `install_id`, `click_id` and `customer_id`. |
| `event_id` | Yes | Your own ID for this event, up to 128 characters, or a whole number. It is the idempotency key: use a new one for each event. |
| `occurred_at` | Yes | When it happened, in the same ISO 8601 format as purchases, with an explicit offset (`Z` or `±HH:MM`). It can't be earlier than the click, or more than 5 minutes after Refermate receives it. Set it once and keep it for retries. |
| `platform` | Yes | `chrome`, `edge`, `firefox` or `safari` for an extension; `ios` or `android` for a mobile app. It must match the store the click was sent to. |
| `test` | No | `true` only for a test link's events. Otherwise leave it out or send `false`. |

An extension install:

```json
{
  "event": "install",
  "event_id": "install-6f1c1d1e",
  "install_id": "6f1c1d1e-3b8a-4a4e-9d2f-2b9e4b6d7a10",
  "occurred_at": "2026-09-28T17:05:00.000Z",
  "platform": "chrome"
}
```

An Android app activation:

```json
{
  "click_id": "3f9a0c4be27d1856",
  "event": "activation",
  "event_id": "activation-3f9a0c4b",
  "occurred_at": "2026-09-29T08:30:00.000Z",
  "platform": "android"
}
```

An activation of a referred customer:

```json
{
  "customer_id": "cus-1001",
  "event": "activation",
  "event_id": "activation-cus-1001",
  "occurred_at": "2026-09-29T08:30:00.000Z",
  "platform": "chrome"
}
```

A test install on iPhone:

```json
{
  "click_id": "rmv_Qm7Tz2Lp9Xc4Vb8Nw1Rk6Hs3Jd5Gf0Ay",
  "event": "install",
  "event_id": "test-install-ios",
  "occurred_at": "2026-09-28T17:05:00.000Z",
  "platform": "ios",
  "test": true
}
```

### POST /api/partner-network/apps/<app-public-key>/reversals

Reverse an install or an activation you reported, before you are billed for it. Name it by the same `install_id`, `click_id` or `customer_id` the event used. A reversed install ends its click's install, so nothing more on that click pays. An event still waiting for its install page is cancelled.

| Field | Required | Description |
| --- | --- | --- |
| `event` | Yes | The event to reverse. |
| `install_id` | Yes, for extensions | The same `install_id` the event used. |
| `click_id` | Yes, for mobile apps | The same `click_id` the event used. |
| `customer_id` | No | The same `customer_id` the event used. |
| `reason` | Yes | `uninstalled`, `fraud` or `refunded`. |

An extension uninstalled:

```json
{
  "event": "install",
  "install_id": "6f1c1d1e-3b8a-4a4e-9d2f-2b9e4b6d7a10",
  "reason": "uninstalled"
}
```

A fraudulent Android activation:

```json
{
  "click_id": "3f9a0c4be27d1856",
  "event": "activation",
  "reason": "fraud"
}
```

### Timing

- Installs must happen within the click's install window, activations within your program's attribution window. A late delivery of an event that happened in time still counts for 7 days after the window closes.
- Your server may report an extension's event before the extension opens the install page, since both start at install. The answer is then 202 `awaiting_handoff`. Refermate keeps the event until the page opens with that `install_id`. It then counts, and bills if a payout covers it. Nothing bills before then.

## App event answers

Every answer is JSON with `ok` and a `reason`, plus `click_id`, `transaction_id` and `replayed: true` when they apply, for example `{"ok": true, "reason": "paid", "click_id": "3f9a0c4be27d1856", "transaction_id": 123}`. Branch on the status and `reason`, never on wording.

### Events

| Status | Reason | Meaning |
| --- | --- | --- |
| 200 | `paid` | Counted, and a payout covers it. You're billed for it after its hold, and the creator earns it. |
| 200 | `unpaid_no_rule` | Counted, but no payout covers this event, so nothing is billed. It still uses its click's slot. |
| 200 | `test_verified` | Test received. The listing is verified. Nothing is billed. |
| 200 | `reversed` | You already reversed this event. It doesn't count again. |
| 202 | `awaiting_handoff` | Kept until your extension opens the install page with this `install_id`. Nothing bills until then. |
| 400 | `invalid_payload` | A field is missing or not valid, or `install_id` or `click_id` doesn't fit the platform. Fix the body. |
| 400 | `json_required` | Send `Content-Type: application/json`. |
| 400 | `invalid_json` | The body isn't a JSON object. |
| 401 | `unauthorized` | Missing or wrong event key, or no app with that public key. |
| 403 | `app_archived` | The app is archived. It accepts reversals only. |
| 403 | `app_disabled` | Tracking is turned off for this app. |
| 404 | `click_not_found` | Refermate has no such click or install. |
| 404 | `relationship_not_found` | That `customer_id` has no referral relationship with your program in this environment. |
| 409 | `cross_environment` | The click came from a different Refermate environment, such as a staging link. |
| 409 | `duplicate_event` | This click already has this event. A click pays at most one install and one activation. |
| 409 | `event_id_conflict` | This `event_id` was already used for a different event. |
| 410 | `test_click_expired` | The test link expired. Get a new one. |
| 413 | `payload_too_large` | The body is larger than 16 KiB. |
| 422 | `billing_rejected` | Refermate couldn't bill the charge. Check billing in Partners, then send the same body again. |
| 422 | `inactive_referral_context` | The creator's link or membership, your program, or your billing isn't active. |
| 422 | `install_not_active` | That install was reversed or has expired, so nothing more on its click pays. |
| 422 | `invalid_occurred_at` | `occurred_at` isn't a valid time with an offset, is before the click, or is more than 5 minutes ahead. |
| 422 | `outside_attribution_window` | The activation happened after your program's attribution window. |
| 422 | `outside_install_window` | The install happened after the click's install window. |
| 422 | `platform_mismatch` | `platform` doesn't match the app, or the store the click was sent to. |
| 422 | `pricing_history_ambiguous` | `occurred_at` falls in the same second as a change to your payouts, so Refermate can't tell which applied. Send `occurred_at` with milliseconds, or contact support. |
| 422 | `test_flag_required` | This is a test link's event. Send it with `test: true`. |
| 422 | `test_not_allowed` | `test: true` only works with a test link. |
| 422 | `unsupported_commission_configuration` | Your program's pricing can't pay app events. App payouts need a program priced in USD. |
| 429 | `rate_limited` | More than 3,000 events for this app in a minute. Wait for `Retry-After` (60 seconds), then send it again. |
| 500 | `internal_error` | Something failed on Refermate's side. Send the same body again in a few minutes. |
| 503 | `creator_rate_unavailable` | The creator's rate couldn't be read. Send the same body again in a few minutes. |
| 503 | `pricing_history_unavailable` | Your payout history couldn't be read. Send the same body again in a few minutes. |
| 503 | `rate_limit_unavailable` | The rate limit couldn't be checked. Send the same body again in a few minutes. |

### Reversals

| Status | Reason | Meaning |
| --- | --- | --- |
| 200 | `reversed` | Reversed. Nothing is billed for it, and a reversed install's click pays nothing more. |
| 200 | `duplicate_reversal` | Already reversed. |
| 200 | `test_reversal_received` | A test event. Nothing changed. |
| 400 | `invalid_payload` | A field is missing or not valid. Fix the body. |
| 404 | `event_not_found` | Refermate has no such event for this app. |
| 422 | `paid_event_not_reversed` | You were already billed for it, or the creator was paid, so it can't be reversed. Contact support. |
| 423 | `active_hold` | The event is under a dispute or review hold. Send the same body again later. |

Reversals also answer `json_required`, `invalid_json`, `unauthorized`, `payload_too_large`, `rate_limited`, `internal_error` or `rate_limit_unavailable` the same way events do.

### Idempotency and retries

- `event_id` is your idempotency key, unique within each app. Sending the same event again with the same `event_id` returns the first answer with `replayed: true`. The same `event_id` with any other field changed answers 409 `event_id_conflict`.
- Build each event's body once, when the event happens, and store it. Send that stored body on every retry. Building it again, for example with a new `occurred_at`, changes the body and answers 409.
- A refused event uses no slot, so you can fix it and send it again.
- Retry 429, 5xx and 422 `billing_rejected` with the same body, with backoff. After a 429, wait for `Retry-After`. Retry a reversal's 423 `active_hold` later. Fix any other refusal before you send it again.
- Each app can send 3,000 events a minute.
- Partners shows your app's last answer and when it came.

### Reserved order IDs

Order IDs that start with `rm_app:`, in any letter case, belong to app events (`rm_app:<install|activation>:<click id>`). A conversion or refund postback with one answers 400 `invalid_payload`, so a purchase never collides with an app event.

## Test your app

- In Partners, choose "Get test link" on a listing. A test link works for 24 hours, and the same link comes back while it has more than an hour left. Test events never bill.
- An extension's test link opens `https://refermate.com/app-test/<rmv_ ID>`, which sets the click cookie and opens your store page. Install from there, and your extension opens the install page as usual.
- An Android test link is your Google Play listing with the `rmv_` ID as `rm_click`. An iPhone test link is your landing page with it, so an iOS listing needs a landing page to be tested.
- Your server then reports the install with `test: true`. An extension sends its `install_id`; a mobile app sends the `rmv_` ID as `click_id`. The answer is 200 `test_verified` and the listing shows Verified. Your first verified listing verifies the app.
- A test link's event without `test: true` answers `test_flag_required`. A real click with `test: true` answers `test_not_allowed`. An expired test link answers 410 `test_click_expired`.
- Once your app is verified, app links work and your store goes live for creators, as with a verified store integration. Creators see app payouts only for platforms with a verified listing. A brand with only an app never needs a test order.

## What breaks attribution

- Installing in a different browser, browser profile or device from the one that opened the link. The extension cookie lives in that one browser profile.
- Private windows, cleared cookies, and browsers that clear site data.
- Social apps' own browsers, which can't install anything.
- Safari: the install page opens only once the person turns your extension on, and counts only if they opened the link in Safari and the install window is still open.
- iPhone and iPad installs without a landing page and your own way to carry the click.
- An install after the install window, or an activation after your program's attribution window.
- Not supported: mobile measurement partners such as AppsFlyer, Adjust and Branch; SKAdNetwork and AdAttributionKit; Opera's own add-on store; and app payouts in currencies other than USD.
