Forum Discussion
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:
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-JsonHere is a script with manual authentication.
6 Replies
- SBrown_MurphyFrequent VisitorThank you for this suggestion but this is not working for me either. It looks like there is a function that is supposed to return the DAX Query but it errors out too. 'https://api.powerbi.com/v1.0/myorg/datasets/{dataset_ID}/executeQueries' (400): Bad Request I tried calling that API URL from the PowerShell script and got the same error. What I'm really looking for is an API URL that will work so it can be added to my PowerShell scripts.
- lbendlinSuper User
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-JsonHere is a script with manual authentication.