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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
TalIL87
Frequent Visitor

403 error message while trying to hit PBI API (I am able to get the token)

Hi All!

I am tryng to user the new service proncipal profile feature in order to publish datasets on multiple tenents using PBI API.

I created an app registration, Azure AD group for the service principal and enabled all the relevat settings on the PBI servce.

 

I am able to get the service principal access token, but when I trying to use in order to ge t create a new profile I am getting a 403 error.

I have using the trial PPU license.

 

I am attaching the request that I am sending to the API

(using python)

 

token = GetServicePrincipalToken(APIParam['TenantID'],APIParam['ClientID'],APIParam['ClientSecret'])
api_url = "https://api.powerbi.com/v1.0/myorg/profiles"
headers = {"Authorization": f"Bearer {token}"}

payload = {"displayName": "My First Profile"}

response = requests.request("POST",api_url, json=payload, headers=headers)
#response = json.loads(response.text)
print(response)

 

 

I repreformed the entire procees of creating the Azure app registration, AD groups setting PBI service and took screenshot sthrought the entre prcess.

I used 2 guides: The full and official Microsoft guide on this link 

and the Youtube video on guy in a cube "Service principal 101" 

 

Link to Screenshot that I took throguht the entire proccess 

 

Appriciate the help, Tal

 

1 ACCEPTED SOLUTION
mshmordok
Microsoft Employee
Microsoft Employee

The AAD token you are generating in

GetServicePrincipalToken

is not set with the right audience 
make sure the token you are using is with the right audience for powerbi API's "https://analysis.windows.net/powerbi/api"

View solution in original post

7 REPLIES 7
Swetha__Balusam
New Member

Hi, I am using Power BI trial account. Using service principal to get the token to access power BI apis. I get the token and when I access the API https://api.powerbi.com/v1.0/myorg/datasets, I get the error {
"Message": "API is not accessible for application"
} with 403 error. Can you please help me on this?

waqas_ahmed
New Member

To get the access token for service principal profile, you have to use the following endpoint:

https://login.microsoftonline.com/<<tenant_id>>/oauth2/token 

The following 4 parameters should be passed to the body:

Sample request from postman:

Screenshot 2022-10-19 181640.png

mshmordok
Microsoft Employee
Microsoft Employee

The AAD token you are generating in

GetServicePrincipalToken

is not set with the right audience 
make sure the token you are using is with the right audience for powerbi API's "https://analysis.windows.net/powerbi/api"

Thank you! can you please refer me to the the documantion which explain how to generate the token usingthe https you mentioned?

Thank you, Tal

mshmordok
Microsoft Employee
Microsoft Employee

1. Did you manage to make any other calls to PowerBI with the specified App  
For example try to call 
https://docs.microsoft.com/en-us/rest/api/power-bi/groups/create-group 
If not that could indicate some miss configuration os your app or the aquired token 

2. Try to enable the Profiles feature to the entire org and see if that solve the problem 

mshmordok_0-1656396951446.png

 

3. If issue still not resolved then add the requestId from the Create Profile API 403 reponse to this thread so we can try track the failure

 

Hi! Thanks for the response

 

first, I want to check. Can I use the Service principal and the API with PPU or do I need premium capacity?

 

 

I turned all 3 settings to "The entire organization"

I send the request below and got the 403. I also tried using postman

Request ID: 88398de2-d060-4b65-997d-a821d44f36c4

(got the ID from Postman, not using the code below)

 

 

 

 

 

import requests
import json
from config import APIParam
from GetServicePrincipalToken import GetServicePrincipalToken




token = GetServicePrincipalToken(APIParam['TenantID'],APIParam['ClientID'],APIParam['ClientSecret'])
api_url = "https://api.powerbi.com/v1.0/myorg/groups?workspaceV2=True"
headers = {"Authorization": f"Bearer {token}"}

payload = {"name": "Sample workspace V2"}

response = requests.request("POST",api_url, json=payload, headers=headers)
#response = json.loads(response.text)
print(response)

 

 

 

 

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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