In Azure Synapse Analytics, I'm trying to create a code that returns a list with all notebook names.
In databricks I verified that it is possible by these two solutions:
, but I can't get a solution for synapse notebooks.
Can anyone please help me in achieving this?
Thank you!
#install msal using !pip install msal for getting bearer token
import msal
client_id = "<client_id>"
authority = "https://login.microsoftonline.com/<tenant_id>"
client_secret = "<client_secret>"
# Create a ConfidentialClientApplication instance
app = msal.ConfidentialClientApplication(client_id=client_id, authority=authority, client_credential=client_secret)
# Get the token
scopes = ["https://dev.azuresynapse.net/.default"]
result = app.acquire_token_for_client(scopes=scopes)
print(result)
import requests
response = requests.get("https://synapse3003.dev.azuresynapse.net/notebooks?api-version=2020-12-01", headers = {"Authorization":f"Bearer {result['access_token']}"}).json()
print(len(response['value']))
for i in response['value']:
print(i)
NOTE: You need to create a service principle by navigating to azure AD-> App registration. After that go to your synapse studio->manage tab->Access control and then add your service principle with appropriate role to create token as in above procedure.