It appears msgraph-sdk-dotnet
(v.1.21.0
) doesn't generate the correct URL for Chart: Image
endpoint and the following error occurs:
The type 'microsoft.graph.image' specified in the URI is neither a
base type nor a sub-type of the previously-specified type
'microsoft.graph.workbookChart'
The following comment could be found in ExcelTests.cs
regarding same issue:
Workaround since the metadata description isn't correct as it states
it returns a string and not the actual JSON object, and since the
service doesn't accept the fully qualified name that the client emits
even though it should accept the FQN.
and the following workaround to get chart image
var chartResourceUrl = graphClient.Me.Drive.Items[itemId]
.Workbook
.Worksheets[nameSheet]
.Charts[chartName]
.Request().RequestUrl;
var urlToGetImageFromChart = $"{chartResourceUrl}/image(width=400, height=480)";
var message = new HttpRequestMessage(HttpMethod.Get, urlToGetImageFromChart);
await graphClient.AuthenticationProvider.AuthenticateRequestAsync(message);
var response = await graphClient.HttpProvider.SendAsync(message);
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
JObject imageObject = JObject.Parse(content);
JToken chartData = imageObject.GetValue("value");
//...
}