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

# Using Rewards with the Connect Widget

The MX Connect Widget is a ready-made user interface that allows developers to quickly add members to Platform and navigate the multifactor authentication process. It can also be used to manage and resolve connection errors, and it even works with various premium features, such as rewards.

Connecting to an institution in rewards mode will gather rewards information for the `member`, as well as associated account and transaction data.

This guide assumes you are following MX's recommendation to use the Connect Widget. If your use case requires you to use API endpoints only, see our [separate guide on this type of integration](https://docs.mx.com/api-reference/rewards/overview/fetching-rewards/fetch-rewards-api.md).

## Prerequisites

Before you follow the steps in this guide make sure that you have:

1. Signed up for the Platform API and [received your development API Keys](https://dashboard.mx.com).
2. Integrated the Connect Widget into your application or website. The best way to do this is to use one of the widget SDKs mentioned in [Integration Guides](https://docs.mx.com/connect/guides/) that MX has created for this purpose.
3. Ensure MX has enabled rewards.

## 1. Create a User

A user represents your end user in the MX Platform. Make a POST request to the `/users` endpoint, as shown below.

We recommend that you include a unique [`id`](https://docs.mx.com/api-reference/platform-api/v20260929/overview/requests-and-responses#identifiers-and-metadata) of your choice with the request. You may also include `metadata`, such as the date the `user` was created or the end user's name. Don't include any sensitive information here, such as credentials.

None of these parameters are required, but the `user` object cannot be empty. We recommend that partners always set the `id` parameter when creating a user.

In the response, the API gives each new `user` an MX-defined `guid` (or `user_guid` when appearing outside the `user` object). Between your `id` and the `guid`, you can map between your system and ours. You'll need the user `guid` for nearly every request on the MX API, at least when using basic authorization.

```shell Request theme={null}
curl -i -X POST 'https://int-api.mx.com/users' \
-u 'client_id:api_key' \
-H 'Accept: application/vnd.mx.api.v1+json' \
-H 'Content-Type: application/json' \
-d '{
  "user": {
    "email": "test@mx.com",
    "id": "My-Test-ID",
    "is_disabled": false,
    "metadata": "{\\\"type\\\": \\\"individual\\\", \\\"status\\\": \\\"preferred\\\"}"
  }
}`
```

```json Response theme={null}
{
    "user": {
        "did": null,
        "guid": "USR-d60dcf31-e14a-489a-a67a-9476534849c6",
        "id": "My-Test-ID",
        "email": "test@mx.com",
        "is_disabled": false,
        "metadata": "{\\\"type\\\": \\\"individual\\\", \\\"status\\\": \\\"preferred\\\"}"
    }
}
```

## 2. Request a Connect Widget URL

There are many configuration options for the Connect Widget for performing various tasks. Use the following information to configure the Connect Widget for rewards.

Make a POST request to the `/users/{user_guid}/widget_urls` endpoint.

* In the path, set the `user_guid` to the value for the user you created in step 1.
* In the body:

  * Set the `widget_type` parameter to `connect_widget`
  * Set the `mode` to `reward`

The response will contain a URL to Connect Widget which you will load in the next step.

```shell Request theme={null}
curl -L -X POST 'https://int-api.mx.com/users/:user_guid/widget_urls' \
-H 'Content-Type: application/json' \
-H 'Accept: application/vnd.mx.api.v1beta+json' \
-H 'Authorization: Basic BASE_64_ENCODING_OF{client_id:api_key}' \
--data-raw '{
  "widget_url": {
    "widget_type": "connect_widget",
    "client_redirect_url": "https://mx.com",
    "color_scheme": "light",
    "current_institution_code": "mxbank",
    "current_institution_guid": "INS-f1a3285d-e855-b61f-6aa7-8ae575c0e0e9",
    "current_member_guid": "MBR-7c6f361b-e582-15b6-60c0-358f12466b4b",
    "disable_background_agg": false,
    "disable_institution_search": false,
    "enable_app2app": false,
    "include_identity": false,
    "include_transactions": true,
    "is_mobile_webview": false,
    "mode": "reward",
    "oauth_referral_source": "BROWSER",
    "ui_message_version": 4,
    "ui_message_webview_url_scheme": "mx",
    "update_credentials": false
  }
}'
```

```json Response theme={null}
{
    "widget_url": {
        "url": "https://int-widgets.moneydesktop.com/md/connect/rxvmt33qq211phfmz3mA8gqqq3Zcv35A605f70zzp4rsjbmgy467ks1qtlpnzzddc7w7cdx77zdjd3hm9kc2brqpl1vtzdsgm1wj1b2gkj3616bt4mm1dj2hAgAx3Aplgm8AjA02hf3mm6xq3h4v2g0d7fv7hjjp19qx3hx088ld2ct4hm7ywl7rtxA9gg8yshv42glf89nhq8zv08ngxzb01qz66ljnIiwiY3VycmVudF9tZW1iZXJfZ3VpZCI6Ik1CUi03YzZmMzYxYi1lNTgyLTE1YjYtNjBjMC0zNThmMTI0NjZiNGIiLCJkaXNhYmxlX2JhY2tncm91bmRfYWdnIjpmYWxzZSwiZGlzYWJsZV9pbnN0aXR1dGlvbl9zZWFyY2giOmZhbHNlLCJlbmFibGVfYXBwMmFwcCI6ZmFsc2g5AAd2nrvrh16rzbAfxz0yk4646745sppqmsqv64mc8gsdgwvwb1xlf78yw43vty0ny4xghx8mdrm9dncnl0vwh9g074g5s657gp1yzA5A3ylrb3kn6m6617l7vgknwmjx9jlxx5/eyJ1aV9tZXNzYWdlX3ZlcnNpb24iOjQsInVpX21lc3NhZ2Vfd2Vidmlld191cmxfc2NoZW1lIjoibXgiLCJjb2xvcl9zY2hlbWUiOiJsaWdodCIsImlzX21vYmlsZV93ZWJ2aWV3IjpmYWxzZSwiY2xpZW50X3JlZGlyZWN0X3VybCI6Imh0dHBzOi8vbXguY29tIiwiY3VycmVudF9pbnN0aXR1dGlvbl9jb2RlIjoiY2hhc2UiLCJjdXJyZW50X2luc3RpdHV0aW9uX2d1aWQiOiJJTlMtZjFhMzI4NWQtZTg1NS1iNjFmLTZhYTctOGFlNTc1YzBlMGU5UsImluY2x1ZGVfaWRlbnRpdHkiOmZhbHNlLCJpbmNsdWRlX3RyYW5zYWN0aW9ucyI6dHJ1ZSwibW9kZSI6InJld2FyZCIsIm9hdXRoX3JlZmVycmFsX3NvdXJjZSI6IkJST1dTRVIiLCJ1cGRhdGVfY3JlZGVudGlhbHMiOmZhbHNlLCJsb2NhbGUiOiJlbi1VUyJ9",
        "type": "connect_widget",
        "user_id": "My-Test-ID"
    }
}
```

## 3. Load the URL and Let the End User Interact

Load the URL in your application or website. At this point the end user will interact with the Connect Widget. The widget handles the creation of a `member` as well as the process and any MFA that may be encountered. It automatically asks end users to search for an institution, give their credentials, or authenticate with OAuth. It also deals with any errors along the way.

You'll need to listen for a couple important [event messages](https://docs.mx.com/connect/widget-events.md) from the Connect Widget:

* [member status updated](https://docs.mx.com/connect/widget-events.md#member-status-update) which gives you the member GUID and the current `connection_status`.
* [member connected](https://docs.mx.com/connect/widget-events.md#member-connected) tells you that the member has been successfully connected and you can move on to the next steps.

Alternatively, if the end user closes the Connect Widget early or some other problem occurs before you see a `CONNECTED` status, you can use the `member_guid` to immediately [check the member's connection status](https://docs.mx.com/api-reference/platform-api/v20260929/reference/members/read-member-status.md) with a dedicated API endpoint.

```shell Request theme={null}
curl -L -X GET 'https://int-api.mx.com/users/USR-d60dcf31-e14a-489a-a67a-9476534849c6/members/MBR-fcc99539-8caa-4a7b-8cb6-8b22ae79662e/status' \
-H 'Accept: application/vnd.mx.api.v1beta+json' \
-H 'Authorization: Basic BASE_64_ENCODING_OF{client_id:api_key}'
```

```json Response theme={null}
{
    "member": {
        "guid": "MBR-fcc99539-8caa-4a7b-8cb6-8b22ae79662e",
        "aggregated_at": "2024-06-03T17:15:21Z",
        "has_processed_account_numbers": false,
        "has_processed_accounts": true,
        "has_processed_transactions": true,
        "is_being_aggregated": false,
        "successfully_aggregated_at": "2024-06-03T17:15:34Z",
        "connection_status": "CONNECTED",
        "is_authenticated": true
    }
}
```

> [!NOTE]
>
> We suggest you add a [Rewards Webhook](https://docs.mx.com/api-reference/rewards/overview/webhook.md). Please reachout to MX to have this enabled. We provide webhooks that send HTTPS POST callback requests to the URL of your choice. This webhook notifies you when any new data is available after a successful rewards fetch. For more information on webhooks, [see our complete reference page](https://docs.mx.com/resources/webhooks).

## 4. List Rewards

Get a list of all rewards data associated with a member by making a GET request to the [list rewards](https://docs.mx.com/api-reference/rewards/overview/fetching-rewards/fetch-rewards-api.md) endpoint.

The response includes an array of rewards which include account numbers, balance, and type. Make note of the `guid` as you can use this to read specific rewards using the [read Rewards](https://docs.mx.com/api-reference/rewards/overview/fetching-rewards/fetch-rewards-api.md) endpoint.

```shell Request theme={null}
curl -L -X GET 'https://int-api.mx.com/users/USR-d60dcf31-e14a-489a-a67a-9476534849c6/members/MBR-fcc99539-8caa-4a7b-8cb6-8b22ae79662e/rewards' \
-H 'Accept: application/vnd.mx.api.v1beta+json' \
-H 'Authorization: Basic BASE_64_ENCODING_OF{client_id:api_key}'

```

```json Response theme={null}
{
  "rewards": [
    {
      "account_guid": "ACT-481fa472-bb3e-47b5-954d-1cd296261d5d",
      "balance_type": "EXPIRING_BALANCE",
      "balance": 102,
      "created_at": "2020-01-28T21:09:01+0000",
      "description": "A description of the reward.",
      "expires_on": "2020-02-28",
      "guid": "RWD-1234",
      "member_guid": "MBR-fcc99539-8caa-4a7b-8cb6-8b22ae79662e",
      "unit_type": "POINTS",
      "user_guid": "USR-d60dcf31-e14a-489a-a67a-9476534849c6"
    }
  ],
  "pagination": {
    "current_page": 1,
    "per_page": 25,
    "total_entries": 1,
    "total_pages": 1
  }
}
```

## 5. Read the Account

Using the `account_guid`, you can also fetch user account details by making a GET request to the [read account](https://docs.mx.com/api-reference/platform-api/v20260929/reference/accounts/read-account.md).

> [!WARNING]
>
> This endpoint also exists outside of the Rewards product. To include rewards data in the response, you must use the beta accept header: \`application/vnd.mx.api.v1beta+json'. If you do not use the correct Accept header, the response will be successful but will not include rewards data.

Notable rewards fields associated with a user's account include:

* `credit_card_product_guid`
* `enrolled_in_rewards_on`
* `primary_reward_unit `
* `current_reward_level`
* `next_reward_level`

```shell Request theme={null}
curl -L -X GET 'https://int-api.mx.com/users/USR-d60dcf31-e14a-489a-a67a-9476534849c6/accounts/ACT-481fa472-bb3e-47b5-954d-1cd296261d5d' \
-H 'Accept: application/vnd.mx.api.v1beta+json' \
-H 'Authorization: Basic BASE_64_ENCODING_OF{client_id:api_key}'

```

```json Response theme={null}
{
  "account_number": "1234567890",
  "apr": null,
  "apy": null,
  "available_balance": 1000,
  "available_credit": null,
  "balance": 1000,
  "cash_balance": null,
  "cash_surrender_value": null,
  "created_at": "2019-06-07T21:16:01Z",
  "credit_card_product_guid": "CCA-b5bcd822-6d01-4e23-b8d6-846a225e714a",
  "credit_limit": null,
  "currency_code": null,
  "current_reward_level": null,
  "day_payment_is_due": null,
  "death_benefit": null,
  "enrolled_in_rewards_on": "2019-06-07",
  "guid": "ACT-481fa472-bb3e-47b5-954d-1cd296261d5d",
  "holdings_value": null,
  "institution_code": "mxbank",
  "interest_rate": null,
  "is_closed": false,
  "last_payment": null,
  "last_payment_at": null,
  "loan_amount": null,
  "matures_on": null,
  "member_guid": "MBR-a4652b66-3ee5-cb9f-295a-72eddef61db5",
  "minimum_balance": null,
  "minimum_payment": null,
  "name": "Test Account 3",
  "next_reward_level": null,
  "original_balance": null,
  "payment_due_at": null,
  "payoff_balance": null,
  "primary_reward_unit": null,
  "started_on": null,
  "subtype": null,
  "total_account_value": null,
  "type": "INVESTMENT",
  "updated_at": "2019-06-07T21:16:01Z",
  "user_guid": "USR-72aba5cc-8c74-b22c-227c-4b1c095fa12e"
}
```

## 6. Read a Credit Card Product

If a rewards account is a credit card, the account details return a `credit_card_product_guid`. Use this `guid` to read more specific credit card details such as `has_cashback_rewards` or `is_accepting_applications`, to help drive next steps for your end users.

```shell Request theme={null}
curl -L -X GET 'https://int-api.mx.com/credit_card_products/CCA-b5bcd822-6d01-4e23-b8d6-846a225e714a' \
-H 'Accept: application/vnd.mx.api.v1beta+json' \
-H 'Authorization: Basic BASE_64_ENCODING_OF{client_id:api_key}'

```

```json Response theme={null}
{
  "reward": {
    "annual_fee": 45,
    "duration_of_introductory_rate_on_balance_transfer": null,
    "duration_of_introductory_rate_on_purchases": null,
    "guid": "CCA-b5bcd822-6d01-4e23-b8d6-846a225e714a",
    "has_cashback_rewards": false,
    "has_other_rewards": true,
    "has_travel_rewards": true,
    "has_zero_introductory_annual_fee": true,
    "has_zero_percent_introductory_rate": false,
    "has_zero_percent_introductory_rate_on_balance_transfer": true,
    "financial_institution": true,
    "is_accepting_applications": true,
    "is_small_business_card": true,
    "name": "Bank Credit Card"
  }
}
```
