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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
otravers
Community Champion
Community Champion

Forcing Web.Contents to make a GET call with a body

Hi,

 

I've used the following code pattern against several APIs to retrieve JSON content via Web.Contents, like so:

 

 

 

let
    getProjects = let
    relpath = "/api/path/here",
    Body = "
        {
            ""uid"": ""xyz"",
            ""api_key"": ""123"",
            ""secret_token"": ""456""
        }",
    Source = Json.Document(
        Web.Contents(
            "https://api.domain.com",
            [
                RelativePath = relpath,
                Content = Text.ToBinary(Body),
                Headers = [
                    #"Content-type" = "application/json"
                ]
            ]
        )
    ),
    response = try Source otherwise null
in
    Source
in
    getProjects

 

 

 

When I repurposed this code snippet to call a new (for me) API, I ran into a 404 Not found error. I triple checked my URL and relative path, all is correct. After running Advanced Diagnostics, I realized that all along this code pattern has been making POST requests, not GET. The reason I hadn't realized that in the past is that those specific APIs accept both GET and POST requests, but the new one doesn't.

 

Is there a way to force Web.Contents to stick to a GET HTTP request when you add a body (via Content) to the request? I need this body as this API uses it to pass along authentication parameters. Thanks for any help!

------------------------------------------------
1. How to get your question answered quickly - good questions get good answers!
2. Learning how to fish > being spoon-fed without active thinking.
3. Please accept as a solution posts that resolve your questions.
------------------------------------------------
BI Blog: Datamarts | RLS/OLS | Dev Tools | Languages | Aggregations | XMLA/APIs | Field Parameters | Custom Visuals
9 REPLIES 9
v-yingjl
Community Support
Community Support

Hi @otravers ,

As far as I know, Web.contents() sends GET request by default. But please note this optional parameter Content in it

Content: Specifying this value changes the web request from a GET to a POST, using the value of the option as the content of the POST.

 

If you are using the Content parameter, it will change the web request from GET to POST compulsorily.

 

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yingjl thanks for confirming that using Content changes from GET to POST compulsorily. In my opinion this is undesirable behavior that prohibits from using some valid HTTP requests.

------------------------------------------------
1. How to get your question answered quickly - good questions get good answers!
2. Learning how to fish > being spoon-fed without active thinking.
3. Please accept as a solution posts that resolve your questions.
------------------------------------------------
BI Blog: Datamarts | RLS/OLS | Dev Tools | Languages | Aggregations | XMLA/APIs | Field Parameters | Custom Visuals

Hi @otravers ,

Nevertheless, it is currently by design in power query. If you have any new ideas, you can create a new idea here:

https://ideas.powerbi.com/ideas/ 

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

watkinnc
Super User
Super User

I wonder if Chris Webb's article will help. Seems to consider your issue.

https://www.google.com/amp/s/blog.crossjoin.co.uk/2014/03/26/working-with-web-services-in-power-quer... 


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

@watkinncI fail to see how this article is addressing my specific issue, which again how to force Power Query to execute a GET HTTP request that includes a body.

------------------------------------------------
1. How to get your question answered quickly - good questions get good answers!
2. Learning how to fish > being spoon-fed without active thinking.
3. Please accept as a solution posts that resolve your questions.
------------------------------------------------
BI Blog: Datamarts | RLS/OLS | Dev Tools | Languages | Aggregations | XMLA/APIs | Field Parameters | Custom Visuals

My fault man. I know that the documentation for Web.Contents says that when a body is included, it becomes a POST request. I thought you were having trouble with the permissions/authentication with the API part of it, which the article talks about. Sorry my man!


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!
otravers
Community Champion
Community Champion

WebAction.Request with a get method sounds like it's the alternative to Web.Contents to address my requirement, but I cannot for the life of me find a single working example.

 

I'm getting "Expression.Error: We haven't been given permission to perform actions against this resource" like other people in various unresolved threads across the web.

 

Edit:  Chris Webb told me on Twitter that "those functions [WebAction.Request, WebMethod.Get/Post etc.] aren’t for public use and should really be hidden."

------------------------------------------------
1. How to get your question answered quickly - good questions get good answers!
2. Learning how to fish > being spoon-fed without active thinking.
3. Please accept as a solution posts that resolve your questions.
------------------------------------------------
BI Blog: Datamarts | RLS/OLS | Dev Tools | Languages | Aggregations | XMLA/APIs | Field Parameters | Custom Visuals

@otravers Have you found a solution to your problem?


I dealing with a REST Api that requires that I submit Content with GET to specify what exactly I want to retrieve. This limitation makes it really difficult ... 

otravers
Community Champion
Community Champion

No, as far as I can know Web.Contents still behaves the same way:

https://learn.microsoft.com/en-us/powerquery-m/web-contents#about

------------------------------------------------
1. How to get your question answered quickly - good questions get good answers!
2. Learning how to fish > being spoon-fed without active thinking.
3. Please accept as a solution posts that resolve your questions.
------------------------------------------------
BI Blog: Datamarts | RLS/OLS | Dev Tools | Languages | Aggregations | XMLA/APIs | Field Parameters | Custom Visuals

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors
Top Kudoed Authors