Forum Discussion
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,
'scope': 'https://api.fabric.microsoft.com/.default'
}
token_r = requests.post(token_url, data=token_data)
access_token = token_r.json().get("access_token")
workspaceID = '*****'
api_url = f'https://api.fabric.microsoft.com/v1/workspaces/{workspaceID}/notebooks'
headers = {
"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'])
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!!
8 Replies
- yvaubourg
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.
- dobosdavidFrequent Visitor
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
Super User
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
headers = {'Authorization': f'Bearer {pbi_token}','Content-Type': 'application/json'}Step 2: Code to fetch notebooks for a specific workspaceresponse = requests.get(headers=headers,verify=False)Regards,SrisakthiIf this solution helps you, please mark "Accpet As Solution" , as it will help others who are lokking for similar solution.- dobosdavidFrequent Visitor
Thank you for the tip, unfortunately this didn't solve my issue.
- v-sathmakuri
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!!
- v-sathmakuri
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
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
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!!