azurepowerbigeolocationazure-mapsazure-rest-api

Error at accessing Azure Maps Geographic API Endpoints from Web query in PowerBI


I try to use the azure maps endpoint, but i am unable to access any of the endpoints from PowerBI with the Azure Maps "primary key" from my Azure Maps account instance.

https://eu.atlas.microsoft.com
https://atlas.microsoft.com

Basically i want to geolocate addresses (postal code + city name) -> [Longitude, Lattidude]

The sample response from the azure service is structured like that, and i want to access geometry points with the attribute "usageTypes":[ route]

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "address": {
          "countryRegion": {
            "name": "United States"
          },
          "adminDistricts": [
            {
              "shortName": "WA"
            },
            {
              "shortName": "King County"
            }
          ],
          "formattedAddress": "15127 NE 24th St, Redmond, WA 98052",
          "streetName": "NE 24th St",
          "streetNumber": "15127",
          "locality": "Redmond",
          "postalCode": "98052",
          "addressLine": "15127 NE 24th St"
        },
        "type": "Address",
        "confidence": "High",
        "matchCodes": [
          "Good"
        ],
        "geocodePoints": [
          {
            "geometry": {
              "type": "Point",
              "coordinates": [
                -122.138681,
                47.630358
              ]
            },
            "calculationMethod": "Rooftop",
            "usageTypes": [
              "Display"
            ]
          },
          {
            "geometry": {
              "type": "Point",
              "coordinates": [
                -122.1386787,
                47.6302179
              ]
            },
            "calculationMethod": "Rooftop",
            "usageTypes": [
              "Route"
            ]
          }
        ]
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          -122.138681,
          47.630358
        ]
      },
      "bbox": [
        -122.14632282407,
        47.626495282429325,
        -122.13103917593001,
        47.63422071757068
      ]
    }
  ]
}

Inside PowerBI i tried several approaches to use the service:

  1. Providing the API-KEY directly (Web query - error)
  2. Providing the API-KEY with a PowerBI parameter, which stores the key (Web query - error)
  3. Providing the API-KEY by a path to a text file (i tested the code segment which loads the key from the .txt - ok)

PowerBI test-query from approach 3:

let
Query1 = let

// load API-KEY from .txt
FilePath = "C:\Users\<my local path to the .txt>\API-KEY.txt",
#"API-KEY" = Text.Trim(Text.FromBinary(File.Contents(FilePath))),

url = "https://atlas.microsoft.com/geocode?api-version=2025-01-01&query=10115 Berlin&subscription-key=" & #"API-KEY",
rawResponse = Web.Contents(url),

jsonResponse = Json.Document(rawResponse),
features = jsonResponse[features], 
geocodePoints = features{0}[properties][geocodePoints], 

filteredRoutePoints = List.Select(geocodePoints, each List.Contains(Record.Field(_, "usageTypes"), "Route")),
routePoint = if List.Count(filteredRoutePoints) > 0 then List.First(filteredRoutePoints) else null,

coordinates = if routePoint <> null then routePoint[geometry][coordinates] else {null, null},

latitude = coordinates{1},
longitude = coordinates{0}
in
    [Latitude = latitude, Longitude = longitude],
    #"Converted to Table" = Record.ToTable(Query1)
in
    #"Converted to Table"

So 3 approaches and EVERYONE of them throws this error message - i can´t access the service (i tried it for multiple endpoints).

enter image description here


Solution

  • This issue typically occurs when using Web.Contents() with an API that expects the key to be passed using the ApiKeyName option rather than manually appending it to the URL.

    In order to resolve the problem, you should modify your Web.Contents() call to use the ApiKeyName option like this:

    Web.Contents("https://atlas.microsoft.com/search/address/json", [
        ApiKeyName = "subscription-key",
        Query = [
            query = "10115 Berlin",
            "api-version" = "1.0"
        ]
    ])
    

    This way, Power BI correctly includes the subscription-key in the request headers or query string as required by Azure Maps and avoids authentication issues especially when refreshing data in the Power BI.

    Why this matters:

    Power BI treats APIs more securely when using ApiKeyName. Directly giving keys in the URL string can lead to refresh failures or prevent gateway configuration due to implicit credential use.

    For reference: Web.Contents()