This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreDid you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now
To power BI community,
I am trying to query to an API using the M query or the "Advance Editor" in the power query section. The request itself have two different part:
let
auth_url = "https://host.alienvault.cloud/api/2.0/oauth/token",
api_username = "username",
api_secret = "secret",
payload = "grant_type=client_credentials",
bearer_content_header = [#"Content-Type"="application/x-www-form-urlencoded"],
bearer_auth_header = "Basic " & Text.FromBinary(Text.ToBinary(api_username & ":" & api_secret)),
request_bearer = Json.Document(Web.Contents(url, [Headers1=bearer_content_header, Content=Text.ToBinary(payload), Headers=[#"Authorization"=bearer_auth_header]])),
access_token = request_bearer[access_token],
request_header = "Bearer " & access_token,
api_url = "https://host.alienvault.cloud/api/2.0/alarms/",
Source = Json.Document(Web.Contents(api_url, [Headers=[#"Authorization"=requestHeader]])),
in
Source
The snippet of query above is currently how I query the api itself where the logic is to sent first to auth url and pass the token obtained to the resource api endpoint as Bearer authentication. I have also use some other form of query (from different guide) but currently they all return the same error:
Changing it to function also returns similar error:
()=>
let
auth_url = "https://hostname.alienvault.cloud/api/2.0/oauth/token",
api_username = "username",
api_secret = "secret",
body = "grant_type=client_credentials&client_id=" & Text.From(api_username) & "&client_secret=" & Text.From(api_secret),
headers = [#"Content-Type"="application/x-www-form-urlencoded"],
source = Text.ToBinary(body),
token_response = Json.Document(Web.Contents(auth_url, [Headers=headers, Content=source])),
access_token = token_response[access_token]
in
access_token
Is there anyway to resolve this issue, or is there any part that I am missing. For reference this are some of the guide that I have referred:
- https://www.myonlinetraininghub.com/connecting-to-an-oauth-api-like-paypal-with-power-query
Also to include: My possible goal is that this query that I make to the API able to schedule refresh similar to my google sheets resource after creating the template for the powerbi visualisation, is this achievable? . Thanks in advance and sorry if the question lacks some clarfying details, will appreciate any nudge in the right direction.
Check out the April 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.