Unable to retrieve offers from Partner Center for account using app registration

Paolo Lazzari 101 Reputation points
2020-07-28T14:28:35.107+00:00

In Partner Center, we have one Azure AD and two accounts, prod and stage.

I'm looking to use an app registration to read/write offers in the Partner Center.. I have configured one following the instructions here:

https://learn.microsoft.com/en-us/partner/develop/api-authentication

In my application, I get the Bearer Token from this endpoint:

https://login.microsoftonline.com/tenant_id/oauth2/token

using the app registration details.
The request is successful and I get the token.

When I execute a GET request against this api:

https://api.partner.microsoft.com/v1.0/ingestion/products/

I only see the offers from one of the two accounts (stage) but not the other (prod)
How can I see the offers for both accounts?

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.
313 questions
0 comments No comments
{count} votes

Accepted answer
  1. Paolo Lazzari 101 Reputation points
    2020-09-23T08:51:59.08+00:00

    Thank you @Sandeep Bandaru for your help yesterday.

    It seems like the root cause of the issue was that the app registration was not configured correctly to work with the intended account.
    We took the following steps to resolve the issue:

    • Created a new App Registration from the Partner Center from the production account (Developer settings, Users, Add Azure AD Application, New Azure AD Application)
    • We used the new credentials (client id and secret) when requesting the token from the API:

    26670-image.png

    • We used the token in the request against the Partner Center API

    26860-image.png

    1 person found this answer helpful.

5 additional answers

Sort by: Most helpful
  1. Jerryzy 10,566 Reputation points
    2020-07-29T06:47:06.73+00:00

    If you have 2 customers (account), to get the offers for specific customer account, pass customer Id:

    string customerIdToRetrieve = this.ObtainCustomerId("Enter the ID of the customer to retrieve offers for");
    var pageSize = this.Context.Configuration.Scenario.DefaultOfferPageSize;
    var partnerOperations = this.Context.AppPartnerOperations;

            this.Context.ConsoleHelper.StartProgress($"Getting first { pageSize } offers for customer { customerIdToRetrieve }");
            var offers = partnerOperations.Customers.ById(customerIdToRetrieve).Offers.Get(0, pageSize);
            this.Context.ConsoleHelper.StopProgress();
    
            this.Context.ConsoleHelper.WriteObject(offers, $"First { pageSize } offers for customer { customerIdToRetrieve }");
    

    Suggest to get with Partner Center .NET SDK, it will have sample below, also supported App authentication:

    Partner Center SDK for .NET Samples

    0 comments No comments

  2. Paolo Lazzari 101 Reputation points
    2020-07-29T08:21:15.047+00:00

    @Jerryzy-MSFT

    Thank you for your answer.
    Unfortunately, I am not using any SDK. My application is in Python, and I am using simple HTTP requests.

    I get the token as follows:

        url = f"https://login.microsoftonline.com/{self.tenant_id}/oauth2/token"    
    
        data = {    
            "grant_type": "client_credentials",    
            "client_id": self.client_id,    
            "client_secret": self.client_secret,    
            "resource": "https://api.partner.microsoft.com"    
        }    
      res = requests.post(url, data=data)    
    

    then I use the retrieved Bearer token when executing the GET request (in the headers):

       res = requests.get(    
          (    
              f"https://api.partner.microsoft.com/v1.0/ingestion/"    
              f'products/'    
           ),    
           headers=self.prepare_headers()    
       )    
    

    how/where can I specify the customer ID?
    I don't see any option to specify the customer ID here https://apilearn.microsoft.com/services/partneringestion/

    Thanks again for your help, I've been stuck on this for a bit


  3. Paolo Lazzari 101 Reputation points
    2020-07-29T09:27:48.79+00:00

    @Jerryzy-MSFT

    Comments don't seem to be working for me so I'll post here.

    I don't see the CSP option on the left but I guess that's because I don't have enough priviledges.
    Anyway, I found the tenant ID under

    -> Account Settings -> Tenants

    and I've tried using it as you suggested. I first changed the endpoint for the token:

       data = {    
            "grant_type": "client_credentials",    
            "client_id": self.client_id,    
            "client_secret": self.client_secret,    
            "resource": "https://api.partnercenter.microsoft.com"    
        }    
    

    then changed the endpoint for the request:

       res = requests.get(    
            (    
                f"https://api.partnercenter.microsoft.com/v1/customers/{self.tenant_id}/offers"    
            ),    
            headers=self.prepare_headers()    
        )    
    

    but I get a 500. with message Internal server error
    I've tried a bunch of other endpoints (e.g. https://learn.microsoft.com/en-us/partner-center/develop/get-all-of-a-customer-s-subscriptions#request-example) and I keep seeing the same issue.
    I see the same when testing with Postman.

    Any other ideas?

    By the way, the tenant_id is the same for both directories in the account (prod and stage)

    Thanks again for your help.


  4. Sandeep Bandaru 1 Reputation point
    2020-07-30T20:14:01.507+00:00

    Hi @PaoloLazzari-3674 ,

    I am engineer from the Partner Center Accounts team. I have been assigned your case internally.
    I think there is a confusion here in previous comments. From the products endpoint, I see you are trying to access your azure marketplace products using Partner Center API.

    Can you confirm you have added/ are able to view the service-principal you are using to fetch products, under both the accounts?
    I checked that the objectId 3e52a2d6-xxxxxxxx-cdffe6c3ee11 has access to only one of your accounts.

    To switch accounts under the same tenant, you can use the Account Picker from the Left Navigation Pane and add the service principal(as linked above) in the other account as well to be able to access products from both accounts.