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

# Merchant feed for cashback and affiliate sites

> One script that pulls every Fluz merchant, its cashback rate and your referral link, ready to list on your site.

If you run a cashback, coupon or deals site, this page is all you need to list Fluz merchants. You copy four values, run one script, and get a file with every merchant, its cashback rate and a link that credits new members to you.

The script works for personal and business Fluz accounts. Run it once a day.

## What you get

One entry per merchant:

```json theme={null}
{
  "name": "Kohl's",
  "slug": "kohls",
  "cashback": 6,
  "logo_url": "https://storage.googleapis.com/.../kohls-logo.jpg",
  "categories": ["Retail"],
  "link": "https://fluz.app/store/kohls?referred_by=YOURCODE"
}
```

| Field | What it is |
| :- | :- |
| `name` | Merchant name to show on your site |
| `slug` | Fluz's ID for the merchant. It doesn't change, so you can match merchants day to day. |
| `cashback` | The best cashback rate Fluz offers at the merchant, in percent. `6` means up to 6%. |
| `logo_url` | Merchant logo, or `null` |
| `categories` | Shopping categories, such as Dining or Travel. Can be empty. |
| `link` | The merchant's page on fluz.app with your referral code. Use it as the outbound link. |

## Before you start

You need four values. All of them come from your Fluz account.

| Value | Where to get it |
| :- | :- |
| **API Key** | Log in at [fluz.app/for-developers](https://fluz.app/for-developers), create an application, and open it. |
| **User ID** | Same page as the API Key |
| **Account ID** | Same page as the API Key |
| **Referral code** | On fluz.app, open **Maximize** > **Invite a friend** and select **Copy**. |

> [!WARNING]
>
> Create the application at **fluz.app/for-developers**. An application created in the sandbox (`uni.staging.fluzapp.com`) has a different key, and the live API rejects it with `Error verifying API basic token`.

## Run the feed

> [tab] PHP
>
> Save this as `fluz-feed.php`, paste your four values at the top, and run `php fluz-feed.php`. It writes `fluz-feed.json` next to the script. Needs PHP 7.4 or newer with the curl extension.
>
> ```php fluz-feed.php theme={null}
> <?php
> // Fluz merchant feed: every Fluz merchant with its cashback rate and your referral link.
> // Run it once a day, for example from cron. Needs PHP 7.4 or newer with the curl extension.
>
> $API_KEY       = 'YOUR_API_KEY';        // fluz.app/for-developers > your app > API Key
> $USER_ID       = 'YOUR_USER_ID';        // same page
> $ACCOUNT_ID    = 'YOUR_ACCOUNT_ID';     // same page
> $REFERRAL_CODE = 'YOUR_REFERRAL_CODE';  // fluz.app > Maximize > Invite a friend
>
> const FLUZ_API = 'https://transactional-graph.fluzapp.com/api/v1/graphql';
>
> function fluz($auth, $query, $variables = [])
> {
>     $ch = curl_init(FLUZ_API);
>     curl_setopt_array($ch, [
>         CURLOPT_POST           => true,
>         CURLOPT_RETURNTRANSFER => true,
>         CURLOPT_TIMEOUT        => 60,
>         CURLOPT_HTTPHEADER     => ['Authorization: ' . $auth, 'Content-Type: application/json'],
>         CURLOPT_POSTFIELDS     => json_encode(['query' => $query, 'variables' => $variables]),
>     ]);
>     $body   = curl_exec($ch);
>     $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
>     if ($body === false) {
>         throw new Exception('Request failed: ' . curl_error($ch));
>     }
>     curl_close($ch);
>     $json = json_decode($body, true);
>     if ($status !== 200 || !empty($json['errors'])) {
>         throw new Exception("Fluz API error (HTTP $status): $body");
>     }
>     return $json['data'];
> }
>
> // 1. Get an access token with your API key.
> $data = fluz('Basic ' . $API_KEY,
>     'mutation ($userId: UUID, $accountId: UUID, $scopes: [ScopeType!]!) {
>        generateUserAccessToken(userId: $userId, accountId: $accountId, scopes: $scopes) { token }
>      }',
>     ['userId' => $USER_ID, 'accountId' => $ACCOUNT_ID, 'scopes' => ['LIST_OFFERS']]
> );
> $token = $data['generateUserAccessToken']['token'];
>
> // 2. Read the catalog 20 merchants at a time until a page comes back empty.
> $query = 'query ($paginate: OffsetInput, $offerTypes: OfferTypesInput) {
>   getMerchants(paginate: $paginate, offerTypes: $offerTypes) {
>     name
>     slug
>     logoUrl
>     categories { name }
>     offers { offerRates { maxUserRewardValue } }
>   }
> }';
>
> $feed = [];
> for ($offset = 0; ; $offset += 20) {
>     $page = fluz('Bearer ' . $token, $query, [
>         'paginate'   => ['limit' => 20, 'offset' => $offset],
>         'offerTypes' => ['giftCardOffer' => true, 'cardLinkedOffer' => false],
>     ])['getMerchants'];
>
>     if (empty($page)) {
>         break;
>     }
>
>     foreach ($page as $m) {
>         // A merchant can have more than one offer. List its best rate.
>         $rate = 0;
>         foreach ($m['offers'] ?? [] as $offer) {
>             foreach ($offer['offerRates'] ?? [] as $r) {
>                 $rate = max($rate, (float) $r['maxUserRewardValue']);
>             }
>         }
>
>         $feed[] = [
>             'name'       => $m['name'],
>             'slug'       => $m['slug'],
>             'cashback'   => $rate,
>             'logo_url'   => $m['logoUrl'],
>             'categories' => array_column($m['categories'] ?? [], 'name'),
>             'link'       => 'https://fluz.app/store/' . $m['slug'] . '?referred_by=' . rawurlencode($REFERRAL_CODE),
>         ];
>     }
> }
>
> // 3. Save the feed. Your site reads this file.
> file_put_contents(__DIR__ . '/fluz-feed.json', json_encode($feed, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
> echo count($feed) . " merchants saved to fluz-feed.json\n";
> ```

> [tab] curl
>
> Use these two requests from any language. Both go to the same URL:
>
> ```text theme={null}
> POST https://transactional-graph.fluzapp.com/api/v1/graphql
> ```
>
> **1. Get an access token.** Send your API Key exactly as it appears in the console. It is already encoded.
>
> ```bash theme={null}
> curl -X POST https://transactional-graph.fluzapp.com/api/v1/graphql \
>   -H "Authorization: Basic YOUR_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "query": "mutation ($userId: UUID, $accountId: UUID, $scopes: [ScopeType!]!) { generateUserAccessToken(userId: $userId, accountId: $accountId, scopes: $scopes) { token } }",
>     "variables": { "userId": "YOUR_USER_ID", "accountId": "YOUR_ACCOUNT_ID", "scopes": ["LIST_OFFERS"] }
>   }'
> ```
>
> Copy `data.generateUserAccessToken.token` from the response.
>
> **2. Get merchants, 20 at a time.** Start with `offset` 0. Add 20 and repeat until `getMerchants` is an empty list `[]`.
>
> ```bash theme={null}
> curl -X POST https://transactional-graph.fluzapp.com/api/v1/graphql \
>   -H "Authorization: Bearer ACCESS_TOKEN" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "query": "query ($paginate: OffsetInput, $offerTypes: OfferTypesInput) { getMerchants(paginate: $paginate, offerTypes: $offerTypes) { name slug logoUrl categories { name } offers { offerRates { maxUserRewardValue } } } }",
>     "variables": { "paginate": { "limit": 20, "offset": 0 }, "offerTypes": { "giftCardOffer": true, "cardLinkedOffer": false } }
>   }'
> ```
>
> For each merchant, use the highest `maxUserRewardValue` as its cashback rate, and build its link:
>
> ```text theme={null}
> https://fluz.app/store/{slug}?referred_by={your referral code}
> ```

## Check it

1. Open `fluz-feed.json` and check that it lists merchants with rates.
2. Open one `link` in a private browser window. It should land on that merchant's page on fluz.app.
3. Check that the code at the end of the link matches your referral code exactly, including uppercase and lowercase letters. A wrong code shows no error, and the signup isn't credited to you.

## Keep it current

* Run the script once a day, for example from cron. Fluz updates the catalog twice a day, and rates change often.
* The access token is short-lived. The script gets a new one each time it runs, so you never have to manage it.
* Merchant slugs don't change when rates change, so links you've already published keep working.

## If it doesn't work

> [accordion] Error verifying API basic token
>
> The API Key isn't accepted. Check that:
>
> * You created the application at **fluz.app/for-developers**, not in the sandbox.
> * You pasted the API Key whole, exactly as shown. Don't encode it again.
> * The key wasn't regenerated. A regenerated key replaces the old one right away.
> * The User ID and Account ID come from the same application as the key.

> [accordion] The feed has merchants but a rate of 0
>
> Some merchants have no rate at the moment. Skip them on your site, or show them without a rate. They are back in the feed when a rate returns.

> [accordion] Signups from my links aren't credited to me
>
> Credit is given only when the person creates a **new** Fluz account in the same browser where they opened your link. Check that your referral code in the link matches your code in Fluz exactly. See [How referral credit works](https://docs.fluz.app/formatting-referral-links.md#how-referral-credit-works).

> [accordion] The script stops partway through
>
> The script stops on any error and prints the response from Fluz. Run it again. If the same error repeats, send that message to your Fluz contact.

## More detail

* [Referral links](https://docs.fluz.app/formatting-referral-links.md): every link format, and how referral credit works
* [Get catalog](https://docs.fluz.app/get-gift-card-merchant-catalog.md): every field and filter on `getMerchants`
* [API credentials](https://docs.fluz.app/get-started/api-credentials.md): how access tokens work


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.