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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

Top Kudoed Authors