Forum Discussion
andrebaldo
Oct 29, 2024Copper Contributor
Download Price List - https://learn.microsoft.com/en-us/partner-center/developer/get-a-price-sheet
Hi guys, check if you can help me out.
I'm trying to download the price list of my customer, I'm following this documentation here https://learn.microsoft.com/en-us/partner-center/developer/get-a-price-sheet looks like the problem is that my app doesn't have the correct permissions, but I don't know what more permissions I need to add to it.
I'm using an access token retrieved through the OAuth2 user consent, I have an WebApplication created on my Microsoft Entra ID, this application has the permissions below:
I'm able to receive the authorization code and exchange it to an access code normaly, however this access code is not working when I try to use it to retrieve the price list, where is how I'm doing it:
var market = "EU"; // Two-letter country/region code
var view = "updatedlicensebased"; // Type of price sheet view
var requestUri = $"https://api.partner.microsoft.com/v1.0/sales/pricesheets(Market='{market}',PricesheetView='{view}')/$value";
System.Net.Http.HttpRequestMessage linesMarketplaceReq6 = new System.Net.Http.HttpRequestMessage(HttpMethod.Get, requestUri);
linesMarketplaceReq6.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
linesMarketplaceReq6.Headers.Host = "api.partner.microsoft.com";
var linesMarketplaceResult6 = client.Send(linesMarketplaceReq6);
var result6 = await linesMarketplaceResult6.Content.ReadAsStringAsync();
var t = await linesMarketplaceResult6.Content.ReadAsStringAsync();
t.Dump();
The response is: { "statusCode": 401, "message": "Unauthorized: Invalid Authorization header" }
Then I found this thread here
https://github.com/microsoft/Partner-Center-PowerShell/issues/405#issuecomment-1709773538
which tells me to get a new access_code using the current refresh_code, but changing the resource to https://api.partner.microsoft.com , but when I try to do it I receive other error:
{"error":"invalid_grant","error_description":"AADSTS65001: The user or administrator has not consented to use the application with ID '92b24bbe-bbe0-44e9-b9ca-35ba915bab5e' named 'SITC-CSP'. Send an interactive authorization request for this user and resource., ...,"suberror":"consent_required"}
Code to get the new access_code using the refresh token:
using var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, new Uri($"https://login.microsoftonline.com/{tenantId}/oauth2/token"))
{
Content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("resource", "https://api.partner.microsoft-int.com"),
new KeyValuePair<string, string>("client_id", "<client_id>"),
new KeyValuePair<string, string>("client_secret", "<client_secret>"),
new KeyValuePair<string, string>("grant_type", "refresh_token"),
new KeyValuePair<string, string>("refresh_token", refreshToken),
new KeyValuePair<string, string>("scope", "openid"),
})
};
request.Headers.Add("ContentType","application/x-www-form-urlencoded");
var response = await client.SendAsync(request);
var data = await response.Content.ReadAsStringAsync();
data.Dump();
Any help would be greatly appreciated. Thanks in advance!
- ClaudioStalloneSteel Contributor
hi andrebaldo,
It looks like a Global Admin has to confirm the consent of your application first:
https://learn.microsoft.com/en-us/partner-center/developer/secure-app-model-framework#application-captures-partner-consentAlso very helpful here:
https://techcommunity.microsoft.com/t5/partner-led-questions-tech/configuring-the-secure-app-model-for-powershell-api-graph/m-p/3821164#M2- JillArmourMicrosoft
Community Manager
ClaudioStallone THANK YOU! 🙂
- JillArmourMicrosoft
Community Manager
andrebaldo I have moved your post to our Partner-led questions and tech topics board in hopes someone has experience with this. Tagging some of our superusers in case they have anything to add.
Thanks all!