Native app or server-side Tutorial
In this tutorial, we will learn how to integrate the JSON version of Connect, the Connect-headless into your application to get consent from your customers to access their energy tariffs.
Understanding Connect-headless
Connect-headless (hereafter Connect) is an HTTP-POST service that uses JSON objects to carry the payload. As a developer, you can consider it to be a chatbot that uses pre-created pages (aka routes) instead of free text messages to build user flows.
Every time you send a request to Connect’s sole HTTP endpoint, it will respond with instructions to render a page where your customer will make a selection from a list of options or input new data. You will capture your customer’s responses and submit them to the same HTTP endpoint.
This flow continues for as long as necessary to discover or connect to your customer’s tariff. Once completed you will receive a permanent location identifier that you can use to query your customer’s tariff from FlatPeak API.
Follow the instructions below to learn how to implement Connect in your application:
Obtain a Connect token
You need a connect_token
to start a session with Connect.
Connect Tokens are single-use objects that identify and secure your user’s session with Connect. Every time you want to start a new Connect session for your customer (i.e. your app’s user), you need to create a new connect_token
.
Authenticate to FlatPeak API
To create a connect token you need to make a request to create-conect-token API endpoint. Learn how to authenticate to FlatPeak API, follow the authorization-guide.
Create a Connect token
Go to create-connect-token API endpoint and create a connect_token
.
callback_uri
to any page that can accept callbacks. Our team likes https://webhook.site but you can choose any other service.Run Connect-headless flow
Once you obtained the connect_token
, you can start exploring the Connect HTTP service.
curl --request POST \
--url https://connect.flatpeak.com \
--header 'Content-Type: application/json' \
--data '{
"route": "session_restore",
"connect_token": "cot_65df3e949a785c52283026ec"
}'
Connect will respond with any of the following JSON objects, each representing the content of a page that you will render in your app.
Obtain IDs to access customer’s tariff
Using connect_token
as a reference, call exchange-connect-token API endpoint to get permanent identifiers that you will use to obtain your customer’s tariff.
customer_id | Identifies your customer in FlatPeak systems. |
location_id | Identifies the physical location where energy is supplied under an agreement between your customer and their provider. |
Store both IDs in your application’s database in reference to your customer and the physical location of their property.
Make requests to tariff rates API endpoint
Requesting tariff rates
You can now make requests to tariff-rates and other API endpoints using location_id
as a reference.
Handling pending tariff connection
If FlatPeak background service is unable to immediately access your customer’s tariff (for example if energy provider systems are down or if FlatPeak provider integration is unable to parse the tariff) you will receive a 422 error
response from the API.
Continue to make the API calls, the error will usually clear itself in minutes. If this does not happen, FlatPeak engineer will resolve the issue behind the scenes; no action is required.
{
"object": "error",
"type": "api_error",
"live_mode": true,
"time_created": "2022-01-24T14:15:22.003",
"code": "pending_connect",
"message": "Connect is processing link to tariff source."
}
Was this page helpful?