Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
luqmannurai
Regular Visitor

API connection to SIEM using M query

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:

 

  • Whenever I set to anonymous, it will return:
  • luqmannurai_1-1695195365440.png

     

  • After I set it to the Windows where I provided Username with the <api_username> and the password with the <api_secret>, it returns me the following error: "DataSource.Error: Web.Contents with the Content option is only supported when connecting anonymously."

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://community.fabric.microsoft.com/t5/Developer/Connecting-from-power-BI-to-rest-API-with-Oath2-...

- 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.

0 REPLIES 0

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.