Partner Centre SDK API, get Analytics Lisence Usage

Cairn 41 Reputation points
2020-10-26T13:06:31.587+00:00

I have an Application that is monitoring out CSP. I am using the following code authenticate and open up the SDK

IPartnerCredentials appCredentials = PartnerCredentials.Instance.GenerateByApplicationCredentials(
applicationId,
applicationSecret,
applicationDomain);

IAggregatePartner partner = PartnerService.Instance.CreatePartnerOperations(appCredentials);

I use this to the the customer usage and works fine for getting the subscriptions and the usage, but when attempting to get the License usage

var customers = partner.Customers.Get();

foreach (var customer in customers.Items)
{
try
{
var usageRecords = partner.Customers.ById(customer.Id).Analytics.Licenses.Usage.Get();

              ParseLicenceUsage(usageDetails, usageRecords, customer, startDate);
     }
     catch (Exception ex)
     {

     }

}
within the line to get the usage an exception is thrown with a message of Forbidden.
What is going wrong here, the authentication works for subscriptions so I think thats all ok, the code to get the licenses usage is from the samples, so why the error?
Or is the login authentication needed for the license data different?

Microsoft Partner Center API
Microsoft Partner Center API
Microsoft Partner Center: A Microsoft website for partners that provides access to product support, a partner community, and other partner services.API: A software intermediary that allows two applications to interact with each other.
345 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Jerryzy 10,571 Reputation points
    2020-10-27T01:41:32.543+00:00

    Hi @Carim-3868,

    Analytics Lisence Usage should use "User" authentication instead of "App Only" authentication:

     protected override void RunScenario()  
        {  
            string customerIdToRetrieve = this.ObtainCustomerId("Enter the ID of the customer to retrieve");  
      
            var partnerOperations = this.Context.UserPartnerOperations;  
            this.Context.ConsoleHelper.StartProgress("Retrieving customer licenses usage analytics");  
      
            var customerLicensesDeploymentAnalytics = partnerOperations.Customers.ById(customerIdToRetrieve).Analytics.Licenses.Usage.Get();  
      
            this.Context.ConsoleHelper.StopProgress();  
            this.Context.ConsoleHelper.WriteObject(customerLicensesDeploymentAnalytics, "Customer licenses usage analytics");  
        }  
    

    35291-snipaste-2020-10-27-09-37-15.png

    Check the demo in GitHub:

    Partner Center SDK for .NET Samples


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Cairn 41 Reputation points
    2020-10-28T12:51:45.803+00:00

    Not yet (I am using .net core 5 latest preview). I have attempted used the samples to test the access, the call to AuthenticationResult LoginUserToAad() within ScenarioContext.cs will not complie due to the PlatformParameters not accepting the number of parameters, and reading about this this method of access is not longer supported and moving to MSAL.
    I have also attempted to us the Secure model samples but within the RefreshAccessTokenAsync method the response tot he httpClient.SendAsync fails as a Status Code : 400 BadRequest
    RequestMessage = {Method: POST, RequestUri: 'https://login.microsoftonline.com//********-****-****-****-************/oauth2/token', Version: 1.1, Content: System.Net.Http.FormUrlEncodedContent, Headers:
    {
    User-Agent: FxVersion/5.0.20.47505
    User-Agent: OSName/Windows
    ...

    Any Ideas as to what is causing the issue with the bad return?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.