> ## Documentation Index
> Fetch the complete documentation index at: https://docs.flatpeak.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Import your data to Flatpeak

## Overview

This guide shows how to import your existing energy tariff data into Flatpeak.

Importing enables your customers to benefit from pricing, optimisation, and reporting features immediately—without taking any manual action.

## Implementation

<Steps>
  <Step title="Create Customer object (optional)">
    If your systems maintain a separate reference for customer (i.e., user) objects, independent of their address, you can create a Customer object in Flatpeak to keep your data model aligned. Call the [customer-create](/api-reference/anode/customers/create-a-customer) endpoint and pass your internal customer reference as `reference_id`.

    The response will return a Flatpeak Customer ID (`customer_id`), which you should store and associate with the customer in your systems.

    <CodeGroup>
      ```json Request example theme={"system"}
      curl --request POST \
        --url https://api.flatpeak.com/customers \
        --header 'Authorization: Bearer <token>' \
        --header 'Content-Type: application/json' \
        --data '{
        "reference_id": "CUS1234567890"
      }'
      ```

      ```json Response example theme={"system"}
      {
        "id": "cus_65e421d1daa4a24082b4f590",
        "object": "customer",
        "live_mode": true,
        "reference_id": "CUS1234567890"
      }
      ```
    </CodeGroup>
  </Step>

  <Step title="Create Location object">
    Before creating tariffs, you must first create a Location object using the [location-create](/api-reference/anode/locations/create-a-location) endpoint. Pass your internal location reference as `reference_id`. The response will return a Flatpeak Location ID (`location_id`), which you must permanently store and associate with the device location in your system.

    At minimum, you must pass `postal_address.city` and `postal_address.country_code`. If the device is located in the US, you must also include `postal_address.state`. These fields enable Flatpeak to determine the correct timezone, currency, and market rates for the specified location.

    <Check>
      If you created a Customer Object in the optional step above, you **must** include it in this Location Create request using the `customer_id` field.
    </Check>

    <CodeGroup>
      ```json Request example {7} theme={"system"}
      curl --request POST \
        --url https://api.flatpeak.com/locations \
        --header 'Authorization: Bearer <token>' \
        --header 'Content-Type: application/json' \
        --data '{
        "reference_id": "LOC1234567890",
        "customer_id": "cus_65e421d1daa4a24082b4f590",
        "postal_address": {
          "address_line1": "1-3 Strand",
          "city": "London",
          "state": "Greater London",
          "post_code": "WC2N 5EH",
          "country_code": "GB"
        }
      }'
      ```

      ```json Response example theme={"system"}
      {
        "id": "loc_641b90b758fb8e6293716e40",
        "object": "location",
        "reference_id": "LOC1234567890",
        "customer_id": "cus_65e421d1daa4a24082b4f590",
        "timezone": "Europe/London",
        "currency_code": "EUR",
        "postal_address": {
          "address_line1": "1-3 Strand",
          "city": "London",
          "state": "Greater London",
          "post_code": "WC2N 5EH",
          "country_code": "GB"
        }
      }
      ```
    </CodeGroup>
  </Step>

  <Step title="Create Tariff object">
    Once you have a Location ID, you can call [create-tariff](/api-reference/anode/tariffs/create-a-tariff) endpoint to create a Tariff object.

    Flatpeak’s tariff model is highly flexible, supporting advanced structures that include market-based pricing, transmission fees, consumption tiers, seasonal rates, and special day overrides.

    In the example below, we create a simple tariff where the customer pays a fixed `€0.02123` per kWh on top of the market rate for their location:

    | Object/Parameter                | Description                                                                                                                                                                                                               |
    | :------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
    | `location_id`                   | Flatpeak Location ID, to which this tariff applies.                                                                                                                                                                       |
    | `direction`                     | Tariff direction, i.e. if it applies to the energy being consumed `IMPORT` at the supply address or exported from that address, i.e. `EXPORT`. The most common value will be `IMPORT`.                                    |
    | `type`                          | Represents if the tariff describes energy purchase (`COMMODITY`) or transmission (`NON_COMMODITY`) cost, see [Importing Your Data](/guides/migrate/import-your-data) guide. The most common value is `COMMODITY`.         |
    | `market_rates`                  | Set to `true` if you want the tariff to be based on the market rate. When set to true, Flatpeak will automatically find [market rate region](/guides/sources/market-rates) using `postal_address` in the Location object. |
    | `contract_start_date`           | Date when the contract between your customer and their energy provider has begun. If you don't have this information, set it to today's date.                                                                             |
    | `contract_end_date`             | Date when the contract between your customer and their energy provider has ended or will end. If you don't have this information, set it to today's date + 1 year.                                                        |
    | `schedule.months`               | Specifies months when tariff applies. Set to `All`.                                                                                                                                                                       |
    | `schedule.days_and_hours.days`  | Specifies days when tariff applies. Set to `All`.                                                                                                                                                                         |
    | `schedule.days_and_hours.hours` | Specifies hours when this tariff applies. Set to align with the example below when your customer is on a fixed tariff. Set `rates.value` to their tariff rate in **large** currency units, i.e. €0.02123¢.                |

    <CodeGroup>
      ```json Request example theme={"system"}
      curl --request POST \
        --url https://api.flatpeak.com/tariffs \
        --header 'Authorization: Bearer <token>' \
        --header 'Content-Type: application/json' \
        --data '{
        "location_id": "loc_641b90b758fb8e6293716e40",
        "direction": "IMPORT",
        "type": "COMMODITY",
        "market_rates": false,
        "contract_start_date": "2024-01-24T00:00:00Z",
        "contract_end_date": "2025-01-24T00:00:00Z",
        "schedule": [
          {
            "months": [
              "All"
            ],
            "days_and_hours": [
              {
                "days": [
                  "All"
                ],
                "hours": [
                  {
                    "valid_from": "00:00:00",
                    "valid_to": "00:00:00",
                    "rate": [
                      {
                        "fixed": 0.02123
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }'
      ```

      ```json Response example theme={"system"}
      {
        "id": "trf_66ba584eb6923d7c3b942ef6",
        "object": "tariff",
        "location_id": "loc_641b90b758fb8e6293716e40",
        "connection_type": "MANUAL",
        "direction": "IMPORT",
        "type": "COMMODITY",
        "timezone": "Europe/London",
        "market_rates": false,
        "contract_start_date": "2024-01-24T00:00:00Z",
        "contract_end_date": "2025-01-24T00:00:00Z",
        "schedule": [
          {
            "months": [
              "All"
            ],
            "days_and_hours": [
              {
                "days": [
                  "All"
                ],
                "hours": [
                  {
                    "valid_from": "00:00:00",
                    "valid_to": "00:00:00",
                    "rate": [
                      {
                        "fixed": 0.23431
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
      ```
    </CodeGroup>
  </Step>
</Steps>

<Accordion title="Learn more about object relationships, tariff types and directions" icon="lightbulb">
  Flatpeak stores tariff information (Tariff) in a many-to-one relationship with a Location (also referred to as the supply address). Each tariff also specifies the direction of energy flow—IMPORT or EXPORT.

  Because multiple tariffs can apply to the same location (e.g. commodity pricing, grid fees, export compensation), Flatpeak refers to each one as a **tariff**. Together, these elements form the full energy cost at that location. You can access the combined result using the [retrieve-price](/api-reference/anode/prices/retrieve-a-price) endpoint.

  ```mermaid theme={"system"}
  ---
  config:
    theme: redux
  ---
  flowchart TD
      A(["Customer<br>(optional)"]) --- B["Location A (Country Home)"] & n1["Location B (City Home)"]
      B --- D["Import Tariff<br>(COMMODITY)"] & n2["Import Tariff<br>(COMMODITY)"] & n4["Grid Tariff<br>(NON_COMMODITY)"]
      n1 --- n3["Import Tariff<br>(COMMODITY)"]
      n1 --> n5["Grid Tariff<br>(NON_COMMODITY)"]
      B@{ shape: rounded }
      n1@{ shape: rounded }
      style A stroke-width:2px,stroke-dasharray: 2

  ```

  #### Supported Tariff Combinations

  Flatpeak supports the following combinations of tariff type and energy flow direction to cover all major business cases:

  | Type/Direction           | Description                                                                                          |
  | :----------------------- | :--------------------------------------------------------------------------------------------------- |
  | `COMMODITY`+`IMPORT`     | Cost of the electricity consumed. Essential to enable this—it’s foundational across all markets.     |
  | `COMMODITY`+`EXPORT`     | Price for exported electricity. Use this if your users have solar panels or energy storage.          |
  | `NON_COMMODITY`+`IMPORT` | Delivery costs (e.g., **grid fees**). Recommended if your customer pays delivery charges separately. |
</Accordion>
