Forum Discussion
Service Principal Approach to Extract Data from Power BI Semantic Models via Python
- 1 year ago
Please let me know if this post helped solve your problem. If so, I’ll mark it as solved to make it easier for others to find for similar future queries. Thanks 😊
I just tried running this code with a service principal and it returns the following:
Error 401: {"error":{"code":"PowerBINotAuthorizedException","pbi.error":{"code":"PowerBINotAuthorizedException","parameters":{},"details":[],"exceptionCulprit":1}}}
I think my service principal is configured correctly because when I change the URL to...
...I get a valid JSON response.
I suspect that this is because the Dataset.Read.All and Dataset.ReadWrite.All API permissions are delegated permissions not application permissions. Which would mean that they only take effect when a user is accessing the enterprise application. Is this correct?
Decoding the JWT generated seems to support this - only the application permissions are in the token:
"roles": [
"Tenant.ReadWrite.All",
"Tenant.Read.All"
]
Am I missing something in my configuration? Has something changed in the REST API?
I'd greatly appreciate any assistance you can provide with this.
- kushanNa4 months agoSuper User
Hi philip_gray
Yes, I’m using delegated permissions. actually I’m not an expert with the technical side of Azure app permissions, but my understanding is that delegated permissions mean the app acts on behalf of a user.
and I have tested it right now and it's still working for me :
- philip_gray4 months agoRegular Visitor
kushanNa Thanks for the response - much appreciated.
Would you be able to decode your JWT (the accesss_token part of the result variable) and confirm:
- the "idtyp" value
- The content of the "Roles" array
If you're using a service principal then the idtyp should be app and it shouldn't be possible for the roles to contain Dataset.Read.All or Dataset.ReadWrite.All - as these are only available as delegated permissions.