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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

How to Pass values to the Power BI Filter via API (while Generating PPTX from Power BI Report)

Hi Team,

I am able to generate PPTX and PDF from the API but I am not able to pass the filter to the report while generating PPTX. I tried and showing all the steps below

 

                                                         I have Generated PPTX from the given link

 

https://community.powerbi.com/t5/Community-Blog/How-to-use-Power-BI-Rest-API-to-export-the-Power-BI-...

 

# Passing Filters while generating PPTX

Step 1 - Get the exportId

 

https://api.powerbi.com/v1.0/myorg/groups/56811d8e-a609-435e-853e-c813fb83b7rQ8/reports/f0b99643-194...


Step 2 - Get the Current Status If the session is successful

 

https://api.powerbi.com/v1.0/myorg/groups/56811d8e-a609-435e-853e-c813fb83b7b8/reports/f0b99643-194d...


Step 3 - Download PPTX

 

https://api.powerbi.com/v1.0/myorg/groups/56811d8e-a609-435e-853e-c813fb83b7b8/reports/f0b99643-194d...

 

Filter also added in power BI Report and screenshot Attched

 

spcpowerb_0-1645535617147.png

 


With Regards

Bipin Kumar

 

4 REPLIES 4
satishkumar123
Regular Visitor

Hi Team, I am using the Power BI trail account and wants to fetch the filtered Report content. But at the end I am getting long HTML reponse. Below is my Python Code. Please let me know where I am wrong here.

 

Below is the code-

import requests

def get_access_token(client_id, client_secret, username, password, scope, token_url):
data = {
'grant_type': 'password',
'client_id': client_id,
'client_secret': client_secret,
'username': username,
'password': password,
'scope': scope
}
response = requests.post(token_url, data=data)
print(response.text)
access_token = response.json().get('access_token')
print(access_token)
return access_token

def get_embed_token(access_token, report_id, filters, dataset_id, group_id):
url = f"https://api.powerbi.com/v1.0/myorg/groups/{group_id}/reports/{report_id}/GenerateToken"
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}
body = {
'accessLevel': 'View',
'datasetId': dataset_id,
'filters': filters # Corrected to pass as a dictionary
}
response = requests.post(url, headers=headers, json=body)
print(response.text)
embed_token = response.json().get('token')
print(embed_token)
return embed_token

def fetch_report_data(emb_url, embed_token):
headers = {'Authorization': f'Bearer {embed_token}',
'Content-Type': 'application/x-www-form-urlencoded'
}
response = requests.get(emb_url, headers=headers)
print(response.status_code)
print(emb_url)
report_data = response.text
#report_data =response.json()
return report_data

def main():
# Power BI credentials and parameters
client_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
client_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
username = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'
password = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'
scope = 'https://analysis.windows.net/powerbi/api/.default'
token_url = 'https://login.microsoftonline.com/65df6efa-f78b-4336-9681-654c7fd66c53/oauth2/v2.0/token'
report_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'
group_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
emb_url = f'https://app.powerbi.com/reportEmbed?reportId={report_id}&groupId={group_id}'
dataset_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

# Filters to apply
filters = {
'name': 'Id',
'operator': 'eq',
'value': '00018bcgypygtvgt15'
}

# Obtain access token
access_token = get_access_token(client_id, client_secret, username, password, scope, token_url)

# Get embed token
embed_token = get_embed_token(access_token, report_id, filters, dataset_id, group_id)

# Fetch report data
report_data = fetch_report_data(emb_url, embed_token)

print(report_data)

if __name__ == "__main__":
main()

v-chenwuz-msft
Community Support
Community Support

Hi @Anonymous ,

 

You want to add filter on the page then export the report in format of pptx.

Maybe you can try add json in the body of this POST request. You can refer this article about REST API.

vchenwuzmsft_0-1645774084447.png

 

Reports - Export To File In Group - REST API (Power BI Power BI REST APIs) | Microsoft Docs

 

Best Regards

Community Support Team _ chenwu zhu

 

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

 

Anonymous
Not applicable

Hi Team,

              I have added json in body of this post request which has given below but filter is not working

 

{
format: "PPTX",
filter:"FarmData/RegisteredUserId eq 122"
}

 

Filter also added in power BI Report and screenshot Attched

spcpowerb_1-1646239594421.png

 

With Regards

Bipin Kumar

Hi Bipin Kumar,

 

Does the issue got resolved?. If yes can you share the solution please!.

 

Regards,

Naveen Mohan

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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