I am trying to retrieve information from this API endpoint:
https://learn.microsoft.com/en-us/graph/api/subscribedsku-get?view=graph-rest-1.0&tabs=csharp
But I have a problem during execution, it gives me this error:
ODataError: Invalid object identifier. It must be a string in the form of [Guid]_[Guid].
And yet I send him a GUID in String
Here is my code :
public async Task<SubscribedSku> GetAvailableLicenceDetails(string idSku)
{
try
{
string accessToken = await tokenAcquisition.GetAccessTokenForUserAsync(new string[] { "Organization.Read.All" });
var authenticationProvider = new BaseBearerTokenAuthenticationProvider(new TokenProvider(accessToken));
var graphServiceClient = new GraphServiceClient(authenticationProvider);
var SubscribedSku = await graphServiceClient.SubscribedSkus[idSku].GetAsync();
return SubscribedSku;
}
catch (ODataError odataError)
{
Console.WriteLine(odataError.Error.Code);
Console.WriteLine(odataError.Error.Message);
throw;
}
}
var sku = await GetAvailableLicenceDetails("6fd2c87f-b296-42f0-b197-1e91e994b900");
I tried to find the problem but I can't, I need help !
Thank you
You are trying to retrieve subscribed sku by skuId
(id of the service SKU)
Check the properties in the doc
Property | Description |
---|---|
id | The unique identifier for the subscribed sku object |
skuId | The unique identifier (GUID) for the service SKU |
The call await graphServiceClient.SubscribedSkus["id"].GetAsync();
requires id
not skuId
.
The limitation of the subscribedSkus is that they don't support filtering by skuId
, so you can't use
var result = await graphClient.SubscribedSkus.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Filter = $"skuId eq {idSku}";
});
Only way is to retrieve all subscribedskus and perform filter on the client
var response = await graphServiceClient.SubscribedSkus.GetAsync();
var subscribedSku = response.Value.FirstOrDefault(x=>x.SkuId eq idSku);
Or you have id not skuId, you can retrieve the specific subscribed sku
var SubscribedSku = await graphServiceClient.SubscribedSkus[id].GetAsync();