<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Fabric APIs from notebook using SPN auth in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Fabric-APIs-from-notebook-using-SPN-auth/m-p/4645082#M8502</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="788986" data-lia-user-login="g3kuser" class="lia-mention lia-mention-user"&gt;g3kuser&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for reaching out to Microsoft Fabric Community Forum.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the notebook is being executed under a Service Principal (SPN), you'll need to ensure the app registration in Azure AD is correctly configured for the required permissions.&lt;/P&gt;
&lt;P&gt;--Register the SPN (app) in Azure Active Directory, and assign the necessary API permissions for Microsoft Fabric.&lt;/P&gt;
&lt;P&gt;--Recommended application-level permissions:&lt;/P&gt;
&lt;P&gt;Tenant.Read.All&lt;/P&gt;
&lt;P&gt;Workspace.ReadWrite.All&lt;/P&gt;
&lt;P&gt;Shortcut.Create.All (if available)&lt;/P&gt;
&lt;P&gt;--If you’re using the client credentials flow, you can also work with the /.default scope to inherit all granted permissions.&lt;/P&gt;
&lt;P&gt;--After adding the permissions, make sure an Azure AD Admin grants admin consent to them.&lt;/P&gt;
&lt;P&gt;Then, you can authenticate using the ClientSecretCredential as follows:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;scope = '&lt;A href="https://api.fabric.microsoft.com/.default" target="_blank"&gt;https://api.fabric.microsoft.com/.default&lt;/A&gt;'&lt;BR /&gt;credential = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)&lt;BR /&gt;access_token = credential.get_token(scope)&lt;BR /&gt;token_string = access_token.token&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This approach ensures that your Service Principal has the correct permissions to perform operations like creating shortcuts or managing connections through the Fabric APIs.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;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!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;B Manikanteswara Reddy&lt;/P&gt;</description>
    <pubDate>Wed, 09 Apr 2025 12:57:51 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2025-04-09T12:57:51Z</dc:date>
    <item>
      <title>Fabric APIs from notebook using SPN auth</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Fabric-APIs-from-notebook-using-SPN-auth/m-p/4644382#M8487</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to call Fabric APIs from notebook to get workspace, items and create shortcuts but getting following error just for shortcut creation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;'errorCode': 'InsufficientScopes', 'message': 'The caller does not have sufficient scopes to perform this operation'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The notebook owner is SPN as it is deployed through fabric ci-cd python library.&lt;/P&gt;&lt;P&gt;I tried following scopes but nothing worked for shortcut creation.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;token_string&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; mssparkutils.credentials.getToken(&lt;/SPAN&gt;&lt;SPAN&gt;"pbi"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;SPAN&gt;token_string&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; mssparkutils.credentials.getToken(&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;A href="https://api.fabric.microsoft.com/.default" target="_blank" rel="noopener"&gt;https://api.fabric.microsoft.com/.default&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Similarly getting error while retrieving connections /v1/connections.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I noticed if I explicitly get token through&amp;nbsp;&lt;SPAN&gt;ClientSecretCredential class and it worked fine to create shortcuts.&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;scope&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;'&lt;A href="https://api.fabric.microsoft.com/.default" target="_blank" rel="noopener"&gt;https://api.fabric.microsoft.com/.default&lt;/A&gt;'&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;client_secret_credential_class&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;ClientSecretCredential&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;tenant_id&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;tenant_id&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;client_id&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;client_id&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;client_secret&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;client_secret&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;access_token_class&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;client_secret_credential_class&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;get_token&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;scope&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;token_string&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;access_token_class&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;token&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I would like to get this working without explicitly setting up credential class as it would work for any executing user either named user/SPN.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Any thoughts?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Gayatri&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 06:54:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Fabric-APIs-from-notebook-using-SPN-auth/m-p/4644382#M8487</guid>
      <dc:creator>g3kuser</dc:creator>
      <dc:date>2025-04-09T06:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: Fabric APIs from notebook using SPN auth</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Fabric-APIs-from-notebook-using-SPN-auth/m-p/4645082#M8502</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="788986" data-lia-user-login="g3kuser" class="lia-mention lia-mention-user"&gt;g3kuser&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for reaching out to Microsoft Fabric Community Forum.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the notebook is being executed under a Service Principal (SPN), you'll need to ensure the app registration in Azure AD is correctly configured for the required permissions.&lt;/P&gt;
&lt;P&gt;--Register the SPN (app) in Azure Active Directory, and assign the necessary API permissions for Microsoft Fabric.&lt;/P&gt;
&lt;P&gt;--Recommended application-level permissions:&lt;/P&gt;
&lt;P&gt;Tenant.Read.All&lt;/P&gt;
&lt;P&gt;Workspace.ReadWrite.All&lt;/P&gt;
&lt;P&gt;Shortcut.Create.All (if available)&lt;/P&gt;
&lt;P&gt;--If you’re using the client credentials flow, you can also work with the /.default scope to inherit all granted permissions.&lt;/P&gt;
&lt;P&gt;--After adding the permissions, make sure an Azure AD Admin grants admin consent to them.&lt;/P&gt;
&lt;P&gt;Then, you can authenticate using the ClientSecretCredential as follows:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;scope = '&lt;A href="https://api.fabric.microsoft.com/.default" target="_blank"&gt;https://api.fabric.microsoft.com/.default&lt;/A&gt;'&lt;BR /&gt;credential = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)&lt;BR /&gt;access_token = credential.get_token(scope)&lt;BR /&gt;token_string = access_token.token&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This approach ensures that your Service Principal has the correct permissions to perform operations like creating shortcuts or managing connections through the Fabric APIs.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;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!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;B Manikanteswara Reddy&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 12:57:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Fabric-APIs-from-notebook-using-SPN-auth/m-p/4645082#M8502</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2025-04-09T12:57:51Z</dc:date>
    </item>
    <item>
      <title>Re: Fabric APIs from notebook using SPN auth</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Fabric-APIs-from-notebook-using-SPN-auth/m-p/4645774#M8513</link>
      <description>&lt;P&gt;My app is granted correct permission and I can make the calls successul by explicitly initializing credential object but it fails when only for few endpoints when I don't initialize and get token through mssparkutils.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;token_string&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;mssparkutils.credentials.getToken(&lt;/SPAN&gt;&lt;SPAN&gt;"pbi"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;SPAN&gt;token_string&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;mssparkutils.credentials.getToken(&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;&lt;A href="https://api.fabric.microsoft.com/.default" target="_blank" rel="noopener nofollow noreferrer"&gt;https://api.fabric.microsoft.com/.default&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I don't want to initialize credential class explicilty as I am trying to develop a framework wherein if executed by named user/SPN it should generate the same results.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I also tried to identify executing user in notebook using mssparkutils.env.getUserName which returns entire email of named user but in case of SPN as executing user it fails. Atleast if I find a way to differentiate then I split the flow as needed.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Gayatri&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 09 Apr 2025 23:10:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Fabric-APIs-from-notebook-using-SPN-auth/m-p/4645774#M8513</guid>
      <dc:creator>g3kuser</dc:creator>
      <dc:date>2025-04-09T23:10:22Z</dc:date>
    </item>
    <item>
      <title>Re: Fabric APIs from notebook using SPN auth</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Fabric-APIs-from-notebook-using-SPN-auth/m-p/4649016#M8544</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="788986" data-lia-user-login="g3kuser" class="lia-mention lia-mention-user"&gt;g3kuser&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;As you're building a generic framework that should work for both named users and SPNs, but you're hitting limitations where:&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;gt;&amp;gt;Direct use of ClientSecretCredential works for SPNs.&lt;/DIV&gt;
&lt;DIV&gt;&amp;gt;&amp;gt;mssparkutils.credentials.getToken(...) does not work for some endpoints (e.g., shortcut creation, connections) under SPN context.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Cause for the issue might be,&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;The token retrieved using mssparkutils.credentials.getToken(...) does not always include all required scopes — particularly for application-level permissions used by SPNs. It's likely retrieving a user-delegated token, or a token with limited/default scopes.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;This mismatch causes InsufficientScopes errors on more privileged Fabric APIs like:&lt;/DIV&gt;
&lt;DIV&gt;*POST /v1/workspaces/{workspaceId}/shortcuts&lt;/DIV&gt;
&lt;DIV&gt;*GET /v1/connections&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;These often require app-level roles and proper access tokens issued via the client credentials flow.&lt;/DIV&gt;
&lt;DIV&gt;We can suggest that,&lt;/DIV&gt;
&lt;DIV&gt;Since you want a framework-agnostic approach, here’s how you can proceed:&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;**Differentiate Named User vs SPN Execution&lt;/DIV&gt;
&lt;DIV&gt;Use this logic to detect if the notebook is running under a user or an SPN:&lt;/DIV&gt;
&lt;DIV&gt;try:&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; user = mssparkutils.env.getUserName()&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; is_spn = False&lt;/DIV&gt;
&lt;DIV&gt;except:&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; is_spn = True&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;else, you can check the structure of the returned token or decode the JWT to see if it’s an app (SPN) or user principal.&lt;/DIV&gt;
&lt;DIV&gt;Split Authentication Flow Dynamically&lt;/DIV&gt;
&lt;DIV&gt;if is_spn:&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; # Use explicit credential (ClientSecretCredential) for SPN&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; scope = "&lt;A href="https://api.fabric.microsoft.com/.default" target="_blank"&gt;https://api.fabric.microsoft.com/.default&lt;/A&gt;"&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; credential = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; access_token = credential.get_token(scope)&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; token_string = access_token.token&lt;/DIV&gt;
&lt;DIV&gt;else:&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; # Use mssparkutils for user context&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; token_string = mssparkutils.credentials.getToken("&lt;A href="https://api.fabric.microsoft.com/.default" target="_blank"&gt;https://api.fabric.microsoft.com/.default&lt;/A&gt;")&lt;/DIV&gt;
&lt;DIV&gt;This ensures the right token with correct scopes is used based on the execution context.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;If these workarounds don't help you,&lt;/DIV&gt;
&lt;DIV&gt;I suggest reaching out to Microsoft Support by raising a ticket. Microsoft will analyze backend logs and provide a resolution&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Below is the link to create Microsoft support ticket:&lt;/DIV&gt;
&lt;DIV&gt;&lt;A href="https://learn.microsoft.com/en-us/power-bi/support/create-support-ticket" target="_self"&gt;https://learn.microsoft.com/en-us/power-bi/support/create-support-ticket&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;EM&gt;&lt;STRONG&gt;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!&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;B Manikanteswara Reddy&lt;/DIV&gt;</description>
      <pubDate>Fri, 11 Apr 2025 15:48:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Fabric-APIs-from-notebook-using-SPN-auth/m-p/4649016#M8544</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2025-04-11T15:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: Fabric APIs from notebook using SPN auth</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Fabric-APIs-from-notebook-using-SPN-auth/m-p/4651234#M8574</link>
      <description>&lt;P&gt;Thanks for the confirmation. I have done the same with additional email regex check. Just in case in future the getUserName method ends up returning application name in case of SPN as executing user.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Gayatri&lt;/P&gt;</description>
      <pubDate>Mon, 14 Apr 2025 11:04:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Fabric-APIs-from-notebook-using-SPN-auth/m-p/4651234#M8574</guid>
      <dc:creator>g3kuser</dc:creator>
      <dc:date>2025-04-14T11:04:29Z</dc:date>
    </item>
  </channel>
</rss>

