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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
athrane
Frequent Visitor

API POST through power query to get data

Hi All,

 

I have been using Python to do a relatively simple POST operation where I in return get som data. Using requests in Python, I use the following code which gives the desired result:

 

 

body = {"ejendomnr":"880",
                "AktivNr":"1",
                "I_Nr":"1",
                "AarsMaerke":"2023",
                "Aflaesningsfilter":"afMaanedsvis"
       }
url = 'https://apiapp.dff-edb.dk/gentofte/api/getforbrug?id=5c474de09dba2c3069908e6f75a99e48&unr=88408800&anr=1&inr=1' 

result = requests.post(url, json=datatest)

 

 

 

I have seached online to implement this in power query, and have currently implemented the following:

 

 

let
    url = "https://apiapp.dff-edb.dk/gentofte/api/getforbrug?id=5c474de09dba2c3069908e6f75a99e48&unr=88408800&anr=1&inr=1",
    headers = [#"Connection" = "keep-alive",#"Content-Type" = "application/json"],
    postData = Json.FromValue([
            Ejendomnr = "880",
            AktivNr = "1",
            I_Nr = "1",
            AarsMaerk = "2023",
            Aflaesningsfilter = "afMaanedsvis"]),
    response = Web.Contents(
        url,
        [
            Headers = headers,
            Content = postData
        ]
    ),
    jsonResponse = Json.Document(response)
    
in
    jsonResponse

 

 

 

This however gives me an error 500 'Internal server error'. Is anybody able to help with how to solve this issue? The response of the POST method should be a JSON object.

 

*Note that the url contains a token which expires, therefore you may not be able to get a satisfying result using the URL*

1 REPLY 1
lbendlin
Super User
Super User

Your code looks ok.  500 usually means an issue on the server, not in your code (unless your code crashed the server).

 

Consider using the RelativePath and Query options.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.