microsoftgraph / msgraph-sdk-serviceissues

Tracks service issues for follow up.
5 stars 0 forks source link

excel doesn't accept fully qualified function names #108

Open loicviardcretat opened 3 years ago

loicviardcretat commented 3 years ago

Hello,

I'm making a request to the microsoft graph api to get an image of a graph in base64 :

return graphClient.drives(driveId)
    .items(fileId)
    .workbook().worksheets().byId(sheetId).charts().byId(chartId).image()
    .buildRequest().get().getBytes();

The url obtained "https://graph.microsoft.com/v1.0/me/drive/items/"sheetId"/workbook/worksheets/"worksheetId"/charts/"chartId"/image" works well with postman but the request returned null on the Java side.

The result obtained with postman :

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Edm.String",
    "value": "iVBORw0KGgo[...]"
}

It is not a problem of bearer Token or something like that because this request returns several results :

return graphClient
          .me()
          .drive()
          .buildRequest()
          .get();

I use version 3.9.0 of the Maven repo. I don't know why I get this result, could someone help me? Thanks a lot !

AB#10144

baywet commented 3 years ago

Salut @loicviardcretat , Thanks for reaching out.

Just to make sure we're taking about the same things, I believe the URL you are referring to https://graph.microsoft.com/v1.0/me/drive/items/{driveItemId}/workbook/worksheets/{sheetId}/charts/{chartId}/image translate to

graphClient.me()
.drive()
.items("driveItemId")
.workbook()
.worksheets()
.byId("sheetId")
.charts()
.byId("chartId")
.image(WorkbookChartImageParameterSet.newBuilder().build())
.buildRequest()
.get()

Which can be shortened to

graphClient.me()
.drive()
.items("driveItemId")
.workbook()
.worksheets("sheetId")
.charts("chartId")
.image()
.buildRequest()
.get()

Anytime you have a REST request, you can try it out in the graph explorer and get a code snippet after executing the request which should guide you towards writing the required code.

image

Let us know if you have further questions.

loicviardcretat commented 3 years ago

Thanks @baywet for your answer but you didn't answer my question very well, let me explain

I executed my request with a url in the graph explorer but it returns an "itemNotFound". The problem is that I don't understand why in graphExplorer I get an "itemNotfound", in my Java code a "null" and in postman the image in base64...

I forgot to mention that I changed in the source code the .image() function. It added to the query url '/microsoft.graph.image' which made the query false (instead of '/image').

Capture d’écran 2021-07-08 à 16 44 42

baywet commented 3 years ago

Oh I see! I didn't understand you were implying the URL generated by the SDK was incorrect.

This path segment is an OData function, without getting too much in OData details, and according to its conventions, the SDK is supposed to use the full name (namespace name + function name) when calling the service. It is "right" for the SDK to call the service using microsoft.graph.image instead of image. And you can see another example of that with the sendMail function. (which works properly) https://github.com/microsoftgraph/msgraph-sdk-java/blob/a6d7abf1a9e6d8008426cc7cadb8da6d4bcba0c7/src/main/java/com/microsoft/graph/requests/UserRequestBuilder.java#L1481

The service should recognize that URL and return the same response as when it's called using /function.

Generating different segments based on service "quickyness" would be a maintenance nightmare. The service should fix their implementation. (I'll transfer this issue after this reply).

In the meantime, here is a workaround for you:

var request = graphClient.me()
.drive()
.items("driveItemId")
.workbook()
.worksheets("sheetId")
.charts("chartId")
.image()
.buildRequest();

request = new  WorkbookChartImageRequest(new URL(request.getRequestUrl().toString().replace("microsoft.graph.image", "image")), request.getClient(), request.getOptions()):

request.get();
loicviardcretat commented 3 years ago

Hi @baywet I am coming back to you following your last answer. I have edited my code according to your advice (java language) :

IWorkbookChartImageRequest request = graphClient.me()
    .drive()
    .items(fileId)
    .workbook()
    .worksheets(sheetId)
    .charts(chartId)
    .image()
    .buildRequest();

WorkbookChartImageRequest imageRequest = new WorkbookChartImageRequest(
    request.getRequestUrl().toString().replace("microsoft.graph.image", "image"),
    graphClient,
    request.getOptions()
);

return imageRequest.get().getBytes();

The url of "request" contains well 'microsoft.graph.image' and it is well replaced by 'image' in "imageRequest". Except that imageRequest.get() returns null...

Concerning graphExplorer, the query I get in the Java code does return data. Always the same request: https://graph.microsoft.com/v1.0/me/drive/items/itemId/workbook/worksheets/worksheetId/charts/chartId/image Still the same structure of the answer:

{
    "@odata.context":         
         "https://graph.microsoft.com/v1.0/$metadata#Edm.String",
    "value": "XXXXXXXXX"
}

I specify that this request returns data (in java) :

graphClient.me()
    .drive()
    .items(fileId)
    .workbook()
    .worksheets(sheetId)
    .charts(chartId)
        .buildRequest().get()

I can't figure out what's wrong, but I thank you for your help !

loicviardcretat commented 3 years ago

If I remove the part of the code that changes the "microsoft.graph.image" to "image", the request returns "Bad Request"

baywet commented 3 years ago

The fact that you have IWorkbookChartImageRequest in your sample leads me to think you're not on latest. Can you double check your app is on the 4.0.0 version of the library and 2.0.7 of the core library please? Thanks

petrhollayms commented 7 months ago

Thank you for reporting this issue. This appears to be an issue or limitation with the service APIs. Unfortunately, as the Microsoft Graph SDK team, we do not have ownership of the APIs that are causing you issues. We invite you to create a question about the service API to Microsoft Q&A and tagged with one of the [microsoft-graph-*] tags, that way it will get routed to the appropriate team for them to triage:

https://aka.ms/msgraphsupport or directly https://aka.ms/askgraph

For now, we will close the issue on our side but feel free to open it in the relevant repository if you think the issue is specific to SDK. Please let us know if this helps!

Note: We will close this repository on April 19, 2024.