<?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: Using Power BI API in C# in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4923978#M64382</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/901438"&gt;@bigmac025&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Just checking in to see if you were able to make any progress on this. If you are still running into issues or have questions while reviewing the tenant settings, please let us know.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
    <pubDate>Fri, 23 Jan 2026 05:46:22 GMT</pubDate>
    <dc:creator>v-veshwara-msft</dc:creator>
    <dc:date>2026-01-23T05:46:22Z</dc:date>
    <item>
      <title>Using Power BI API in C#</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4913409#M64296</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was wondering if anyone has experiance to use the Power BI API in C#?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created a C# .NET Console App using the PowerBI API Library to connect to the Power BI API to get a list of groups, reports, etc.&amp;nbsp; I would like to use the application I am creating to access the Power BI API and get data so I can automate the analyze and audit processes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Prior to programming I went into Azure and set up the App Registration per this document:&amp;nbsp;&lt;A href="https://www.vahiddm.com/post/call-power-bi-rest-api-with-power-automate" target="_blank" rel="noopener"&gt;https://www.vahiddm.com/post/call-power-bi-rest-api-with-power-automate&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My C# application, I can get the token but then I get a 401 Un-authorized error.&amp;nbsp; Here is the error information I get:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Non-admin groups: 0&lt;BR /&gt;Status: 401 Unauthorized&lt;BR /&gt;Response content:&lt;/P&gt;&lt;P&gt;Pragma: no-cache&lt;BR /&gt;Transfer-Encoding: chunked&lt;BR /&gt;Strict-Transport-Security: max-age=31536000; includeSubDomains&lt;BR /&gt;X-Frame-Options: deny&lt;BR /&gt;X-Content-Type-Options: nosniff&lt;BR /&gt;RequestId: 2ad55907-50ad-49e8-964b-9a7d9de14eef&lt;BR /&gt;Access-Control-Expose-Headers: RequestId&lt;BR /&gt;Cache-Control: no-store, must-revalidate, no-cache&lt;BR /&gt;Date: Tue, 06 Jan 2026 21:01:31 GMT&lt;BR /&gt;Content-Type: application/octet-stream&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code that I am using:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;class PowerBI
{
    public async System.Threading.Tasks.Task getPowerBIWorkspaceData()
    {
        //instantiate the api object 
        API api = new API();

        string accessToken = await api.getPowerBIAccessToken();

        Console.WriteLine(accessToken);

        var credentials = new TokenCredentials(accessToken, "Bearer");
        var apiUrl = "https://[Removed]"; // Base URL for the Power BI Service API

        using (var client = new PowerBIClient(new Uri(apiUrl), credentials))
        {
            try
            {
                var g = await client.Groups.GetGroupsAsync();
                Console.WriteLine($"Non-admin groups: {g.Value?.Count ?? 0}");

                // Example: Get a list of workspaces (groups)
                var workspaces = await client.Groups.GetGroupsAsAdminAsync(top: 500);
                Console.WriteLine($"Found {workspaces.Value?.Count ?? 0} workspaces.");

                // You can now call other APIs, e.g., to get reports in a specific workspace
                if (workspaces.Value.Count &amp;gt; 0)
                {
                    var groupId = workspaces.Value[0].Id;
                    var reports = await client.Reports.GetReportsInGroupAsync(groupId);
                    Console.WriteLine($"Workspace has {reports.Value.Count} reports.");
                }
        }
            catch (Microsoft.Rest.HttpOperationException ex)
            {
            Console.WriteLine($"Status: {(int)ex.Response.StatusCode} {ex.Response.StatusCode}");
            Console.WriteLine("Response content:");
            Console.WriteLine(ex.Response.Content);

            // If headers exist, print them (sometimes the key clue is here)
            if (ex.Response.Headers != null)
            {
                foreach (var h in ex.Response.Headers)
                    Console.WriteLine($"{h.Key}: {string.Join(",", h.Value)}");
            }

            throw;
        }

    }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Tim&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jan 2026 21:04:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4913409#M64296</guid>
      <dc:creator>bigmac025</dc:creator>
      <dc:date>2026-01-06T21:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: Using Power BI API in C#</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4913747#M64299</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/901438"&gt;@bigmac025&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Thanks for reaching out to Microsoft Fabric Community and for sharing the document reference.&lt;/P&gt;
&lt;P data-start="264" data-end="620"&gt;When using GetGroupsAsAdminAsync() with service principal authentication, Power BI validates tenant level settings and admin role assignment rather than delegated scopes. In the Power BI Admin portal, ensure that Allow service principals to use Power BI APIs is enabled under Tenant settings, and that your service principal or the security group containing it is added to the allowed list. The service principal must also have Fabric Admin role assigned. If any of these are missing, the API returns 401 even with a valid token.&lt;/P&gt;
&lt;P data-start="264" data-end="620"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-start="622" data-end="899"&gt;This behavior is documented here:&lt;BR data-start="655" data-end="658" /&gt;&lt;A href="https://learn.microsoft.com/en-us/power-bi/developer/embedded/embed-service-principal?tabs=azure-portal#step-3---enable-the-power-bi-service-admin-settings" target="_blank"&gt;Embed Power BI content in an embedded analytics application with service principal and an application secret - Power BI | Microsoft Learn&lt;/A&gt;&lt;BR data-start="736" data-end="739" /&gt;&lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/admin/groups-get-groups-as-admin" target="_blank"&gt;Admin - Groups GetGroupsAsAdmin - REST API (Power BI Power BI REST APIs) | Microsoft Learn&lt;/A&gt;&lt;BR data-start="818" data-end="821" /&gt;&lt;A href="https://learn.microsoft.com/en-us/fabric/admin/enable-service-principal-admin-apis" target="_blank"&gt;Enable service principal authentication for admin APIs - Microsoft Fabric | Microsoft Learn&lt;/A&gt;&lt;/P&gt;
&lt;P data-start="622" data-end="899"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-start="901" data-end="1274"&gt;There are also similar community threads where the same issue was resolved by updating tenant settings or admin role assignment:&lt;BR data-start="1029" data-end="1032" /&gt;&lt;A href="https://community.fabric.microsoft.com/t5/Developer/Power-Bi-REST-API-401-Authorization-error-when-using-Service/m-p/3503590/highlight/true#M45166" target="_blank"&gt;Solved: Re: Power Bi REST API - 401 Authorization error wh... - Microsoft Fabric Community&lt;/A&gt;&lt;BR data-start="1155" data-end="1158" /&gt;&lt;A href="https://community.fabric.microsoft.com/t5/Developer/Unauthorized-401-when-accessing-Power-BI-Admin-API/m-p/4012710" target="_blank"&gt;Solved: Re: Unauthorized 401 when accessing Power BI Admin... - Microsoft Fabric Community&lt;/A&gt;&lt;/P&gt;
&lt;P data-start="901" data-end="1274"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-start="1276" data-end="1417" data-is-last-node="" data-is-only-node=""&gt;Once the service principal is enabled in the tenant settings and has the required admin role, the existing API calls should work as expected.&lt;/P&gt;
&lt;P data-start="1276" data-end="1417" data-is-last-node="" data-is-only-node=""&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps. Please reach out for further assistance.&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jan 2026 09:47:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4913747#M64299</guid>
      <dc:creator>v-veshwara-msft</dc:creator>
      <dc:date>2026-01-07T09:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: Using Power BI API in C#</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4913879#M64300</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/901438"&gt;@bigmac025&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Your Code almost fine and the 401 error is caused due to&amp;nbsp;authentication configuration (not the Power BI SDK itself)&lt;/P&gt;&lt;P&gt;Also the two biggest issues I see are token audience and admin or service principal permissions that caused this issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;So you need to ensure&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;the access token is for Power BI&lt;/FONT&gt; &lt;/STRONG&gt;(most common issue)&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Keep in mind even if you successfully get a token....Power BI will return 401 if the token was issued for the wrong resource So when&amp;nbsp;using client credentials the token must be requested with this scope:&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="markup"&gt;https://analysis.windows.net/powerbi/api/.default&lt;/LI-CODE&gt;&lt;UL&gt;&lt;LI&gt;Also If the token’s &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;aud&lt;/FONT&gt;&lt;/STRONG&gt; claim is anything else like&amp;nbsp;Microsoft Graph for an example.....Power BI will reject it&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Make Sure to Use the correct Power BI base URL which is:&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="markup"&gt;var apiUrl = "https://api.powerbi.com/";&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Also you need to know that &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;GetGroupsAsAdminAsync()&lt;/FONT&gt;&lt;/STRONG&gt; requires admin or service principal setup&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;The token belongs to a Power BI / Fabric Admin user or you are using a service principal (and A&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;llow service principals to use Power BI APIs&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;is enabled in&amp;nbsp;Power BI Admin Portal)&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;If you dont need tenant wide access remove this line to be like this:&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="markup"&gt;client.Groups.GetGroupsAsync()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The Last thing thats for app only authentication the service principal must be added to the workspace explicitly (Viewer/Contributor/Admin) or included in an AAD security group that has workspace access (&lt;P&gt;Otherwise Power BI will return 401 or 403, even with a valid token)&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;EM&gt;if this post helps, then I would appreciate a thumbs up&lt;/EM&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;and&amp;nbsp;&lt;STRONG&gt;mark it as the solution&lt;/STRONG&gt;&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;to help the other members find it more quickly.&lt;/EM&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 07 Jan 2026 12:56:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4913879#M64300</guid>
      <dc:creator>Ahmed-Elfeel</dc:creator>
      <dc:date>2026-01-07T12:56:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using Power BI API in C#</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4914275#M64303</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/838901"&gt;@Ahmed-Elfeel&lt;/a&gt;&amp;nbsp;and &lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/882993"&gt;@v-veshwara-msft&lt;/a&gt;&amp;nbsp;for you help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I followed the information you sent me.&amp;nbsp; After reviewing, I couldn't find anything wrong so I went to this page:&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/admin/groups-get-groups-as-admin?tryIt=true&amp;amp;source=docs#code-try-0" target="_blank"&gt;https://learn.microsoft.com/en-us/rest/api/power-bi/admin/groups-get-groups-as-admin?tryIt=true&amp;amp;source=docs#code-try-0&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I copied the Bearer Token from the page and then pasted it into my C# app and got this message:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Non-admin groups: 2&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Found 238 workspaces.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Status: 401 Unauthorized&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Response content:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;X-PowerBI-Error-Info: GroupNotAccessible&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Strict-Transport-Security: max-age=31536000; includeSubDomains&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;X-Frame-Options: deny&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;X-Content-Type-Options: nosniff&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Access-Control-Expose-Headers: RequestId,X-PowerBI-Error-Info&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;request-redirected: true&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;home-cluster-uri: &lt;A href="https://wabi-germany-west-central-primary-redirect.analysis.windows.net/" target="_blank"&gt;https://wabi-germany-west-central-primary-redirect.analysis.windows.net/&lt;/A&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;RequestId: 49a16e45-e847-4323-a0b1-04f97ae4111f&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Date: Thu, 08 Jan 2026 00:43:37 GMT&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Content-Length: 0&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can see that worked and it returned 238 workspaces.&lt;/P&gt;&lt;P&gt;That leads me to believe that I am getting the wrong token when I call my API my getToken Method.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code for getting the token:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;class API
{
    public async Task&amp;lt;string&amp;gt; getPowerBIAccessToken()
    {

        var tenantId = "removed";
        var clientId = "removed";
        var clientSecret = "removed";

        // The Power BI API scope
        var scopes = new[] { "https://analysis.windows.net/powerbi/api/.default" };

        var app = ConfidentialClientApplicationBuilder.Create(clientId)
            .WithClientSecret(clientSecret)
            .WithAuthority(new Uri($"https://login.microsoftonline.com/{tenantId}"))
            .Build();

        var authResult = await app.AcquireTokenForClient(scopes).ExecuteAsync();

        return authResult.AccessToken;

    }
}&lt;/LI-CODE&gt;&lt;P&gt;It returns a token but obvisouly an invalid one.&amp;nbsp; Any help would be appreciated to tell me why I am getting a token that doesn't work and how to get one that works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Tim&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jan 2026 01:16:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4914275#M64303</guid>
      <dc:creator>bigmac025</dc:creator>
      <dc:date>2026-01-08T01:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using Power BI API in C#</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4914468#M64308</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/901438"&gt;@bigmac025&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Thanks for sharing the additional details and for testing with the token from the Try It experience.&lt;/P&gt;
&lt;P&gt;The AcquireTokenForClient call and the scope you are using are correct, and the token itself is being accepted by the Power BI service.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The important clue is the response header X-PowerBI-Error-Info: GroupNotAccessible. This indicates an authorization issue at the workspace level, not a problem with the token.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the code you shared, GetGroupsAsync() is still being executed. This API is user scoped and is not supported when using service principal (app only) authentication.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/fabric/admin/enable-service-principal-admin-apis#supported-power-bi-admin-apis-for-read-only" target="_blank" rel="noopener"&gt;Enable service principal authentication for admin APIs - Microsoft Fabric | Microsoft Learn&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are also calling non admin APIs such as GetReportsInGroupAsync. For these calls, the service principal must be explicitly granted access to the workspace, either directly or via an Entra ID security group, with at least Viewer permissions. Without workspace access, Power BI will return 401 or 403 even with a valid token.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For tenant wide discovery using a service principal, GetGroupsAsAdminAsync() is the supported approach. For any workspace scoped operations, ensure the service principal has access to the target workspace.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the issue is caused by a mismatch between the API being called and the authorization context, rather than an invalid or expired token.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps. Please reach out for further assistance.&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jan 2026 08:49:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4914468#M64308</guid>
      <dc:creator>v-veshwara-msft</dc:creator>
      <dc:date>2026-01-08T08:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using Power BI API in C#</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4914492#M64309</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/901438"&gt;@bigmac025&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure which of the API calls fails for you, I can see 2 at least different ones in the code you've shared:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var workspaces = await client.Groups.GetGroupsAsAdminAsync(top: 500);&lt;BR /&gt;var reports = await client.Reports.GetReportsInGroupAsync(groupId);&lt;BR /&gt;&lt;BR /&gt;If the service principal is a tenant admin then the first one should work.&lt;/P&gt;&lt;P&gt;For the second one to work the service principal need to be at least a viewer in the workspace. Not every admin user can call this API for any workspace in the tenant. Can this be the reason?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jan 2026 08:26:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4914492#M64309</guid>
      <dc:creator>AmosHersch</dc:creator>
      <dc:date>2026-01-08T08:26:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using Power BI API in C#</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4916356#M64324</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/901438"&gt;@bigmac025&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;Just wanted to check if the responses provided were helpful. If further assistance is needed, please reach out. Also thanks&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/278935"&gt;@AmosHersch&lt;/a&gt;&amp;nbsp;for sharing your insights.&lt;BR /&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jan 2026 04:56:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4916356#M64324</guid>
      <dc:creator>v-veshwara-msft</dc:creator>
      <dc:date>2026-01-12T04:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using Power BI API in C#</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4917053#M64335</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/882993"&gt;@v-veshwara-msft&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm still having issues getting this C# app to work...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for all the help you have given me.&amp;nbsp; I have read all suggestions and documentation sent to me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my modified code from all the help I have recieved:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;class PowerBI
{
    public async System.Threading.Tasks.Task getPowerBIWorkspaceData()
    {
        //instantiate the api object 
        API api = new API();

        string accessToken = await api.getPowerBIAccessToken();
        Console.WriteLine(accessToken);

        var credentials = new TokenCredentials(accessToken, "Bearer");
        //var apiUrl = "https://removed"; // Base URL for the Power BI Service API

        var apiUrl = "https://api.powerbi.com/";

        using (var client = new PowerBIClient(new Uri(apiUrl), credentials))
        {
            try
            {
                
                // Example: Get a list of workspaces (groups)
                var workspaces = await client.Groups.GetGroupsAsAdminAsync(top: 500);
                Console.WriteLine($"Found {workspaces.Value?.Count ?? 0} workspaces.");

                // You can now call other APIs, e.g., to get reports in a specific workspace
                if (workspaces.Value.Count &amp;gt; 0)
                {
                    var groupId = workspaces.Value[0].Id;
                    var reports = await client.Reports.GetReportsAsAdminAsync(groupId);
                    Console.WriteLine($"Workspace has {reports.Value.Count} reports.");
                }
            }
            catch (Microsoft.Rest.HttpOperationException ex)
            {
                Console.WriteLine($"Status: {(int)ex.Response.StatusCode} {ex.Response.StatusCode}");
                Console.WriteLine("Response content:");
                Console.WriteLine(ex.Response.Content);

                //If headers exist, print them (sometimes the key clue is here)
                if (ex.Response.Headers != null)
                {
                    foreach (var h in ex.Response.Headers)
                        Console.WriteLine($"{h.Key}: {string.Join(",", h.Value)}");
                }

            }

        }
    }
}

class API
{
    public async Task&amp;lt;string&amp;gt; getPowerBIAccessToken()
    {

        var tenantId = "removed";
        var clientId = "removed";
        var clientSecret = "removed";

        // The Power BI API scope
        var scopes = new[] { "https://analysis.windows.net/powerbi/api/.default" };

        var app = ConfidentialClientApplicationBuilder.Create(clientId)
            .WithClientSecret(clientSecret)
            .WithAuthority(new Uri($"https://login.microsoftonline.com/{tenantId}"))
            .Build();

        var authResult = await app.AcquireTokenForClient(scopes).ExecuteAsync();

        return authResult.AccessToken;

    }
}
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I still get this error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Status: 401 Unauthorized&lt;BR /&gt;Response content:&lt;/P&gt;&lt;P&gt;Pragma: no-cache&lt;BR /&gt;Transfer-Encoding: chunked&lt;BR /&gt;Strict-Transport-Security: max-age=31536000; includeSubDomains&lt;BR /&gt;X-Frame-Options: deny&lt;BR /&gt;X-Content-Type-Options: nosniff&lt;BR /&gt;RequestId: ab38caa1-e7f7-47de-97d1-3a3101cce68e&lt;BR /&gt;Access-Control-Expose-Headers: RequestId&lt;BR /&gt;request-redirected: true&lt;BR /&gt;home-cluster-uri: &lt;A href="https://wabi-germany-west-central-primary-redirect.analysis.windows.net/" target="_blank"&gt;https://wabi-germany-west-central-primary-redirect.analysis.windows.net/&lt;/A&gt;&lt;BR /&gt;Cache-Control: no-store, must-revalidate, no-cache&lt;BR /&gt;Date: Mon, 12 Jan 2026 21:03:49 GMT&lt;BR /&gt;Content-Type: application/octet-stream&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I then checked the token's aud claim and got this in the decoded token:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"roles": [&lt;BR /&gt;"Tenant.ReadWrite.All",&lt;BR /&gt;"Tenant.Read.All"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From my understanding this proves my&amp;nbsp;MSAL token is correct for Power BI and it’s an app-only token.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any other things I can check?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jan 2026 22:20:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4917053#M64335</guid>
      <dc:creator>bigmac025</dc:creator>
      <dc:date>2026-01-12T22:20:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using Power BI API in C#</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4917232#M64338</link>
      <description>&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/901438"&gt;@bigmac025&lt;/a&gt;&amp;nbsp;I suspect that for service principal you shouldn't have any admin roles in the token, see here:&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/admin/groups-get-groups-as-admin" target="_blank"&gt;Admin - Groups GetGroupsAsAdmin - REST API (Power BI Power BI REST APIs) | Microsoft Learn&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;"&lt;SPAN&gt;Tenant.Read.All or Tenant.ReadWrite.All&lt;/SPAN&gt;&lt;BR /&gt;Relevant only when authenticating via a standard delegated admin access token. &lt;STRONG&gt;Must not be present when authentication via a service principal is used.&lt;/STRONG&gt;"&lt;BR /&gt;Can you try again after removing those roles?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jan 2026 08:37:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4917232#M64338</guid>
      <dc:creator>AmosHersch</dc:creator>
      <dc:date>2026-01-13T08:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using Power BI API in C#</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4917282#M64340</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/901438"&gt;@bigmac025&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Thanks for the update and for sharing the decoded token details.&lt;/P&gt;
&lt;P&gt;To clarify the point around roles and permissions, the &lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/admin/groups-get-groups-as-admin#permissions" target="_self"&gt;documentation&lt;/A&gt; is referring to delegated Power BI permissions when it states that admin-consent required permissions must not be present for service principal authentication. In an app-only setup, the app registration should not have any delegated Power BI permissions configured.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This does not conflict with assigning a Power BI Admin or Fabric Admin tenant role to the service principal. Tenant roles are evaluated by the Power BI service at runtime and are separate from Azure AD delegated permissions. Admin REST APIs such as GetGroupsAsAdminAsync() are authorized based on tenant-level configuration, not on delegated scopes in the token.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So to address both points together, including &lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/278935"&gt;@AmosHersch&lt;/a&gt;&amp;nbsp;'s comment, the presence of Tenant.Read.All or Tenant.ReadWrite.All in an app-only token does not cause the 401 and does not need to be removed. Those scopes are relevant only for delegated admin user tokens and are ignored when using service principal authentication.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the token itself is valid, a 401 from GetGroupsAsAdminAsync() still points to tenant-level authorization. Please recheck that service principal access is enabled in the Power BI Admin portal and that the service principal or its security group is allowed, that the service principal has a Power BI Admin or Fabric Admin tenant role, and that no delegated Power BI permissions are configured on the app registration.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once these are in place, the updated code using GetGroupsAsAdminAsync() and GetReportsAsAdminAsync() should work as expected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps. Please reach out for further assistance.&lt;BR /&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jan 2026 10:23:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4917282#M64340</guid>
      <dc:creator>v-veshwara-msft</dc:creator>
      <dc:date>2026-01-13T10:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using Power BI API in C#</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4919146#M64349</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/901438"&gt;@bigmac025&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;Just wanted to check if the response provided was helpful. If further assistance is needed, please reach out.&lt;BR /&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jan 2026 07:10:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4919146#M64349</guid>
      <dc:creator>v-veshwara-msft</dc:creator>
      <dc:date>2026-01-16T07:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using Power BI API in C#</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4919742#M64355</link>
      <description>&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/882993"&gt;@v-veshwara-msft&lt;/a&gt;&amp;nbsp;Still going through all the advise and seeing if I can figure out the security.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Tim&lt;/P&gt;</description>
      <pubDate>Sat, 17 Jan 2026 00:57:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4919742#M64355</guid>
      <dc:creator>bigmac025</dc:creator>
      <dc:date>2026-01-17T00:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: Using Power BI API in C#</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4920525#M64360</link>
      <description>&lt;P data-start="0" data-end="27"&gt;Thanks for the update, Tim.&lt;/P&gt;
&lt;P data-start="29" data-end="235" data-is-last-node="" data-is-only-node=""&gt;No problem. This does point to tenant level security and role configuration rather than the code itself. Take your time reviewing those settings, and feel free to update the thread if you need further help.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jan 2026 07:17:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4920525#M64360</guid>
      <dc:creator>v-veshwara-msft</dc:creator>
      <dc:date>2026-01-19T07:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: Using Power BI API in C#</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4923978#M64382</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/901438"&gt;@bigmac025&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Just checking in to see if you were able to make any progress on this. If you are still running into issues or have questions while reviewing the tenant settings, please let us know.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jan 2026 05:46:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4923978#M64382</guid>
      <dc:creator>v-veshwara-msft</dc:creator>
      <dc:date>2026-01-23T05:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using Power BI API in C#</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4926284#M64384</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/882993"&gt;@v-veshwara-msft&lt;/a&gt;&amp;nbsp;I am still having the issue.&amp;nbsp; I'm going to accept the last suggestion as the solution because I know it has something to do with security.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jan 2026 22:04:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Using-Power-BI-API-in-C/m-p/4926284#M64384</guid>
      <dc:creator>bigmac025</dc:creator>
      <dc:date>2026-01-23T22:04:59Z</dc:date>
    </item>
  </channel>
</rss>

