> ## Documentation Index
> Fetch the complete documentation index at: https://docs.affonso.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Embed Data

> Retrieve all data needed to render the embedded referral dashboard

Fetch comprehensive dashboard data for an affiliate using an embed token. This endpoint is **public** and uses token-based authentication via query parameter (no API key required).

<Note>
  This endpoint does not require API key authentication. Instead, it uses the `token` query parameter for authentication.
</Note>

## Query Parameters

<ParamField query="token" type="string" required>
  The public token from `POST /v1/embed/token`.
</ParamField>

## Response

<ResponseField name="success" type="boolean">
  Always `true` for successful responses.
</ResponseField>

<ResponseField name="data" type="object">
  Complete dashboard data.

  <Expandable title="Data Object Properties">
    <ResponseField name="affiliate" type="object">
      Affiliate information.

      * `name` (string | null): Display name
      * `email` (string): Email address
      * `trackingId` (string | null): Unique tracking identifier
      * `avatarUrl` (string | null): Profile picture URL
    </ResponseField>

    <ResponseField name="link" type="string">
      Full referral link with tracking parameter.
    </ResponseField>

    <ResponseField name="websiteUrl" type="string">
      Program's website URL.
    </ResponseField>

    <ResponseField name="rewards" type="object | null">
      Legacy commission structure (if no incentives configured).

      * `type` (string): "percentage" or "flat"
      * `amount` (number): Commission amount
      * `recurring` (boolean): Whether commission is recurring
      * `duration` (string | null): Duration type
    </ResponseField>

    <ResponseField name="incentives" type="array">
      Commission incentives configured for this affiliate. Includes both group incentives and affiliate-specific overrides.
    </ResponseField>

    <ResponseField name="stats" type="object">
      Performance statistics.

      * `clicks` (number): Total referrals
      * `leads` (number): Leads generated
      * `sales` (number): Successful conversions
      * `salesAmount` (number): Total sales amount
      * `earnings.pending` (number): Pending commission
      * `earnings.approved` (number): Approved but unpaid
      * `earnings.paid` (number): Total paid out
    </ResponseField>

    <ResponseField name="earnings" type="array">
      Recent transactions (up to 10). Each contains:

      * `id` (string): Transaction ID
      * `customerId` (string): Referral ID (for anonymous name generation)
      * `date` (string): ISO 8601 timestamp
      * `amount` (number): Transaction amount
      * `commission` (number): Commission earned
      * `status` (string): "PENDING", "APPROVED", "PAID", "REFUNDED", or "DECLINED"
    </ResponseField>

    <ResponseField name="portalUrl" type="string">
      URL to the full affiliate portal (with email pre-filled for login).
    </ResponseField>

    <ResponseField name="coupon" type="object | null">
      Affiliate's coupon code (if they have one).

      * `code` (string): The coupon code
      * `discountType` (string): "percentage" or "flat"
      * `discountValue` (number): Discount amount
    </ResponseField>

    <ResponseField name="couponBlueprint" type="object | null">
      If present, affiliate can create their own coupon via `/v1/embed/coupon`.

      * `discountType` (string): "percentage" or "flat"
      * `discountValue` (number): Discount amount
    </ResponseField>

    <ResponseField name="creatives" type="array">
      Marketing resources/creatives for the affiliate to use.
    </ResponseField>

    <ResponseField name="program" type="object">
      Program information.

      * `name` (string): Program name
      * `description` (string | null): Program description shown when `showDescription=true`
      * `logoUrl` (string | null): Program logo
      * `affiliateLinksEnabled` (boolean): Whether the referral link card is available
      * `defaultReferralParameter` (string): Default referral parameter, such as `via`
      * `enabledReferralParameters` (string\[]): Allowed referral parameter options
    </ResponseField>

    <ResponseField name="theme" type="object">
      Brand colors from portal settings.

      * `primaryColor` (string | null): HEX color code
      * `secondaryColor` (string | null): HEX color code
      * `hideBranding` (boolean): Whether the "Powered by Affonso" badge is hidden
    </ResponseField>

    <ResponseField name="token" type="string">
      The token used for this request (for subsequent API calls).
    </ResponseField>
  </Expandable>
</ResponseField>

## Caching

Responses include `Cache-Control: private, max-age=60` header. Data can be cached for up to 60 seconds client-side.

<RequestExample>
  ```bash cURL theme={null}
  curl "https://api.affonso.io/v1/embed/data?token=a1b2c3d4e5f6789..."
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    `https://api.affonso.io/v1/embed/data?token=${token}`
  );
  const { data } = await response.json();

  console.log(data.link);           // Referral link
  console.log(data.stats.sales);    // Number of sales
  console.log(data.earnings);       // Recent transactions
  ```

  ```python Python theme={null}
  import requests

  response = requests.get(
      'https://api.affonso.io/v1/embed/data',
      params={'token': 'a1b2c3d4e5f6789...'}
  )

  data = response.json()['data']
  print(data['link'])
  print(data['stats']['earnings']['paid'])
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "success": true,
    "data": {
      "affiliate": {
        "name": "John Doe",
        "email": "john@example.com",
        "trackingId": "john-doe",
        "avatarUrl": null
      },
      "link": "https://acme.com?via=john-doe",
      "websiteUrl": "https://acme.com",
      "rewards": {
        "type": "percentage",
        "amount": 20,
        "recurring": true,
        "duration": "lifetime"
      },
      "incentives": [],
      "stats": {
        "clicks": 150,
        "leads": 45,
        "sales": 12,
        "salesAmount": 2400,
        "earnings": {
          "pending": 120,
          "approved": 280,
          "paid": 480
        }
      },
      "earnings": [
        {
          "id": "tx_abc123",
          "customerId": "ref_xyz789",
          "date": "2024-01-14T15:30:00.000Z",
          "amount": 99.00,
          "commission": 19.80,
          "status": "APPROVED"
        }
      ],
      "portalUrl": "https://yourcompany.affonso.io/auth?email=john%40example.com",
      "coupon": {
        "code": "JOHN20",
        "discountType": "percentage",
        "discountValue": 20
      },
      "couponBlueprint": null,
      "creatives": [
        {
          "id": "cr_123",
          "name": "Banner 300x250",
          "description": "Standard banner ad",
          "category": "banners",
          "url": "https://cdn.example.com/banner.png",
          "dimensions": { "width": 300, "height": 250 }
        }
      ],
      "program": {
        "name": "Acme Affiliate Program",
        "description": "Promote Acme and earn recurring commissions on every qualified referral.",
        "logoUrl": "https://acme.com/logo.png"
      },
      "theme": {
        "primaryColor": "#881337",
        "secondaryColor": "#f0f0f0",
        "hideBranding": false
      },
      "token": "a1b2c3d4e5f6789..."
    }
  }
  ```

  ```json Error - Missing Token theme={null}
  {
    "success": false,
    "error": {
      "code": "MISSING_TOKEN",
      "message": "Token is required"
    }
  }
  ```

  ```json Error - Expired Token theme={null}
  {
    "success": false,
    "error": {
      "code": "TOKEN_EXPIRED",
      "message": "Token has expired"
    }
  }
  ```

  ```json Error - Invalid Token theme={null}
  {
    "success": false,
    "error": {
      "code": "INVALID_TOKEN",
      "message": "Invalid or expired token"
    }
  }
  ```
</ResponseExample>

## Using with iframe

For the pre-built dashboard UI, use the embed page instead of the API directly:

```html theme={null}
<iframe
  src="https://yourcompany.affonso.io/embed/referrals?token=a1b2c3d4e5f6789..."
  width="100%"
  height="600"
  frameborder="0"
/>
```

<Warning>
  Tokens expire after 30 minutes. If you receive a `TOKEN_EXPIRED` error, generate a new token using `POST /v1/embed/token`.
</Warning>
