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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Anonymous
Not applicable

Dataset refresh REST API, Service Principal Not Authorised

Hi all,

 

I'm trying to trigger a refresh via the Rest API using a service principle registered app. So far, the app has been granted all PowerBi permissions in Azure, it is also part of a a security group with all PowerBi permissions, and I have granted API access for service principals in the admin portel. Futhermore, the service principle has admin access in the workspace of the dataset in question.

 

When making the REST API request, I successfully aquire an access token with the service principle client info:

 

 

 

import requests

url = 'https://login.microsoftonline.com/common/oauth2/token'
data = {
        'grant_type':  'client_credentials',
        'scope': 'https://api.powerbi.com',
        'resource': 'https://analysis.windows.net/powerbi/api',
        'client_id': <Client ID>,
        
        'client_secret': <Client Secret>
        }
r = requests.post(url, data=data)
access_token = r.json().get('access_token')

 

 

However when I make the request using this token, I get a response error 401, not authorised:

 

 

 

header = {'Authorization': f'Bearer {access_token}'}

url='https://api.powerbi.com/v1.0/myorg/groups/' + <Group ID> + '/datasets/' + <Dataset ID> + '/refreshes'
r = requests.post(url=url, headers=header)
print(r.status_code)

 

 

 I can only imagine it's some authorisation issue external to the request. Any ideas?

1 ACCEPTED SOLUTION
mariussve1
Solution Sage
Solution Sage

Hi,

I think you need to add the SPN as admin in the Workspace where your dataset is stored. The best way to do this is, if you havent already done this, is to put the SPN in a Security Group in AAD. Then grant this security group admin access to the workspace. After you have granted access it can take a while before the access has been granted, so I suggest to wait 30 min before trying the REST API again.

 

Br
Marius


Br
Marius
BI Fabrikken
www.bifabrikken.no

View solution in original post

2 REPLIES 2
mariussve1
Solution Sage
Solution Sage

Hi,

I think you need to add the SPN as admin in the Workspace where your dataset is stored. The best way to do this is, if you havent already done this, is to put the SPN in a Security Group in AAD. Then grant this security group admin access to the workspace. After you have granted access it can take a while before the access has been granted, so I suggest to wait 30 min before trying the REST API again.

 

Br
Marius


Br
Marius
BI Fabrikken
www.bifabrikken.no
Anonymous
Not applicable

HI @Anonymous,

As the document mentions, this refresh API required an additional option 'notifyOption' in the body. I'd like to suggest you add it to your request and try again:

Datasets - Refresh Dataset In Group - REST API (Power BI Power BI REST APIs) | Microsoft Docs

BTW, what type of data source are you working on? If you mean Azure Analysis Services, it seems to need additional permission for that instance.

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.