Forum Discussion

misaki's avatar
misaki
Regular Visitor
9 months ago
Solved

sending API requests from Power Query

When sending API requests from Power Query: If I use the Web connector and store credentials in the credential store, I am unable to include a Content body in the Web.Contents request. It appears t...
  • v-lgarikapat's avatar
    v-lgarikapat
    9 months ago

    Hi misaki ,

     

    Workaround to handle this scearion :

     

    Use query parameters or headers instead of Content

    If the API supports authentication via headers (e.g., Authorization: Bearer <token>) or query string, you can safely store credentials in the credential store and still send requests.


    m
    Web.Contents("https://api.example.com/data",
    [
    Headers = [Authorization="Bearer " & AccessToken]
    ])
    Use relative path with Web.Contents

    Power BI allows Content bodies only when the base URL is fixed and the dynamic part is passed via RelativePath or Query.

    This way, the credential store knows exactly which domain is being authenticated.

    :

    m
    Web.Contents("https://api.example.com",
    [
    RelativePath = "endpoint",
    Content = Text.ToBinary("{""param"":""value""}")
    ])
    Use OAuth2 authentication

    If the API supports OAuth2, Power BI has built-in support.

    You authenticate once, and Power BI manages tokens securely.

    This avoids embedding secrets in your query.

    Store secrets in Azure Key Vault or parameterize them

    Instead of hardcoding credentials, you can store them in Azure Key Vault or as Power BI parameters.

    Then reference them in your query, keeping sensitive values out of the M code.

     

     

     

    Thanks,

    Lakshmi.