SmoothProfitDocs
ProductStart free

Getting started

  • Introduction
  • Quickstart
  • Authentication
  • Errors & rate limits

Core concepts

  • Tenancy model
  • Attribution
  • Commission resolution
  • Payout lifecycle

Guides

  • Install the tracker
  • Connect a storefront
  • Affiliate storefronts

API reference

  • Context
  • Affiliates
  • Conversions
  • Landing pages
  • Coupons
  • Payouts
  • Providers
  • Tracking

Getting started

Quickstart

End to end: create a key, install the tracker, and report a sale. About ten minutes.

1. Create an API key

In the agency console, open your program's Settings and create an API key. Give it both read and write scope — reporting conversions needs write.

The key is shown once, at creation. Only a SHA-256 hash is stored, so it cannot be recovered — if you lose it, revoke it and issue another.

2. Find your program id

Every data endpoint is nested under a program id. Your key already knows which program it belongs to; ask it:

bash
curl https://app.smoothprofit.app/api/v1/me \
  -H "Authorization: Bearer sp_live_your_key"

Cache program.id from the response. It never changes for that key.

3. Install the tracker

Add one script tag to your storefront, before </body>. It reads ?ref= off the landing URL, records the click, and stores the attribution in a first-party cookie for 60 days.

layout.html
<script
  src="https://app.smoothprofit.app/tracker/smoothprofit.js"
  data-program="peakcare"
  data-api-base="https://app.smoothprofit.app"
  data-cookie-domain=".peakcare.health"
  async
></script>

Set data-cookie-domain to your registrable domain with a leading dot if checkout lives on a subdomain — without it the cookie is host-only and attribution is lost on the hop to checkout.

4. Report the sale

When an order is paid, read the sp_ref cookie server-side and post the conversion. Reading it on the server rather than passing it through your checkout UI means attribution works no matter which flow started the order.

app/api/orders/complete/route.ts
const attribution = JSON.parse(cookies().get("sp_ref")?.value ?? "{}");

await fetch("https://app.smoothprofit.app/api/v1/conversions", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Authorization: `Bearer ${process.env.SMOOTHPROFIT_API_KEY}`,
  },
  body: JSON.stringify({
    orderId: order.id,
    orderAmountCents: order.totalCents,
    clickId: attribution.clickId,
    referralCode: attribution.referralCode,
    customerEmail: order.customerEmail,
    externalProductId: order.productId,
  }),
});

5. Confirm it landed

bash
curl "https://app.smoothprofit.app/api/v1/programs/$PROGRAM_ID/dashboard-summary" \
  -H "Authorization: Bearer sp_live_your_key"

sales.total should have gone up by one, and the affiliate's commission appears as pending until its holding period elapses and the agency approves it.

Refunded an order? Call POST /v1/conversions/clawback so the commission is reversed rather than paid out on a sale that no longer exists.