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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! 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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.

Top Solution Authors