Understanding Connect-headless

Connect-headless is an HTTP API with a single endpoint that behaves similarly to a chatbot:

In this article, Connect-headless is referred to simply as Connect.
  1. 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.
  2. 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.
  3. 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.
  4. 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

  1. 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.

  2. 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

1

Create a Connect Token

This step shall be implemented in your back-end.

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.

2

Start session

We recommend that you implement this step in your front-end.

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

We recommend that you implement this step in your back-end.

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_idIdentifies your customer in FlatPeak systems.
location_idIdentifies 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.

If you find it challenging to implement Connect using this guide, get in touch with our support team. We’d be glad to help!