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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Abhinay_Rozer
Regular Visitor

REST API - Executequeries function

REST API - Executequeries function


Hi All,

Abhinay_Rozer_0-1660977206692.png

 

I am trying to execute the "ExecuteQueries" REST API method on a dataset using Python programming, but I am not sure where i need to write body.
I gone through the microsoft documentation for ExecuteQueries REST API method
there it's mentioned to provide body in json format to get desired results
but i don't have any clue how i can pass this body to the executequeries API

Can you plese help on this if possible 
thanks in advance

1 ACCEPTED SOLUTION
ibarrau
Super User
Super User

Hi Abhinary_Roze. Yes the doc specify a body for the post. You can build a dict at python and then convert it as the parameter of the request. Check this example using requests and json libraries:

import requests
import json
url= "https://api.powerbi.com/v1.0/myorg/groups/{}/datasets/{}/executeQueries".format(workspace_id, dataset_id)
body = {
    "queries": [{"query": query}], 
    "serializerSettings": {"includeNulls": "true"}
}
res = requests.post(url, data = json.dumps(body), headers = headers) 

The requests.post will receive the url, body and headers (here you must write the bearer). You can convert your python dictionary (body variable) with json.dumps.

If you feel this all is too much you can use a Power Bi Rest API python library like SimplePBI. In there you can just import library, create token, create dataset class and make the request.

https://pypi.org/project/SimplePBI/

I hope that helps,


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

View solution in original post

2 REPLIES 2
ibarrau
Super User
Super User

Hi Abhinary_Roze. Yes the doc specify a body for the post. You can build a dict at python and then convert it as the parameter of the request. Check this example using requests and json libraries:

import requests
import json
url= "https://api.powerbi.com/v1.0/myorg/groups/{}/datasets/{}/executeQueries".format(workspace_id, dataset_id)
body = {
    "queries": [{"query": query}], 
    "serializerSettings": {"includeNulls": "true"}
}
res = requests.post(url, data = json.dumps(body), headers = headers) 

The requests.post will receive the url, body and headers (here you must write the bearer). You can convert your python dictionary (body variable) with json.dumps.

If you feel this all is too much you can use a Power Bi Rest API python library like SimplePBI. In there you can just import library, create token, create dataset class and make the request.

https://pypi.org/project/SimplePBI/

I hope that helps,


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

Abhinay_Rozer
Regular Visitor

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.