microsoft / kiota

OpenAPI based HTTP Client code generator

Home Page:https://aka.ms/kiota/docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

KeyError - unexpected argument deltatoken

shemogumbe opened this issue · comments

Not sure this is the best place to raise this, doing so coz it affects all Languages.

The docs show than SDKs have deltatoken key that can be used to get the delta token the SDKs and the HTTP call both point to the same error:

HTTP Call
doing a call to The api does not recognise - https://graph.microsoft.com/v1.0/applications/delta?deltatoken=latest Gives:

{
    "error": {
        "code": "Request_BadRequest",
        "message": "Unrecognized query argument specified: 'deltatoken'.",
        "innerError": {
            "date": "2024-04-28T16:30:39",
            "request-id": "f2ea5621-e131-47c3-9ee2-d1bd91f96236",
            "client-request-id": "f7d27604-49ba-7cfd-b151-19d46c093e3f"
        }
    }
}

If the API does not support the argument, why do we have it in our SDKs and snippets.

A call to the C# snippet here gives:

Unhandled exception. Microsoft.Graph.Models.ODataErrors.ODataError: Unrecognized query argument specified: 'deltatoken'.

A similar call to Python snippet returns:

Result: Failure Exception: TypeError: DeltaRequestBuilder.DeltaRequestBuilderGetQueryParameters.__init__() got an unexpected keyword argument 'deltatoken' Stack: File "/azure-functions-...

Possible workarounds
Loop through the get requests, following @odata.NextLink to the last page, the use odata_delta_link, and extract deltatoken from it

async def get_user_delta(max_calls=10):
    try:

        # user dela
        url = "https://graph.microsoft.com/v1.0/applications/delta"
        calls = 0
        while calls < max_calls:
            response = await user_client.applications.delta.with_url(url).get()
            print(calls)
            if response.odata_next_link:
                url = response.odata_next_link
            elif response.odata_delta_link:
                print(response.odata_delta_link)
                return response.odata_delta_link
            calls += 1

    except APIError as e:
        print(f"Error: {e.response_status_code}: {e.message}")

This might not be efficient if the loops are too many, in my case it worked as we got the deltatoken on the third iteration of
Optionally, use the page iterator

@andrueastman @baywet your thoughts on this:

  1. The documentation seems to suggest what the API does not support.
  2. Our SDKs and snippets suggest it but it is not supported, the parameter delta token is not recognized - in fact the only recognized parameters are:
  • count
  • expand
  • filter
  • search
  • orderby
  • select
  • skip
  • top

https://graph.microsoft.com/v1.0/applications/delta?deltatoken=latest

I believe, the deltaToken needs the $ character to be $deltatoken according to the docs.

The snippet generation for python (and other languages) need to be updated here for snippets using the $deltaToken to use the withUrl method. This is because the example is using a result from a nextLink and consumers should ideally not be parsing the deltaToken from a nextLink(they should use the pageiterator or use the full url in making a subsequent request). See an explanation at on why the openApi metadata does not include the parameters at https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/dev/docs/upgrade-to-v5.md#skiptoken-and-deltatoken-query-parameters-in-delta-requests

It should therefore be possible to do this.

url = "https://graph.microsoft.com/v1.0/applications/delta?$deltatoken=latest"
response = await user_client.applications.delta.with_url(url).get()

Good, then it implies a problem with our snippets across SDKs

Taking a look at the snippets, the snippets for C# and Java look to be okay. (This scenario should also be failing on the raptor checks).

@shemogumbe should we close this here and file issues in the snippet generator?