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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
matiman
Regular Visitor

microsoft partner center API

Hi,

 

So I'm trying to get usage data from Microsoft Partner Center (via web API). I know that I need an Azure token and a Partner Center token to access the data. Connecting to the sandbox partner center environment is no problem (because i'm global admin here). But for the primary environment I can't even get an Azure token. I have registered the Partner Center web API in the Azure active directory. which settings, permissions do I need to change to get the AAD token?

The code below is for the azure token. On the print screen you can see the permissions that I have for the web API. In properties: multi-tenanted = 'no' and I'm not an owner of the api.

 

edit: I can't refresh the tokens for the sandbox environment and still can't get an Azure active directory token for the primary account.

 

Thanks in advance

 

afbeelding.png

 

 

let
    Source = (AccountId as text, ApplicationId as text, ApplicationSecret as text, Password as text, Username as text) => let   
    aadRequest = [
        client_id = ApplicationId, 
        client_secret = ApplicationSecret,
        grant_type = "password",
        password = Password,
        resource = "https://api.partnercenter.microsoft.com",        
        scope = "openid",
        username = Username
    ],
    aadContent = Text.ToBinary(Uri.BuildQueryString(aadRequest)),
    aadTokenRequest = Web.Contents("https://login.microsoftonline.com/" & AccountId & "/oauth2/token", 
        [
            Headers = [#"content-type"="application/x-www-form-urlencoded"], 
            Content = aadContent
        ]
    ),
    aadTokenJSON = Json.Document(aadTokenRequest), 
    aadToken = aadTokenJSON[access_token]
in    
    aadToken
in
    Source

 

1 ACCEPTED SOLUTION

Thanks for the replies, but I had to take another route because Partner Center doens't offer a way to automate billing. I can't get prices or reconciliation files via API. So I just have to manually download them. Adding the downloaded files to Power BI is no problem.

View solution in original post

4 REPLIES 4
Eric_Zhang
Employee
Employee


@matiman wrote:

Hi,

 

So I'm trying to get usage data from Microsoft Partner Center (via web API). I know that I need an Azure token and a Partner Center token to access the data. Connecting to the sandbox partner center environment is no problem (because i'm global admin here). But for the primary environment I can't even get an Azure token. I have registered the Partner Center web API in the Azure active directory. which settings, permissions do I need to change to get the AAD token?

The code below is for the azure token. On the print screen you can see the permissions that I have for the web API. In properties: multi-tenanted = 'no' and I'm not an owner of the api.

 

edit: I can't refresh the tokens for the sandbox environment and still can't get an Azure active directory token for the primary account.

 

Thanks in advance 

 

let
    Source = (AccountId as text, ApplicationId as text, ApplicationSecret as text, Password as text, Username as text) => let   
    aadRequest = [
        client_id = ApplicationId, 
        client_secret = ApplicationSecret,
        grant_type = "password",
        password = Password,
        resource = "https://api.partnercenter.microsoft.com",        
        scope = "openid",
        username = Username
    ],
    aadContent = Text.ToBinary(Uri.BuildQueryString(aadRequest)),
    aadTokenRequest = Web.Contents("https://login.microsoftonline.com/" & AccountId & "/oauth2/token", 
        [
            Headers = [#"content-type"="application/x-www-form-urlencoded"], 
            Content = aadContent
        ]
    ),
    aadTokenJSON = Json.Document(aadTokenRequest), 
    aadToken = aadTokenJSON[access_token]
in    
    aadToken
in
    Source

 


The Power Query code looks good. Does it work in you sandbox while it doesn't work in the primary environment? If yes, let's put the Power Query aside, could you get the token in your primary enviroment by calling that API with C# code or any tool like POSTMAN?

 

I suspect that the problem may be with the Microsoft Partner Center API call. Since this forum is for PowerBI expertise, it doesn't make much sense posting details about the Microsoft Partner Center API, I'd suggest your post your question at the dedicated Microsoft Partner Center community.

I tried connecting on both environments with visual studio (C#) and it works fine.

So I thought I missed some authentication code in power query...

 

Summary:

For sandbox -> Can't refresh

For primary -> Can't get an Azure AD token

 

Thank you for the response. I will post it in the Partner Center community.

 


@matiman wrote:

I tried connecting on both environments with visual studio (C#) and it works fine.

So I thought I missed some authentication code in power query...

 

Summary:

For sandbox -> Can't refresh

For primary -> Can't get an Azure AD token

 

Thank you for the response. I will post it in the Partner Center community.

 


When saying "it works fine", in visual studio do you call the same API as the power query code does, that is to say, you can get an token in C# but not in Power Query? In both enviroment, do you test with the same client_id and client_secrect?

Thanks for the replies, but I had to take another route because Partner Center doens't offer a way to automate billing. I can't get prices or reconciliation files via API. So I just have to manually download them. Adding the downloaded files to Power BI is no problem.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.