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

Join us at FabCon Vienna from September 15-18, 2025, for the ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM. Get registered

Reply
dobosdavid
Frequent Visitor

Can't list notebook names from workspace

I'm trying to query to down all the notebooks' names in my current workspace. I'm using an entra id api to make the query that has the workspace.read.all permission and is added as admin to my workspace. I still get <Response [403]>. I get the access token successfully.

import
json

import requests

import msal

from azure.identity import ClientSecretCredential

from azure.keyvault.secrets import SecretClient

import requests

 

# Fetch the credentials using the service principal

v_tenant_id = notebookutils.credentials.getSecret(p_keyvault_url, p_secret_name_tenant)

v_client_id = notebookutils.credentials.getSecret(p_keyvault_url, p_secret_name_client)

v_client_secret = notebookutils.credentials.getSecret(p_keyvault_url, p_secret_name_secret)

 

# Create a credential using the service principal

v_credential = ClientSecretCredential(v_tenant_id, v_client_id, v_client_secret)

# Initialize SecretClient with Key Vault URL and the credentials

v_client = SecretClient(vault_url=p_keyvault_url, credential=v_credential)

token_url = f"https://login.microsoftonline.com/{v_tenant_id}/oauth2/v2.0/token"

token_data = {

    'grant_type': 'client_credentials',

    'client_id': v_client_id,

    'client_secret': v_client_secret,

}

 

token_r = requests.post(token_url, data=token_data)

 

access_token = token_r.json().get("access_token")

 

workspaceID = '*****'

 

   "Authorization": access_token,

   "Content-Type": "application/json"

}

 

res = requests.get(api_url,headers=headers)

 

note = res.json().get("value",[])

 

for note in note:

    if note['type'] == 'Notebook':

        print(note['displayName'])

1 ACCEPTED SOLUTION
v-sathmakuri
Community Support
Community Support

Hi @dobosdavid ,

 

Thank you for reaching out to Microsoft Fabric Community.

 

Thank you @dobosdavid  and @yvaubourg  for the response. 

 

First, in Azure Active Directory, navigate to App registrations and select your application. Under the API permissions section, add the necessary Application permission. Specifically, add Workspace.Read.All, Notebook.Read.All, and optionally Capacity.Read.All. After adding these permissions, be sure to click Grant admin consent to enable the app to use them.

 

Next, in the Power BI Admin Portal (https://app.powerbi.com/admin-portal ) , Under Tenant settings,

  • Allow service principals to use Power BI APIs - enable it
  • Allow service principals to access content – add your SP here
  • Ensure your Fabric workspace is in a capacity that allows service principals

If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

 

Thank you!!

View solution in original post

8 REPLIES 8
v-sathmakuri
Community Support
Community Support

Hi @dobosdavid ,

 

I hope the information provided is helpful. Feel free to reach out if you have any further questions or would like to discuss this in more detail. If responses provided answers your question, please accept it as a solution so other community members with similar problems can find a solution faster.

 

Thank you!!

v-sathmakuri
Community Support
Community Support

Hi @dobosdavid ,

 

I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If the responses has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.

 

Thank you!!

v-sathmakuri
Community Support
Community Support

Hi @dobosdavid ,

 

May I ask if the provided solution helped in resolving the issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

 

Thank you!!

v-sathmakuri
Community Support
Community Support

Hi @dobosdavid ,

 

Thank you for reaching out to Microsoft Fabric Community.

 

Thank you @dobosdavid  and @yvaubourg  for the response. 

 

First, in Azure Active Directory, navigate to App registrations and select your application. Under the API permissions section, add the necessary Application permission. Specifically, add Workspace.Read.All, Notebook.Read.All, and optionally Capacity.Read.All. After adding these permissions, be sure to click Grant admin consent to enable the app to use them.

 

Next, in the Power BI Admin Portal (https://app.powerbi.com/admin-portal ) , Under Tenant settings,

  • Allow service principals to use Power BI APIs - enable it
  • Allow service principals to access content – add your SP here
  • Ensure your Fabric workspace is in a capacity that allows service principals

If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

 

Thank you!!

yvaubourg
Resolver I
Resolver I

Hi @dobosdavid,

 

To request the Fabric API with a microsoft entra identity, you have to allow this in the tenant settings.

See the MS documentation here.

 

A best pratctice is to use a Security Group that is allowing you to manage exactly wich Entre Identity can use the MS Fabric API.

 

Hope this would help.

Hi, thank you for the tip.

I followed the guide and put the service principal in a security group and then allowed the security group to use fabric apis. It does not say anything else. My problem still stays.

Srisakthi
Continued Contributor
Continued Contributor

Hi @dobosdavid ,

 

Can you try using powerbi rest api to get the token? Im using the below code from notebook to fetch all notebooks under a workspace

For ex., 

Step 1: Using the below code to fetch token

pbi_token = mssparkutils.credentials.getToken('https://analysis.windows.net/powerbi/api')
headers = {
        'Authorization': f'Bearer {pbi_token}',
        'Content-Type': 'application/json'
}
Step 2: Code to fetch notebooks for a specific workspace
response = requests.get(
            url = f"https://api.fabric.microsoft.com/v1/workspaces/{target_workspace_id}/items?type=notebooks",
            headers=headers,
            verify=False)
 
Regards,
Srisakthi
 
If this solution helps you, please mark "Accpet As Solution" , as it will help others who are lokking for similar solution.
 

Thank you for the tip, unfortunately this didn't solve my issue.

Helpful resources

Announcements
May FBC25 Carousel

Fabric Monthly Update - May 2025

Check out the May 2025 Fabric 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.

Top Solution Authors