Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more.
Get startedGrow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.
Hi All ,
I am new to power bi and trying to triggger a data connection referesh using API. I have gone through the link
Datasets - Refresh Dataset - REST API (Power BI Power BI REST APIs) | Microsoft Learn
Unfortunately when i try to execute the api post call through browser , i am getting the below error.
You don't have authorization to view this page.
Can someone guide me how to proceed or implement the API feature here.
Hi @Anonymous ,
A 403 error can occur for any of the following reasons. A fiddler capture may be required to investigate further.
Troubleshoot Power BI REST APIs - Power BI | Microsoft Learn
Best Regards
Community Support Team _ Polly
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Anonymous ,
A 403 error can occur for any of the following reasons. A fiddler capture may be required to investigate further.
More details:Troubleshoot Power BI REST APIs - Power BI | Microsoft Learn
If it still does not help, We suggest you to open a ticket here for help if you are a pro user: https://powerbi.microsoft.com/en-us/support/
Best Regards
Community Support Team _ Polly
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks again for the response. Is there any guidelines or docs for creating a new user for executing power bi API or do we need to register an app in AD to do all these? i dont want to use my own id to call the API , Any reference or steps to followed for the below steps
1) Create a Servcie account or app registration in AD ( which ever the best practice)
2) Any setup needs to be done in power bi for the service account?
3) How to obtain a access token using those account.
Hi @Anonymous ,
In this case please try an approach from this link.
Power BI REST APIs for embedded analytics and automation - Power BI REST API | Microsoft Learn
Best Regards
Community Support Team _ Polly
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
I have created an app using Embed for your organization for executing the API in ad directory. I have generated the token using client id and client secret from the new app, i even added the permission for read & write all datasets . but still getting 403 error.
i have used my existing cliend id and client secret where i have registered an app for pulling data from AD directory , i have used the same credentials for the below code
#import msal
import requests
import json
import os
from adal import AuthenticationContext
def main():
client_id='xxxxx'
resource = 'ZZZZZ'
username = 'youraccount@domain.com'
tenantname = 'YYYYYY'
client_secret = 'GGGGGG'
password = 'YourMegaSafePassword738!*'
authority_url = 'https://login.microsoftonline.com/yourdomain.com'
scope = ["https://analysis.windows.net/powerbi/api/.default"]
url_groups = 'https://api.powerbi.com/v1.0/myorg/groups'
#msal to obtain the token - TBD !!!!
#app = msal.PublicClientApplication(client_id, authority=authority_url)
#result = app.acquire_token_by_username_password(username=username,password=password,scopes=scope)
auth_context = AuthenticationContext('https://login.microsoftonline.com/' +tenantname)
token = auth_context.acquire_token_with_client_credentials(resource=resource, client_id=client_id,client_secret=client_secret)
print('DEBUG', token)
accessToken = "test"
tokenType = token['tokenType']
refresh_url = 'https://api.powerbi.com/v1.0/myorg/datasets/{datasetid}/refreshes'
header = {"referer": "https://learn.microsoft.com/", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.62", "Content-Type":"application/json","Authorization": f"Bearer {accessToken}"}
payload = {"notifyOption":""}
print('header', header)
response = requests.post(url=refresh_url, data=payload, headers=header)
print('response', response) #response.json())
#os.system("pause")
if __name__ == '__main__':
main()
Can you guide me , is there any step where i need to do a app registration in AD directory for power bi . i believe i am missing something with app registration and obtaining the access token.
I am trying to get the access token or some way of login using python and submit the post request using python.
Hi @Anonymous ,
Do you want to connect to Power BI REST API in Power BI Desktop and you will get 403 errror?
Firstly, we need to get Access token in Power BI Desktop. We will get access token from Power BI by below code.
Please replace the parameters like "client_id","APP ID" and so on by correct values.
() =>
let
body = "client_id=" & #"App ID"
& "&scope=https://analysis.windows.net/powerbi/api/.default&client_secret=" & #"App Secret"
& "&grant_type=client_credentials",
Data= Json.Document(Web.Contents("https://login.microsoftonline.com/"& TenantID & "/oauth2/v2.0/token/",
[Headers=[#"Content-Type"="application/x-www-form-urlencoded"], Content=Text.ToBinary(body)])),
access_token = Data[access_token]
in
access_token
OR
() =>
let
body = "&grant_type=Password&resource = https://analysis.windows.net/powerbi/api
&client_id=*****&username=*****&password=*****",
Data=Json.Document(Web.Contents("https://login.microsoftonline.com/common/oauth2/v2.0/token/",
[Headers=[#"Content-Type"="application/x-www-form-urlencoded"], Content=Text.ToBinary(body)])),
access_token = Data[access_token]
in
access_token
Then you can follow this video to get data from the Rest API by access token in first step.
Finally, you can replace bear token by the access token parameter.
It will refresh every time your refresh your report.
Video: How to get access token and call Rest API by dynamic access token in Power BI Desktop? (5:30 to 9:30)
all Power BI Rest API with Dynamic Access Token From Power BI Desktop |Power BI Rest API
For more details, you may refer to this offical blog to learn more details about Get Report Rest API.
I have also found a similar psot, please refer to it to see if it helps you.
Solved: Power BI REST API gives 403 error (User does not h... - Microsoft Power BI Community
If it still does not help, please provide more details.
Best Regards
Community Support Team _ Polly
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks for the detailed explanation and sorry for missing information.
I am trying to trigger the data connection referesh using Python.