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

Did 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

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
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.