is it possible to get the query consumed/executed in a powerBI report/dataset using API's?

Shaik, Shahid (ACCENTURE) 5 Reputation points
2023-08-11T06:16:46.8533333+00:00

is it possible to get the query consumed/executed in a powerBI report/dataset using API's?
if yes please do share the endpoint.

Microsoft 365 and Office PowerPoint For business Windows
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Adnan Maalik 85 Reputation points
    2023-08-11T06:38:29.2433333+00:00

    Get the report ID and dataset ID of the report/dataset you want to get the query for. You can do this by opening the report in Power BI Desktop and then looking at the URL in the address bar. The report ID and dataset ID will be in the URL, separated by a "/".

    Use the Power BI REST API to get the query for the report/dataset. The following request will get the query for the report with the ID "reported"

    GET https://api.powerbi.com/v1.0/myReportId/datasets/myDatasetId/queries
    

    This request will return a JSON object with the following properties:

    • id: The ID of the query.
    • name: The name of the query.
    • text: The text of the query.
    • parameters: An array of objects that represent the parameters of the query. Each object has the following properties:
    • name: The name of the parameter.
    • value: The value of the parameter.
    1. Once you have the query, you can execute it by using the Power BI REST API to run a query. The following request will run the query with the ID "myQueryId"
    POST https://api.powerbi.com/v1.0/myReportId/datasets/myDatasetId/queries/myQueryId/run
    

    Impact Windows
    This request will return a JSON object with the following properties:

    • data: The results of the query.
    • errors: An array of objects that represent any errors that occurred while running the query. Each object has the following properties:
    • message: The error message.
    • severity: The severity of the error.

    I hope this helps!


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.