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

# Integrate tariff connection into your app

Flatpeak Connect is the customer-facing entry point to the Flatpeak platform. It allows your app to enable customers to link their electricity tariff, so your backend can access energy prices.

<Card title="View Quickstart" icon="rocket" horizontal href="/quickstart">
  New to Flatpeak? Start with the Quickstart guide before continuing.
</Card>

Connect can be integrated in two main ways:

* Clone our reference implementation and embed it into your app via **WebView**.
* Build the necessary pages in your app using preferred framework and the Flatpeak **API** (recommended).

<Tabs>
  <Tab title="WebView integration">
    Use this guide to integrate Flatpeak’s Connect into your app by embedding it via WebView.

    <Frame>
      <img src="https://mintcdn.com/flatpeak/TQaxvXRAD8Q-IDz9/images/anode/connect/connect-web-flow.png?fit=max&auto=format&n=TQaxvXRAD8Q-IDz9&q=85&s=9f30a08f27ff1b7ae45722d84a349579" alt="WebView" width="4164" height="2364" data-path="images/anode/connect/connect-web-flow.png" />
    </Frame>

    <Steps>
      <Step title="Download Connect web app">
        Clone our repo and install the required dependencies

        ```bash theme={"system"}
        git clone https://github.com/flat-peak/flatpeak-connect-web.git
        cd flatpeak-connect-web
        npm install
        ```

        You will need to host the web app on your servers for production.

        For now, you can simply run it on your computer.
      </Step>

      <Step title="Configure environment variables">
        ```bash theme={"system"}
        export FLATPEAK_CONNECT_URL=https://connect.flatpeak.com
        ```

        Ensure this is set correctly for your environment. Adjust for Windows-based shells if needed.
      </Step>

      <Step title="Test run the Connect app">
        ```bash theme={"system"}
        npm run dev
        ```

        A local preview will be available at [http://localhost:7070](http://localhost:7070).

        <Frame>
          <img src="https://mintcdn.com/flatpeak/-Ak0AVMaQzkfm1jo/images/connect-web-local-clean.png?fit=max&auto=format&n=-Ak0AVMaQzkfm1jo&q=85&s=1a5f6c5bf0167b381612c1fa230694d5" alt="" width="1136" height="280" data-path="images/connect-web-local-clean.png" />
        </Frame>

        You will see an error. This is because you have not provided a Connect token. Ignore the error for now and continue following this guide.
      </Step>

      <Step title="Subscribe to Connect session events">
        Your system needs to be notified when a customer completes the Connect flow so it can start retrieving their electricity prices and using other energy intelligence endpoints.

        <Frame>
          <img src="https://mintcdn.com/flatpeak/TQaxvXRAD8Q-IDz9/images/anode/dashboard/dashboard-webhooks.png?fit=max&auto=format&n=TQaxvXRAD8Q-IDz9&q=85&s=e426f78778cf2edc720c15544496399e" alt="Flatpeak Dashboard Webhooks" className="block dark:hidden" width="2738" height="1686" data-path="images/anode/dashboard/dashboard-webhooks.png" />

          <img src="https://mintcdn.com/flatpeak/TQaxvXRAD8Q-IDz9/images/anode/dashboard/dashboard-webhooks.png?fit=max&auto=format&n=TQaxvXRAD8Q-IDz9&q=85&s=e426f78778cf2edc720c15544496399e" alt="Flatpeak Dashboard Webhooks" className="hidden dark:block" width="2738" height="1686" data-path="images/anode/dashboard/dashboard-webhooks.png" />
        </Frame>

        Subscribe to `connect_session.complete` events via a webhook:

        1. Open [Flatpeak Dashboard](https://dashboard.flatpeak.com/)
        2. Select **Webhooks** in the main menu
        3. In **Endpoint URL**, enter the address where you want to receive webhook events
        4. Click **Events** and select `connect_session.complete`
        5. Set the selector to **Live data** or **Test data**, depending on API key you are using
        6. Click **Create** to start sending events to your webhook destination
      </Step>

      <Step title="Create a Connect token">
        <Info>
          Single-use Connect tokens enable secure access to Connect API endpoints while keeping API keys away from the frontend.
        </Info>

        1. First, authenticate to the API by calling [authentication](/api-reference/anode/authentication) endpoint.
        2. Next, call the [create-connect-token](/api-reference/anode/connect/create-a-connect-token) endpoint to create a `connect_token`.

        <CodeGroup>
          ```json Request example theme={"system"}
          curl --request POST \
          --url https://api.flatpeak.com/connect/token \
          --header 'Authorization: Bearer <bearer_token>' \
          --header 'Content-Type: application/json' \
          --data '{
            "connect_url": "<URL to return from external resources back to your app>",
            "callback_url": "<URL to redirect after Connect flow completes>",
            "postal_address": {
              "address_line1": "1-3",
              "address_line2": "Strand",
              "city": "London",
              "state": "Greater London",
              "post_code": "WC2N 5EH",
              "country_code": "GB"
            }
          }'
          ```

          ```json Response example theme={"system"}
          {
            "connect_token": "cot_6587fa4362341be5b524de3b",
            "expires_in": "86400"
          }
          ```
        </CodeGroup>
      </Step>

      <Step title="Launch the Connect app">
        In your browser, open: `http://localhost:7070?fp_cot=cot_***`, replacing `cot_***` with the `connect_token`:

        <Frame>
          <img src="https://mintcdn.com/flatpeak/TQaxvXRAD8Q-IDz9/images/anode/connect/connect-local-uri-build.png?fit=max&auto=format&n=TQaxvXRAD8Q-IDz9&q=85&s=096e3be6be3d680371c485e1519af1f1" alt="" width="1136" height="280" data-path="images/anode/connect/connect-local-uri-build.png" />
        </Frame>

        In production, customers will launch Connect directly from your app. Your backend should create Connect tokens on demand and pass them to the app.
      </Step>

      <Step title="Customer will interact with Connect flow">
        Connect guides customers through a short flow to share their tariff. It automatically chooses the best method based on provider APIs, data-sharing rules, and usage patterns across Flatpeak.

        <Frame>
          <img src="https://mintcdn.com/flatpeak/TQaxvXRAD8Q-IDz9/images/anode/connect/connect-micro-flow.png?fit=max&auto=format&n=TQaxvXRAD8Q-IDz9&q=85&s=4a1009d232fc937d4389be6ec0cafedd" alt="" width="1578" height="852" data-path="images/anode/connect/connect-micro-flow.png" />
        </Frame>

        <Tip>
          To test Connect flow, use your own account from any supported energy provider. If you don’t have access to one, contact [support](https://dashboard.flatpeak.com/#support) for a test account.
        </Tip>

        <Info>
          Learn more about [Connect flow architecture](/guides/connect/architecture), [markets](/guides/sources/market-rates) and [provider integrations coverage](/guides/sources/providers).
        </Info>
      </Step>

      <Step title="Handle session completion">
        1. When the customer successfully completes a session with Connect, you will receive a webhook to the destination you specified earlier:

        ```json Example webhook payload theme={"system"}
        {
          "id": "evt_66167787c1652b3fbeba5f01",
          "object": "event",
          "type": "connect_session.complete",
          "data": {
            "id": "cot_6587fa4362341be5b524de3b",
            "object": "connect_token",
            "location_id": "loc_641b90b758fb8e6293716e40",
            "price_available": true

          }
        }
        ```

        2. The `location_id` is a permanent identifier for your customer’s address. Store it in your database as a reference to the customer’s address. You will use it to fetch electricity prices and access other energy intelligence endpoints. You can also re-request this ID by calling [retrieve-connect-token](/api-reference/anode/connect/retrieve-a-connect-token) endpoint.

        <CodeGroup>
          ```bash Request example theme={"system"}
          curl --request GET \
          --url 'https://api.flatpeak.com/connect/token?connect_token=cot_6587fa4362341be5b524de3b' \
          --header 'Authorization: Bearer <token>'
          ```

          ```json Response example theme={"system"}
          {
          "id": "cot_6587fa4362341be5b524de3b",
          "object": "connect_token",
          "location_id": "loc_641b90b758fb8e6293716e40"
          }
          ```
        </CodeGroup>
      </Step>

      <Step title="Provide an option for customers to change tariff connection">
        To enable customers to modify or remove their tariff connection, see the [Tariff Settings Page](/guides/connect/settings-page) guide. It explains how to build UI controls that let them view, reconnect, disconnect, or adjust their tariff — including connecting an export tariff.

        <Info>
          In short, you’ll need to implement passing the `location_id` when creating Connect tokens. This will launch Connect in the context of the existing tariff connection for that location.
        </Info>
      </Step>
    </Steps>

    ### Tip for embedding

    When embedding Connect in your app, launch it in a modal or bottom sheet ([iOS](https://developer.apple.com/design/human-interface-guidelines/sheets)/[Android](https://m3.material.io/components/bottom-sheets/guidelines)) to prevent layout issues—especially on devices with notches or cutouts.

    <Frame>
      <img src="https://mintcdn.com/flatpeak/-Ak0AVMaQzkfm1jo/images/modal.png?fit=max&auto=format&n=-Ak0AVMaQzkfm1jo&q=85&s=a126e943bcdc8acaf2549afb1ee95f10" style={{ width:"250px" }} width="489" height="231" data-path="images/modal.png" />
    </Frame>

    This will keep the interface clean and ensure all elements remain visible.
  </Tab>

  <Tab title="API integration">
    Use this guide to integrate Flatpeak’s Connect into your app using your preferred framework.

    <Frame>
      <img src="https://mintcdn.com/flatpeak/TQaxvXRAD8Q-IDz9/images/anode/connect/connect-api-flow.png?fit=max&auto=format&n=TQaxvXRAD8Q-IDz9&q=85&s=70ad16c6a217fa56255f678382e7755d" alt="Native" width="4164" height="2364" data-path="images/anode/connect/connect-api-flow.png" />
    </Frame>

    Connect uses JSON-based session conversation, rather than standard REST request/response.

    <Warning>
      Make sure to complete [Quickstart](/quickstart) before following this guide. It provides **necessary** context on how the Connect works and what to expect during this integration.
    </Warning>

    <Steps>
      <Step title="Subscribe to Connect session events">
        Your system needs to be notified when a customer completes the Connect flow so it can start retrieving their electricity prices and interacting with other energy intelligence endpoints.

        <Frame>
          <img src="https://mintcdn.com/flatpeak/TQaxvXRAD8Q-IDz9/images/anode/dashboard/dashboard-webhooks.png?fit=max&auto=format&n=TQaxvXRAD8Q-IDz9&q=85&s=e426f78778cf2edc720c15544496399e" alt="Flatpeak Dashboard Webhooks" className="block dark:hidden" width="2738" height="1686" data-path="images/anode/dashboard/dashboard-webhooks.png" />

          <img src="https://mintcdn.com/flatpeak/TQaxvXRAD8Q-IDz9/images/anode/dashboard/dashboard-webhooks.png?fit=max&auto=format&n=TQaxvXRAD8Q-IDz9&q=85&s=e426f78778cf2edc720c15544496399e" alt="Flatpeak Dashboard Webhooks" className="hidden dark:block" width="2738" height="1686" data-path="images/anode/dashboard/dashboard-webhooks.png" />
        </Frame>

        To do this, subscribe to a webhook that delivers `connect_session.complete` events:

        1. Open [Flatpeak Dashboard](https://dashboard.flatpeak.com/)
        2. Select **Webhooks** in the main menu
        3. In **Endpoint URL**, enter the address where you want to receive webhook events
        4. Click **Events** and select `connect_session.complete`
        5. Set the selector to **Live data** or **Test data**, depending on API key you are using
        6. Click **Create** to start sending events to your webhook destination
      </Step>

      <Step title="Create a Connect token">
        <Info>
          Single-use Connect tokens provide secure access to Connect API endpoints while keeping API keys away from the frontend.
        </Info>

        1. First, authenticate to the API by calling [authentication](/api-reference/anode/authentication) endpoint.
        2. Next, call the [create-connect-token](/api-reference/anode/connect/create-a-connect-token) endpoint to create a `connect_token`.

        <CodeGroup>
          ```json Request example theme={"system"}
          curl --request POST \
          --url https://api.flatpeak.com/connect/token \
          --header 'Authorization: Bearer <bearer_token>' \
          --header 'Content-Type: application/json' \
          --data '{
            "connect_url": "<URL where the Connect app is hosted, http://localhost:7070 in this example>",
            "callback_url": "<URL to redirect after Connect flow completes>",
            "postal_address": {
              "address_line1": "1-3",
              "address_line2": "Strand",
              "city": "London",
              "state": "Greater London",
              "post_code": "WC2N 5EH",
              "country_code": "GB"
            }
          }'
          ```

          ```json Response example theme={"system"}
          {
            "connect_token": "cot_6587fa4362341be5b524de3b",
            "expires_in": "86400"
          }
          ```
        </CodeGroup>
      </Step>

      <Step title="Implement the Connect flow">
        Call the [start-connect-session](/api-reference/anode/connect/start-a-connect-session) endpoint to begin the Connect flow.

        The response will be one of the predefined pages listed under **Connect** > **Required pages** in the API Reference.

        Your app must provide a customer action that starts the Connect flow when they want to connect their tariff. It must also support handling **all** required pages.

        <Info>
          For guidance on implementing tariff controls in your app, see the [Tariff Settings Page](/guides/connect/settings-page) guide.
        </Info>
      </Step>

      <Step title="Handle session completion">
        1. When the customer successfully completes a session with Connect you will receive a webhook to the destination you specified earlier:

        ```json Example webhook payload theme={"system"}
        {
          "id": "evt_66167787c1652b3fbeba5f01",
          "object": "event",
          "type": "connect_session.complete",
          "data": {
            "id": "cot_6587fa4362341be5b524de3b",
            "object": "connect_token",
            "location_id": "loc_641b90b758fb8e6293716e40",
            "price_available": true

          }
        }
        ```

        2. The `location_id` is a permanent identifier for your customer’s address. Store it in your database as a reference to the customer’s address. You will use it to fetch electricity prices and access other energy intelligence endpoints. You can also re-request this ID by calling [retrieve-connect-token](/api-reference/anode/connect/retrieve-a-connect-token) endpoint.

        <CodeGroup>
          ```bash Request example theme={"system"}
          curl --request GET \
          --url 'https://api.flatpeak.com/connect/token?connect_token=cot_6587fa4362341be5b524de3b' \
          --header 'Authorization: Bearer <token>'
          ```

          ```json Response example theme={"system"}
          {
          "id": "cot_6587fa4362341be5b524de3b",
          "object": "connect_token",
          "location_id": "loc_641b90b758fb8e6293716e40"
          }
          ```
        </CodeGroup>
      </Step>

      <Step title="Provide an option for customers to change tariff connection">
        To enable customers to modify or remove their tariff connection, see the [Tariff Settings Page](/guides/connect/settings-page) guide. It explains how to build UI controls that let them view, reconnect, disconnect, or adjust their tariff — including connecting an export tariff.

        <Info>
          In short, you’ll need to implement passing the `location_id` when creating Connect tokens. This will launch Connect in the context of the existing tariff connection for that location.
        </Info>
      </Step>
    </Steps>
  </Tab>
</Tabs>

## Next steps

Your systems can now access:

* [Energy prices](/guides/connect/retrieve-price)
* Energy [scheduling](/guides/schedule)
* Energy [cost calculation](/guides/calculate)
