Native app or server-side integration
In this tutorial, you will learn how to integrate the “JSON API” version of Connect, the Connect-headless, natively into your application.
Understanding Connect-headless
Connect-headless is an HTTP API with a single endpoint that behaves similarly to a chatbot:
- Your app initiates a Session: Your application begins new “chat” session with Connect by submitting a request containing a
connect_token
to a Connect’s HTTP endpoint. - Your app receives JSON Response object: Connect responds with a JSON object that includes all the information needed to build a page in your app, including supported user actions.
- Customer makes a Selection: Your customer reviews the page and selects one of the actions, you submit their selection to the same HTTP endpoint using the original
connect_token
as session identifier. - Iterative Exchange: Connect returns the next JSON object in response. This cycle repeats until the customer’s tariff is identified and/or connected.
Planning your implementation
-
You implement all JSON page templates: To handle every possible JSON object you may get from Connect, you must implement 14 pages in your app, listed below.
-
Enable Connect to your app: To integrate Connect functionality to your application so your customer to access it when they want to connect their tariff, refer to Displaying Tariff Settings guide.
Starting new session with Connect service
Create a Connect Token
Connect Token is a single-use object that identifies and secures your customer’s session with Connect service, for the duration of that session. To create it, make a request to create-connect-token API endpoint.
Start session
Now that you have a connect_token
, you can start exploring the Connect HTTP service. Make a request to Connect the URL as per the example below:
An attempt to use a Connect token after it expires will result in token_expired
error. See errors for more information.
Implementing Connect pages in your app
When you start a session with Connect service, it will respond with any of the following JSON objects, each representing the content of a page that you will render in your app:
Completing the Connect session
Once the Connect flow has been completed, it will respond with the session-complete
route. The data payload will include your original callback_uri
with the fp_cot
query parameter carrying the original connect_token
.
Return your customer to other pages of your app and follow the next section to exchange connect_token
for a permanent ID that you will use to obtain your customer’s tariff and access their tariff via FlatPeak API.
Exchanging Connect Token for a Location ID
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 location where energy is supplied under an agreement between your customer and their provider. |
Store both IDs in your application’s database, referencing your customer and the physical location of their property.
Was this page helpful?