Open source FlatPeak provider integration module
If you are missing FlatPeak direct integration with your favorite energy provider, you can develop it yourself by following this guide.
Introduction
This document explains how to develop a third-party integration with an energy provider that will be pluggable into FlatPeak backend systems. To make it easier to follow the steps below, we presume you are developing an integration with a provider that supplies your home or business and will refer to it as “your provider.”
The integration scope is designed to be light and only implements the functionality necessary to obtain access to your account with your energy provider and read your tariff.
Prepare the project
Obtain FlatPeak IDs
Before you can start working on the integration, you need to obtain a FlatPeak ID for your provider. If you cannot find your provider in the list, complete this form.
- Login to Dashboard and go to Integrations > Energy Providers.
- Find your provider in the list, and check that it does not have the
Direct
label. - Make note of its FlatPeak ID and Name.
prv_63a6087272941ef077a8fd3e
and PROVIDER_NAME LunarEnergy
in this guide.Clone FlatPeak starter package
Clone provider integration starter template from FlatPeak repository on GitHub:
Prepare your project
Run the following commands to detach your code from the FlatPeak repository, set the required environment variables and install dependencies:
Apply FlatPeak IDs
Search project and replace text placeholders:
Implement integration functions
The scope of FlatPeak provider integration is comprised of three main functions:
- Obtain authorisation to access your account with your energy support (authorise).
- Locate your tariff inside your energy provider’s dashboard and (capture) it.
- Converting this tariff into FlatPeak format (convert).
Typical energy provider integration architecture
You will implement functions in ./modules/provider/index.js
:
Function | Description |
---|---|
authorise | Validates the username and password that you have captured on views/auth_metadata_capture.hbs page where the login form is located. It shall return the status, error message if it occurred and all additional data required to request the tariff, such as access_token or cookies. |
capture | Fetches tariff object from the user account with the provider using values returned by the authorise function. The output of this function shall be a tariff object with a unique reference_id for which you can use anything that uniquely identifies the tariff, such as user account identification with the provider. |
convert | Transforms the tariff object received from the capture function into a FlatPeak tariff object, as defined in Tariff element model. |
Console testing
You may find it helpful to run e2e tests as defined in e2e.test.js
:
- Insert credentials for your energy provider dashboard to
.env
file:
- Run tests:
npm test
Browser testing
Once integration functions are implemented and you can pass console tests, you shall test user flow in the browser. You will need to obtain a valid token to run FlatPeak Connect. Here is how to do it:
Obtain a token to start Connect session
- Grab
account_id
and anyapi_key
from API keys page in the Dashboard
- Create a bearer_token (read more about FlatPeak API authorization here
- Use
bearer_token
to create a connect_token
callback_uri
to any page accepting callbacks. Our team likes https://webhook.site, but you can choose any other service.Bind your provider to Connect session
Run your application
-
Run
npm start
-
In a browser, open: http://localhost:8080/?fp_cot= and append the Connect token you created earlier, i.e.:
-
A Login form should be displayed. Submit username and password for your account with your provider.
- After you submit the correct login credentials, the Sharing consent form should be displayed.
You have now completed the development of FlatPeak third-party provider integration. For the next steps, contact FlatPeak support at support@flatpeak.com.
Was this page helpful?