msgraph-sdk-dotnet icon indicating copy to clipboard operation
msgraph-sdk-dotnet copied to clipboard

[Client bug]: Pagelevel not available as a QueryParameter for Page/Pages requests

Open dgounaris opened this issue 1 year ago • 3 comments

Describe the bug In the Onenote Graph API spec page, there exists a way to show detailed metadata of a page, by using the pagelevel query parameter. This is clearly described in https://learn.microsoft.com/en-us/graph/onenote-get-content#page-entity. However, the current SDK implementation doesn't allow this query parameter to be set, and due to the template replacement that occurs, workarounds like

var requestInformation = _graphServiceClient.Users[user.Id]
    .Onenote.Sections[section.Id].Pages.ToGetRequestInformation();
requestInformation.QueryParameters.Add("pagelevel", "true");
var result = await _graphServiceClient.RequestAdapter
    .SendAsync<OnenotePageCollectionResponse>(requestInformation,
        OnenotePageCollectionResponse.CreateFromDiscriminatorValue)

don't work either as the query parameters can't be forced in the request.

The issue gets fixed by adding the query parameter in the template and the Request model. I have tested and verified it locally using this branch, which applies it only to the Microsoft.Graph.Users.Item.Onenote.Sections.Item.Pages namespace objects for simplicity: https://github.com/dgounaris/msgraph-sdk-dotnet/tree/patch/pagelevel-onenote.

However if my understanding is correct, Kiota is used to update the API definitions, thus I'm afraid that opening a PR with this fix will get overwritten at a later point until Graph API correctly captures this query parameter. Let me know if this is not the case and a patch can be applied manually, I'd be happy to fix the rest of the occurences and publish the PR.

To Reproduce Steps to reproduce the behavior:

  1. Try using the declarative SDK command for any of the page collection or page requests, for example:
var result = await _graphServiceClient.Users[user.Id]
            .Onenote.Sections[section.Id].Pages.GetAsync(requestConfiguration =>
            {
                // requestConfiguration.QueryParameters.PageLevel = true;
            });
  1. Uncomment the line enabling PageLevel query parameter. Observe that it results in compilation error.
  2. Attempt to apply workaround described in the issue description, with the use of RequestInformation.
  3. See that the pagelevel query param gets skipped.

Expected behavior Pagelevel should be an allowed query parameter

Screenshots If applicable, add screenshots to help explain your problem.

Client version Provide the client version number from the NuGet package.

Desktop (please complete the following information):

  • OS: Not relevant, this is backend usage
  • Browser: Not relevant, this is backend usage
  • Version Not relevant

Additional context Add any other context about the problem here.

dgounaris avatar May 11 '23 14:05 dgounaris

Bumping this due to inactivity, am I misunderstanding something on how this API should work? Is this not a valid issue?

dgounaris avatar May 25 '23 09:05 dgounaris

Thanks for raising this @dgounaris

As you correctly put it, this needs to be fixed in the metadata to have the query parameter showing up but can be worked around as below.

            var requestInformation = graphClient.Users["user.Id"]
                .Onenote.Sections["section.Id"].Pages.ToGetRequestInformation();
            requestInformation.UrlTemplate = requestInformation.UrlTemplate.Insert(requestInformation.UrlTemplate.Length-1,",pagelevel");
            requestInformation.QueryParameters.Add("pagelevel", "true");
            var result = await graphClient.RequestAdapter
                .SendAsync<OnenotePageCollectionResponse>(requestInformation,
                    OnenotePageCollectionResponse.CreateFromDiscriminatorValue);

andrueastman avatar Jun 02 '23 09:06 andrueastman

I missed the possibility of changing the UrlTemplate when I was trying to come up with workarounds, thanks for bringing this in my attention. I will try it out soon.

dgounaris avatar Jun 02 '23 14:06 dgounaris