Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
ericOnline
Post Patron
Post Patron

API Call Help

Hello,

 

I'm trying to use the Advanced Editor to make an API call for the first time. I've watched Chris Webb's excellent video on the subject and took a bunch of notes, but i'm missing something here. In the video, I noted his call as:

let
    Source = Web.Contents("https://baseURL",
        [
            RelativePath="hello",
            Query = [
                key = "value1"
                key = "value2"
            ],
            ApiKeyName = "apikeyskdjf;asdkfj]"])
        ]
        )
in
    Source

But my query parameters didn't like this format.

 

The call I'm trying to make is a GET request: 

let
    Source = Web.Contents(
        "https://somecompanysAPI.com/v2/",
            [
                RelativePath="historical",
                    Query = 
    {
  "geocode": {
    "lon": -122.31177520752,
    "lat": 47.4498901367188
  },
  "location_id": "",
  "start_time": "2017-11-01T12:00:00Z",
  "end_time": "2017-11-07T12:00:00Z",
  "timestep": 60,
  "fields": [
        {"name": "temp", "units": "F"},
        {"name": "feels_like", "units": "F"},
        {"name": "dewpoint", "units": "F"},
        {"name": "wind_speed", "units": "mph"},
        {"name": "wind_gust", "units": "mph"},
        {"name": "baro_pressure", "units": "inHg"},
        {"name": "visibility", "units": "km"},
        {"name": "precipitation", "units": "in/hr"},
        {"name": "cloud_cover", "units": "%"},
        {"name": "cloud_ceiling", "units": "ft"},
        {"name": "cloud_base","units": "ft"},
        {"name": "humidity", "units": "%"},
        {"name": "wind_direction", "units": "degrees"},
        {"name": "precipitation_type"},
        {"name": "sunrise"},
        {"name": "sunset"}
  ]
}
                ApiKeyName = "thisisnotreallymyAPIkeydude"
            ]
    )

in
    Source

Can someone with more experience see what I'm missing here as far as syntax goes?

 

Thank yoU!

1 ACCEPTED SOLUTION

Ok! I figured this out from the great example in the Forums found here: https://community.powerbi.com/t5/Desktop/Connect-to-a-Web-Service-sending-parameters/m-p/295990#M130.... Thank you @Anonymous!

 

Here is what I ended up going with: 

let
    url = "https://company.com/api/path",
    headers = [
        #"apikey" = "thisisnotreallymyapikey",
        #"accept" = "application/json",
        #"Content-Type" = "application/json"
    ],
    content = "{
        ""key"": {
                    ""nestedKey"": value,
                    ""nestedKey"": value
                },
                ""key"": """",
                ""key"": ""value"",
                ""key"": ""value"",
                ""key"": value,
                ""key"": [
                ]
    }",
    webdata = Web.Contents(url, [Headers=headers,Content = Text.ToBinary(content)]),
    response = Json.Document(webdata)
in
    response

Whew! I should have searched the forums better! NOTED 🙂

View solution in original post

2 REPLIES 2
ericOnline
Post Patron
Post Patron

Still needing some assistance here. I've boiled down the code a bit to make it easier to read. Can you see why this is not working?

 

I should be more clear here on what I'm looking for help with:


Method: POST

Authentication: API Key sent in Request Header

Parameterized Request?: No, JSON request, not a parameterized URL
Body: JSON

Request Headers?: Yes, 3 (apikey, accept, Content-Type)

Response: JSON

Response Headers?: Yes, 11 (though I don't think I need to craft the response headers, they should auto)

Error in Advanced Editor: "Invalid Identifier" error on the word "geocode".

 

I've tried "Query" and "Content" in the below M with no success. The docs on Web.Contents have NO examples (and the Github contribute link is broken on that site!). For some reason, not many people are making POST requests with PowerBI so there are like NO examples of this on the internet besides Chris Webb's video. But I can't glean how to do it from his video (@ ~24:54 mark) because he digresses a bit at EXACTLY the moment he covers POST requests!

 

let
    Source = Web.Contents(
        "https://somecompanysAPI.com/v2/historical",
            [
                Query = [
                    "geocode": {
                        "lon": -122.31177520752,
                        "lat": 47.4498901367188
                    },
                    "location_id": "",
                    "start_time": "2017-11-01T12:00:00Z",
                    "end_time": "2017-11-07T12:00:00Z",
                    "timestep": 60,
                    "fields": [
                    ],
                ApiKeyName = "thisisnotreallymyAPIkeydude"
            ]
    )

in
    Source

 Does anyone have insights on this? An example or two of how you do it?


Thank you very much!

Ok! I figured this out from the great example in the Forums found here: https://community.powerbi.com/t5/Desktop/Connect-to-a-Web-Service-sending-parameters/m-p/295990#M130.... Thank you @Anonymous!

 

Here is what I ended up going with: 

let
    url = "https://company.com/api/path",
    headers = [
        #"apikey" = "thisisnotreallymyapikey",
        #"accept" = "application/json",
        #"Content-Type" = "application/json"
    ],
    content = "{
        ""key"": {
                    ""nestedKey"": value,
                    ""nestedKey"": value
                },
                ""key"": """",
                ""key"": ""value"",
                ""key"": ""value"",
                ""key"": value,
                ""key"": [
                ]
    }",
    webdata = Web.Contents(url, [Headers=headers,Content = Text.ToBinary(content)]),
    response = Json.Document(webdata)
in
    response

Whew! I should have searched the forums better! NOTED 🙂

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.