Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more.
Get startedGrow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.
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!
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.
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.
I wonder if Chris Webb's article will help. Seems to consider your issue.
@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.
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!
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."
@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 ...
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
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the June 2024 Power BI update to learn about new features.
User | Count |
---|---|
39 | |
21 | |
20 | |
13 | |
13 |