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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Igorvf83
New Member

Not found exception trying to create a token

Hello

I'm trying to use the embedded token but without any luck, i already create an app registration, i created a embedded capacity to test, get all API permission and the azure admin granted those permission, but i still have the not found exception when i try to create the token via C#

 

Microsoft.Rest.HttpOperationException: Operation returned an invalid status code 'NotFound'
at Microsoft.PowerBI.Api.ReportsOperations.<GenerateTokenInGroupWithHttpMessagesAsync>d__32.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.PowerBI.Api.ReportsOperationsExtensions.<GenerateTokenInGroupAsync>d__87.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.PowerBI.Api.ReportsOperationsExtensions.GenerateTokenInGroup(IReportsOperations operations, Guid groupId, Guid reportId, GenerateTokenRequest requestParameters)
at EmbedAPISample.Program.Main(String[] args) in E:\Testes de Codigo\CSharp\PowerBI\Token\Embed-API-Sample\EmbedAPISample\Program.cs:line 53

 

C# code

 

using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.PowerBI.Api;
using Microsoft.PowerBI.Api.Models;
using Microsoft.Rest;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace EmbedAPISample
{
    class Program
    {
        private static bool useEmbedToken = true;
        private static bool useRLS = false;

        private static string authorityUrl = "https://login.microsoftonline.com/organizations/"; 
        private static string resourceUrl = "https://analysis.windows.net/powerbi/api";
        private static string apiUrl = "https://api.powerbi.com/";

        private static string tenantId = "i put my tenant id here";
        private static Guid groupId = Guid.Parse("i put my group id here");
        
        private static Guid reportId = Guid.Parse("i put my report id here");
        private static Guid datasetId = Guid.Parse("i put my dataset id here"); 

        // **** Update the Client ID and Secret within Secrets.cs ****

        private static ClientCredential credential = null;
        private static AuthenticationResult authenticationResult = null;
        private static TokenCredentials tokenCredentials = null;

        static void Main(string[] args)
        {

            try
            {
                // Create a user password cradentials.
                credential = new ClientCredential(Secrets.ClientID, Secrets.ClientSecret);

                // Authenticate using created credentials
                Authorize().Wait();

                using (var client = new PowerBIClient(new Uri(apiUrl), tokenCredentials))
                {

 

 

What i'm doing wrong?

 

Thanks

0 REPLIES 0

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Kudoed Authors