Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Become a customer
  • Contact Us
English (US)
US English (US)
FR French
ES Spanish
JP Japanese
BR Portuguese (Brazil)
CN Chinese
  • Home
  • Platform
  • APIs
  • Power BI integration
  • Power BI Connection & Authentication

Power BI connection approach - with code examples

Discover effective Power BI connection methods and explore practical code examples to enhance your data integration skills.

Written by Eleonora Lebedeva

Updated at April 29th, 2026

Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Platform
    Dashboard Excel Add-In Mobile apps APIs
  • Log in
  • Training
  • Events
  • Prices and methodology
    Glossaries
  • MyDesk
    Getting Started with MyDesk Using MyDesk MyDesk advanced widgets Data available in MyDesk Troubleshooting
  • Administration
    Manage users Billing and invoices Banking and vendor registration
  • Contact us
+ More

Table of Contents

Web connector Power Query Execution Constraints Key constraints Best Practices for Authentication in Power BI Security Considerations: Using Power Query Parameters How to Connect Power BI to Fastmarkets APIs? Step 1 - Open Power Query Editor Step 2 - Create Power BI Parameters Step 3 - Create an Authentication Query Step 4 - Create a Reusable API Request Function Step 5 - Call the function from a regular query Important Authentication & Data Query

Web connector 

The fastest way to integrate Power BI with Fastmarkets API is using the Web connector. It supports Rest APIs, allows custom headers and works with Power Query (M language).

Typical pattern: 

Power Query Execution Constraints

When designing authentication in Power BI, it is important to understand how Power Query executes.

Key constraints

  • Power Query may re‑evaluate queries multiple times
  • Each table, function, or refresh step can trigger execution
  • Background refresh and preview refresh behave differently
  • Queries cannot reliably share state unless explicitly structured
 

These constraints may affect the authentication approach. If token generation is embedded directly inside multiple queries, Power Bi may request multiple tokens unintentionally and exceed Fastmarkets' authentication limits. This could cause scheduled updates to fail.

Best Practices for Authentication in Power BI

  • Centralize token generation
    Create one query responsible for authentication. Reuse the token across all API requests
    This ensures token reuse and stable refresh behavior.
     
  • Use Power BI parameters for credentials
    Store serviceName, and serviceKey as Power BI parameters. Avoid hard‑coding credentials in multiple places
     
  • Design for token expiry
    Expect refresh failures if a token becomes invalid. Ensure authentication logic runs once per refresh cycle

Security Considerations: Using Power Query Parameters

Storing access credentials in Power Query parameters is not the most secure approach. While it works, the credentials are still stored inside the Power BI model, which can cause security and access issues after the dataset is published to the Power BI Service.

For the use cases when Power BI is used by small teams of individual analysts the parameter‑based approach described in this article is usually acceptable, as long as dataset access is tightly controlled. Make sure that access to the dataset is restricted and credentials are managed carefully.

How to Connect Power BI to Fastmarkets APIs?

Step 1 - Open Power Query Editor

Use Power BI Desktop. Open Get Data → Blank Query.

Step 2 - Create Power BI Parameters

Create the following Power BI parameters (Manage Parameters → New):

Parameter name Type Example
FM_ServiceName Text test-metals
FM_ServiceKey Text K14yr7806AS/uEKO+9XzdsdLxX/5BlbI+aKg==
FM_Scope Text fastmarkets.physicalprices.api

Step 3 - Create an Authentication Query

Create a new blank query named

Fastmarkets_Authenticate

Power Query (M): Authentication

let
    AuthUrl = "https://auth.fastmarkets.com/connect/token",

    Body =
        [
            grant_type  = "servicekey",
            client_id  = "service_client",
            serviceName = FM_ServiceName,
            serviceKey  = FM_ServiceKey,
            scope       = FM_Scope
        ],

    Response =
        Json.Document(
            Web.Contents(
                AuthUrl,
                [
                    Content = Text.ToBinary(Uri.BuildQueryString(Body)),
                    Headers = [#"Content-Type" = "application/x-www-form-urlencoded"]
                ]
            )
        ),

    AccessToken = Response[access_token]
in
    AccessToken

Step 4 - Create a Reusable API Request Function

Create a function query named:

Fastmarkets_ApiRequest

Power Query (M):  data request function

(ApiUrl as text, Token as text, optional QueryParams as nullable record) as any =>
let
    Options =
        [
            Headers =
                [
                    Authorization = "Bearer " & Token,
                    Accept = "application/json"
                ],
            Query = if QueryParams = null then [] else QueryParams
        ],

    Response =
        Json.Document(
            Web.Contents(ApiUrl, Options)
        )
in
    Response

Step 5 - Call the function from a regular query

Create a function query named:

Fastmarkets_GetLatestPrice

let
    Token = Fastmarkets_Authenticate,

    ApiUrl =
        "https://api.fastmarkets.com/physical/v2/Prices/None",

    Response =
        Fastmarkets_ApiRequest(
            ApiUrl,
            Token,
            [
                symbols = "MB-STE-0009,MB-STE-0014"
            ]
        ),

    Data = Response[instruments],
    Table = Table.FromRecords(Data),
    pricesTable = Table.ExpandRecordColumn(
            Table.ExpandListColumn(Table, "prices"),
            "prices",
            {"assessmentDate", "low", "high", "revision"},
            {"assessmentDate", "low", "high", "revision"}
        )

in
    pricesTable

Important

Due to Power BI’s Formula Firewall, access tokens cannot be safely shared between queries, even as simple text values. To avoid firewall errors, authentication and API requests must be executed within the same query. This is a Power BI platform limitation.

To fix Formula.Firewall error you need to disable Privacy Levels on the file level as next: File → Options → Privacy → Ignore Privacy Levels

This is NOT recommended for published datasets.

If maintaining the privacy of access levels is critical for you, call all stages in a single request. Be careful - this will duplicate the authentication logic. 

If you need centralized Auth and keep Firewall setting, consider building custom Power BI connector or a server-side proxy/service that handles authentication

 

 

Authentication & Data Query

let
    //authentication
     AuthUrl = "https://auth.fastmarkets.com/connect/token",

    Body =
        [
            grant_type  = "servicekey",
            client_id  = "service_client",
            serviceName = FM_ServiceName,
            serviceKey  = FM_ServiceKey,
            scope       = FM_Scope
        ],

    Response =
        Json.Document(
            Web.Contents(
                AuthUrl,
                [
                    Content = Text.ToBinary(Uri.BuildQueryString(Body)),
                    Headers = [#"Content-Type" = "application/x-www-form-urlencoded"]
                ]
            )
        ),

    AccessToken = Response[access_token],

    //data request

    ApiUrl =
        "https://api.fastmarkets.com/physical/v2/Prices/None",

    Response =
        Fastmarkets_ApiRequest(
            ApiUrl,
            AccessToken,
            [
                symbols = "MB-STE-0009,MB-STE-0014"
            ]
        ),

    Data = Response[instruments],
    Table = Table.FromRecords(Data),
    pricesTable = Table.ExpandRecordColumn(
            Table.ExpandListColumn(Table, "prices"),
            "prices",
            {"assessmentDate", "low", "high", "revision"},
            {"assessmentDate", "low", "high", "revision"}
        )

in
    pricesTable

 

 

 

 

data connectivity bi integration

Was this article helpful?

Yes
No
Give feedback about this article

Related Articles

  • API technical information and FAQ
  • Excel Add-in User Guide
  • Download and install the Excel Add-in

Copyright 2026 – Fastmarkets.

Knowledge Base Software powered by Helpjuice

Expand