Search code examples
azurepowerbi-embeddedazure-management-api

PowerBi Embedded suspend and resume capacity using .NET SDK


I'm trying to figure out whether there is a azure management NuGet package that I can use to communicate with this part of the API for suspending and resuming my powerbi embedded capacities.

I have been unable to find it. Does what I'm looking for exist?


Solution

  • Does what I'm looking for exist?

    In short, No. As the link you provided, it need azure_auth to access to Power BI Embedded.

    You could use the below code to get the access_token and call the rest api you provide.

        private static string redirectUri = "https://login.live.com/oauth20_desktop.srf";
        private static string resourceUri = "https://analysis.windows.net/powerbi/api";
        private static string authorityUri = "https://login.windows.net/common/oauth2/authorize";
        // Obtain at https://dev.powerbi.com/apps
        private static string clientId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
    
        private static AuthenticationContext authContext = new AuthenticationContext(authorityUri, new TokenCache());
    
        private async void btnAuthenticate_ClickAsync(object sender, EventArgs e)
        {
            var authenticationResult = await authContext.AcquireTokenAsync(resourceUri, clientId, new Uri(redirectUri), new PlatformParameters(PromptBehavior.Auto));
            if (authenticationResult == null)
                MessageBox.Show("Call failed.");
            else
                MessageBox.Show(authenticationResult.AccessToken);
        }
    

    You can refer to the article about Power BI for .NET. Also you could use powershell to Resume-AzPowerBIEmbeddedCapacity.