Forum Discussion
Paginated report - Web API authentication with POST request
- Anonymous1 year ago
Hi kalluu91 ,
When you make POST requests in Power Query you must use Anonymous authentication when asked, then in the actual query you supply the username and password and the authentication is performed via the Headers of the POST request.
let url = "api.xxxx.com", body = "{}", token = "xxxxxxxx", header = [ #"Content-Type" = "application/json", #"Authoritation" = "Basic " & token ], response = Web.Contents(url, [ RelativePath = "/xxxx/login", Headers = header, Content = Text.ToBinary(body) ]), AccessToken = Json.Document(response)[access_token], JsonResponse = Web.Contents( url, [ RelativePath = "/xxx/xxx", Headers = [ Authoraztion = "Basic " & AccessToken, #"Content-Type" = "application/json" ] ] ), Result = Json.Document(JsonResponse) in ResultI found some posts with similar issues that you can refer to:
Solved: Web.Contents with the Content option is only suppo... - Microsoft Fabric Community
Solved: DataSource.Error - Microsoft Fabric Community
Solved: Error with Web.Contents and POSTing to a URL that ... - Microsoft Fabric Community
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi kalluu91 ,
When you make POST requests in Power Query you must use Anonymous authentication when asked, then in the actual query you supply the username and password and the authentication is performed via the Headers of the POST request.
let
url = "api.xxxx.com",
body = "{}",
token = "xxxxxxxx",
header = [
#"Content-Type" = "application/json",
#"Authoritation" = "Basic " & token
],
response = Web.Contents(url, [
RelativePath = "/xxxx/login",
Headers = header,
Content = Text.ToBinary(body)
]),
AccessToken = Json.Document(response)[access_token],
JsonResponse = Web.Contents(
url,
[
RelativePath = "/xxx/xxx",
Headers = [
Authoraztion = "Basic " & AccessToken,
#"Content-Type" = "application/json"
]
]
),
Result = Json.Document(JsonResponse)
in
Result
I found some posts with similar issues that you can refer to:
Solved: Web.Contents with the Content option is only suppo... - Microsoft Fabric Community
Solved: DataSource.Error - Microsoft Fabric Community
Solved: Error with Web.Contents and POSTing to a URL that ... - Microsoft Fabric Community
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.