I have used Graph PI for getting the SKU's with below code:-
private static void getLicenses()
{
string serviceUrl = "graph.microsoft.com";
AuthenticationContext authContext = new AuthenticationContext("login.microsoftonline.com/3b57d5b1-2f5b-4dbd-825b-1c716bcd5494");
ClientCredential credential = new ClientCredential(clientId, secret);
AuthenticationResult result = authContext.AcquireTokenAsync(serviceUrl, credential).Result;
string accessToken = result.AccessToken;
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken}");
client.BaseAddress = new Uri("graph.microsoft.com");
client.Timeout = new TimeSpan(0, 2, 0); //2 minutes
client.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
client.DefaultRequestHeaders.Add("OData-Version", "4.0");
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
//createAccount(client);
var response = client.GetAsync("/v1.0/subscribedSkus",
HttpCompletionOption.ResponseHeadersRead).Result;
if (response.IsSuccessStatusCode)
{
//Get the response content and parse it.
JObject body = JObject.Parse(response.Content.ReadAsStringAsync().Result);
}
}
}
// Client Id and Secret Id : These can be fetched when regisering an application in Azure acricve directory: docs.microsoft.com/.../quickstart-register-app