question

PaoloLazzari-3674 avatar image
0 Votes"
PaoloLazzari-3674 asked SandeepBandaru-1608 commented

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

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://docs.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?


partner-center-api
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

PaoloLazzari-3674 avatar image
1 Vote"
PaoloLazzari-3674 answered SandeepBandaru-1608 commented

Thank you @SandeepBandaru-9414 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







image.png (14.1 KiB)
image.png (8.0 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks Paolo for adding these instructions!

One point to be added is that the credentials for the app created can be obtained from Azure Portal -> Active Directory -> App registrations section.

0 Votes 0 ·
Jerryzy avatar image
0 Votes"
Jerryzy answered

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


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

PaoloLazzari-3674 avatar image
0 Votes"
PaoloLazzari-3674 answered Jerryzy commented

@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://apidocs.microsoft.com/services/partneringestion/


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

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Should be similiar with get customer's subsciption:

https://docs.microsoft.com/en-us/partner-center/develop/get-all-of-a-customer-s-subscriptions

You can try to request like this:

https://api.partnercenter.microsoft.com/v1/customers/<customer-tenant-id>/offers

customer-tenant-id can be got in Partner Center Url:

14245-image-7.png


0 Votes 0 ·
image-7.png (23.7 KiB)
PaoloLazzari-3674 avatar image
0 Votes"
PaoloLazzari-3674 answered Jerryzy commented

@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://docs.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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You will need to contact the Administrator and ask for the Partner Center Permission so that you can check the correct customer Id.

Tenant Id is not the customer id at all.

0 Votes 0 ·

Thanks, under accounts settings I can see:

  • Seller ID

  • User ID

  • MPN ID

Is it neither of those?



0 Votes 0 ·

@Jerryzy-MSFT

I have checked with an Administrator who has full access to the portal and they are not able to see that.
This is what they see:

14691-partnercenterscreenshot.png



How can we find out the customer ID?

0 Votes 0 ·
Show more comments
SandeepBandaru-9414 avatar image
0 Votes"
SandeepBandaru-9414 answered PaoloLazzari-3674 commented

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.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @SandeepBandaru-9414

Yes, I have added the Azure service principal in the prod account, and I have granted it "Manager" and "Developer" permissions

0 Votes 0 ·
elegantcoder avatar image
0 Votes"
elegantcoder answered

@SandeepBandaru-9414

Do you have an update for this partner on this item?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.