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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
steve1024
Frequent Visitor

get data from API with POST request and JSON query

Hi, I am trying to connect to the an API with a blank query an am struggeling with the syntax

 

API instructions:

steve1024_1-1668178412318.png

 

How do I write this query properly in PBI? I have tested mulitple things with different errors

 

one version I tried, which gives the follwing error which is not very helpful

steve1024_2-1668178744048.png

 

 

let
Source = Json.Document(Web.Contents("http://blablabla.px",
[
Headers = [#"Content-Type"="application/json"],
Content=Json.FromValue([query = {}, response = [format = {"px"} ]])
]
))
in
Source

 

 

Have tried other methods for the content part (e.g. text.tobinary) but with no good result either. This M syntax is really confusing - please help! thanks and regards

 

 

1 ACCEPTED SOLUTION
steve1024
Frequent Visitor

thanks Daryl for your help. After some trial and error I found out that the instructions on the API was stated as ...format = ''px" , but this format (not sure what it is even) was not interpretable. Changeing this to format = ''json'' did the trick..

View solution in original post

2 REPLIES 2
steve1024
Frequent Visitor

thanks Daryl for your help. After some trial and error I found out that the instructions on the API was stated as ...format = ''px" , but this format (not sure what it is even) was not interpretable. Changeing this to format = ''json'' did the trick..

Daryl-Lynch-Bzy
Community Champion
Community Champion

Hi @steve1024 - it can sometimes help to split M steps up so that you have more visibility.  Here is your original function:

let
    header = [#"Content-Type"="application/json"],
    body = Json.FromValue([query = {}, response = [format = {"px"} ]]),
    Preview = Text.FromBinary( Body , BinaryEncoding.Base64 ),
    Source = Web.Contents(
        "http://blablabla.px",
        [
            Headers = header,
            Content = body
        ]
    ),
    Json = Json.Document( Source )
in
    Json

 
This generate the following Preview of the JSON.

DarylLynchBzy_0-1668190431038.png

If this is formatted: 

{ 
   "query":[],
   "response": {"format":["px"]}
}

It does not quite match the above.   I have removed the {} around px.  please test and trouble-shoot this way.

let
    header = [#"Content-Type"="application/json"],
    body = Json.FromValue([query = {}, response = [format = "px"]]),
    Preview = Text.FromBinary( Body , BinaryEncoding.Base64 ),
    Source = Web.Contents(
        "http://blablabla.px",
        [
            Headers = header,
            Content = body
        ]
    ),
    Json = Json.Document( Source )
in
    Json

 

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.

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.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.