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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
Don-Bot
Helper V
Helper V

How to obtain an access token utilizing REST API?

I am looking to generate an access token that I can then utilize to edit/create datasets and reports in the power bi service. I came across this link but after attempting to use it I am getting the below error messages I am having problems resolving.

Can someone point me in the correct direction?  Below is the code I've attempted to use and the error messages I am receiving. 

 

DonBot_0-1696860521229.png

DonBot_1-1696860562883.png

DonBot_2-1696860749750.png

 

 

using System;
using Microsoft.IdentityModel.Clients.ActiveDirectory;

namespace walkthrough_push_data
{
    class Program
    {
        private static string token = string.Empty;

        static void Main(string[] args)
        {
            // Get an authentication access token
            token = GetToken();
        }

        private static async Task<string> GetToken()
        {
            string clientID = "{Client_ID}"; // The client id that Azure AD created when you registered your client app.
            string redirectUri = "https://login.live.com/oauth20_desktop.srf"; // RedirectUri you used when you register your app.
            string resourceUri = "https://analysis.windows.net/powerbi/api"; // Resource Uri for Power BI API
            string authorityUri = "https://login.microsoftonline.com/common/"; // OAuth2 authority Uri

            AuthenticationContext authContext = new AuthenticationContext(authorityUri);
            var result = await authContext.AcquireTokenAsync(resourceUri, clientID, new Uri(redirectUri));

            Console.WriteLine(result.AccessToken);
            Console.ReadLine();

            return result.AccessToken;
        }
    }
}

 

1 REPLY 1
lbendlin
Super User
Super User

Have you completed the app registration including asking for the right scope?

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

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.