Forum Discussion

SBrown_Murphy's avatar
SBrown_Murphy
Frequent Visitor
2 years ago
Solved

Looking for the Power BI API for MQuery

When administering a Power BI enviorment were the reports source their data from on-prem SQL databases I've found it is hard match a problem SQL query I see in the database with the symantic model that is running it.  I'd like to use a Power BI API to pull the MQuery's from all the symantic models in all the workspaces on the tenant.  I've done this using other APIs to create SQL inventory tables of the workspaces, datasets, and other things.  I'd like to do the same with the MQuery's now.

 

The only way I was able to find an API call that might work was using an AI search, I found this: 

"https://api.powerbi.com/v1.0/myorg/groups/{workspace_id}/datasets/{dataset_id}/queries"
Running it just gives this error "No HTTP resource was found that matches the request URI"
 
My questions are, do I have the right API URL?  Is there a way to do this?  If this is not the right API what is the right one?   
  • lbendlin's avatar
    lbendlin
    2 years ago

    How do you plan to authenticate?  Did you register an app in AD with the required scope?

     

    $requestBody = @"
    { "queries": [{ "query": "EVALUATE TOPN(10,Dates,[Date])"}]
     ,"serializerSettings":{"includeNulls":true}
    }
    "@
    Login-PowerBI
    $requestUrl = "datasets/xxx/executeQueries"
    $result = Invoke-PowerBIRestMethod -Method Post -Url $requestUrl -Body $requestBody
    $parsed = $result | ConvertFrom-Json

     

     

    Here is a script with manual authentication. 

6 Replies