WebView implementation
Get up and running fast with our open-source reference implementation of FlatPeak API for your app. Clone, embed into your app view WebView and deploy in hours.
Clone our repo and install the required dependencies
Set the environment variables
Run locally
A local preview will be available at http://localhost:7070
.
Your browser will redirect to an error page. This is because you have not provided a Connect token. Ignore this error and continue following this guide.
Obtain a token to access Connect
FlatPeak implements a single-use session token to provide access to Connect API endpoints, so you don’t need to expose API keys to your customer-facing app
-
Get bearer token from create-a-bearer-token endpoint.
-
Make a request to create-connect-token to obtain a connect token endpoint.
Run the app
On your computer, where you already have FlatPeak connect code running locally, open: http://localhost:7070?fp_cot=cot_***
. Replace **cot_ with the connect_token
. The resulting URI may look similar to this example:
Follow the flow
Connect will present you with a set of pages that will let you share your tariff information. It automatically chooses the best route to discover your tariff based on the availability of provider APIs, data-sharing regulations and frequency of provider use within the FlatPeak base.
Receive and process callback
Once click Save button on Your Tariff Summary** screen, Connect will send the following to callback_uri
you specified:
Exchange completed Connect token for Location ID
Once you receive a callback and use connect_token
as a reference, call the exchange-connect-token API endpoint to obtain a location_id
that represents a permanent identifier of your customer’s address in FlatPeak. Store it in your database as a reference to the physical location of your customer’s property.
Subscribe to tariff lifecycle webhooks
After your customer completes the Connect flow, FlatPeak will automatically keep their tariff information up to date. If any action is required from the customer, FlatPeak will generate an event. You should subscribe to these events via webhooks and implement a communication flow to notify your customers and let them update their tariff connection if necessary.
Let customers view their tariff and change connection
Customers may need to manually notify you when they change energy providers. They’ll also need a place in your app to take action when you inform them about a tariff connection event received via webhook. To support these scenarios, follow the Building a tariff settings page in your app guide to add controls that let them update or reconnect their energy account.
Next steps
You can now query the FlatPeak API for your customer’s tariff data and access all other energy intelligence endpoints.
Choose from two different integration paths for this step: