Forum Discussion

matiman's avatar
matiman
Regular Visitor
9 years ago
Solved

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

 

 

 

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

 

  • matiman's avatar
    matiman
    9 years ago

    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.

4 Replies

  • Eric_Zhang's avatar
    Eric_Zhang
    Microsoft 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.

    • matiman's avatar
      matiman
      Regular Visitor

      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.

       

      • Eric_Zhang's avatar
        Eric_Zhang
        Microsoft Employee

        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?