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

# Automatically assign market tariff when you know customer's postal address

## Overview

If you already have customer addresses but the tariff data is missing, you can automatically assign market tariffs without requiring manual action.

This allows your customers to immediately benefit from energy price data in your system, while still encouraging them to connect their actual tariff later via Connect for improved price accuracy.

## Implementation

<Steps>
  <Step title="Create a Location">
    Before creating tariffs, you must first create a **Location** using the [location-create](/api-reference/anode/locations/create-a-location) endpoint. The response will return a Flatpeak **Location ID**, which you must permanently store in your system.

    | Parameter        | Description                                                                                                                                                                                                      |
    | :--------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | `reference_id`   | A reference that is meaningful to you, for example, an ID from your system.                                                                                                                                      |
    | `postal_address` | Postal address of your customer or their equipment. If the exact address is unknown, use an approximate one. The address will be used to map the correct [Market rates source](/guides/sources/market-rates).    |
    | `customer_id`    | (Optional) If your system supports multiple locations per customer, call [create-customer](/api-reference/anode/customers/create-a-customer) first, then include the generated **Customer ID** using this field. |

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

      ```json Response example {2} theme={"system"}
      {
        "id": "loc_641b90b758fb8e6293716e40",
        "object": "location",
        "reference_id": "LOC1234567890",
        "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 a Tariff">
    Once you have a Location ID, create a **Tariff** by calling [create-tariff](/api-reference/anode/tariffs/create-a-tariff) endpoint. This will instruct Flatpeak systems to apply the market rates to the Location you created earlier.

    | Parameter.            | Description                                                        |
    | :-------------------- | :----------------------------------------------------------------- |
    | `location_id`         | Flatpeak Location ID you created earlier                           |
    | `direction`           | `IMPORT`                                                           |
    | `type`                | `COMMODITY`                                                        |
    | `contract_start_date` | Set to today’s date                                                |
    | `contract_end_date`   | Set to a date far in the future (for example, 10 years from today) |
    | `market_rates`        | Set to `true` (important)                                          |

    <CodeGroup>
      ```json Request example {6} 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",
        "contract_start_date": "2025-01-01T00:00:00Z",
        "contract_end_date": "2035-01-01T00:00:00Z",
        "market_rates": true
      }'
      ```

      ```json Response example {12} theme={"system"}
      {
        "id": "trf_66ba584eb6923d7c3b942ef6",
        "object": "tariff",
        "location_id": "loc_641b90b758fb8e6293716e40",
        "connection_type": "MANUAL",
        "direction": "IMPORT",
        "type": "COMMODITY",
        "timezone": "Europe/London",
        "contract_start_date": "2025-01-01T00:00:00Z",
        "contract_end_date": "2035-01-01T00:00:00Z",
        "market_rates": true,
        "market_rate_source_id": "mrs_641b90b758fb8e6293716e40"
      }
      ```
    </CodeGroup>

    <Info>
      The presence of `market_rate_source_id` in the response confirms that Flatpeak successfully mapped a market rates data source.

      For more details, see the [**Market Rates Coverage**](/guides/sources/market-rates) guide.
    </Info>
  </Step>
</Steps>

You are all set. To retrieve energy prices, follow the [**Retrieve energy price**](/guides/connect/retrieve-price) guide. Skip the app integration section and go straight to **Getting the data**, which applies to this use case.
