-1

I have implemented the following method in c#

    public static async Task<WorkbookWorksheetChartsCollectionResponse> GetChart(string idItem, string nameSheet)
    {
        var graphClient = GetAuthenticatedClient();

        var chart = await graphClient.Me.Drive.Items[idItem]
            .Workbook
            .Worksheets[nameSheet]
            .Charts["Chart 1"]
            .Image(640, 480, "fit")
            .Request()
            .GetAsync();

        return chart;
    }

but I get the following error when returning the chart the error is, this is the class by microsoft graph api class

  • According to the docs, it seems as though it returns the image as a base64 string: https://learn.microsoft.com/en-us/graph/api/chart-image?view=graph-rest-1.0 – Evan Trimboli Dec 17 '19 at 21:54
  • yes, that's right, but the implementation I'm doing with the api library, is the idea to use it for it, the documentation shows the example with url's, and I need to do it with microsoft graph – Yilmar Vega Dec 17 '19 at 22:13

1 Answers1

0

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"); 
     //...
 }
Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193