Forum Discussion
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!
9 Replies
- otravers
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."
- otravers
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
- AnonymousNot applicable
I wonder if Chris Webb's article will help. Seems to consider your issue.
- otravers
Community Champion
AnonymousI 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.
- AnonymousNot applicable
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!
- v-yingjl
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.- v-yingjl
Community Support
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.