Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
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.
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the October 2025 Power BI update to learn about new features.