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

Try out the v5 preview 📢 📢

Open andrueastman opened this issue 2 years ago • 7 comments

The Microsoft Graph .NET SDK v5.0.0 is now available for preview!

This updated version features many changes as the SDK is generated with Kiota:

You can go to the upgrade guide for more detailed information on the changes.

For the beta package, please refer to the beta repo.

andrueastman avatar Mar 25 '22 12:03 andrueastman

Will this be able to run on net6.0-maccatalyst or generally speaking be usable with MAUI? This compatibility issue is around for quite some time now, but none of the open issues were given any kind of feedback. Any info would be greatly appreciated - please see issues #1329 and #413

edoust avatar Jun 27 '22 19:06 edoust

How would I serialize a chat message to json?

It seems to serialize additional data wrong:

"From": { "AdditionalData": {}, "Application": null, "BackingStore": { "InitializationCompleted": true, "ReturnOnlyChangedValues": false }, "Device": null, "User": { "AdditionalData": { "userIdentityType": "aadUser" }, "BackingStore": { "InitializationCompleted": true, "ReturnOnlyChangedValues": false }, "DisplayName": "theUser", "Id": "TheUSersGuid" }

Are any any buildin/preconfigured serializers that do this well?

the user is to be serialized like this: "user": { "displayName": "Some User", "id": "UserId", "userIdentityType": "aadUser" }

ymoona avatar Jun 29 '22 13:06 ymoona

Recommendation for upgrade docs:

  • Show a query with multiple query parameters.
  • Show a filter query.

gvanriper avatar Oct 10 '22 20:10 gvanriper

how can we do that with SDK v5.0.0 ?

var driveItem = new DriveItem
            {
                Name = path,
                Folder = new Folder(),
                AdditionalData = new Dictionary<string, object>() { { "@microsoft.graph.conflictBehavior", "fail" } }
            };
           
await graphClient.Sites[siteId].Drives[driveId].Root.Children.Request().AddAsync(driveItem);

amarmechai avatar Oct 13 '22 15:10 amarmechai

How would I serialize a chat message to json?

It seems to serialize additional data wrong:

"From": { "AdditionalData": {}, "Application": null, "BackingStore": { "InitializationCompleted": true, "ReturnOnlyChangedValues": false }, "Device": null, "User": { "AdditionalData": { "userIdentityType": "aadUser" }, "BackingStore": { "InitializationCompleted": true, "ReturnOnlyChangedValues": false }, "DisplayName": "theUser", "Id": "TheUSersGuid" }

Are any any buildin/preconfigured serializers that do this well?

the user is to be serialized like this: "user": { "displayName": "Some User", "id": "UserId", "userIdentityType": "aadUser" }

You can access the inbuilt serializer as below to perform the serialization for you @ymoona

var seralizer = graphServiceClient.RequestAdapter.SerializationWriterFactory.GetSerializationWriter("application/json");
seralizer.WriteObjectValue(string.Empty,application);
var serializedContent = seralizer.GetSerializedContent();

andrueastman avatar Oct 14 '22 07:10 andrueastman

how can we do that with SDK v5.0.0 ?

var driveItem = new DriveItem
            {
                Name = path,
                Folder = new Folder(),
                AdditionalData = new Dictionary<string, object>() { { "@microsoft.graph.conflictBehavior", "fail" } }
            };
           
await graphClient.Sites[siteId].Drives[driveId].Root.Children.Request().AddAsync(driveItem);

Tracked via https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/1524

andrueastman avatar Oct 14 '22 07:10 andrueastman

I am sure this is a stupid question, but I can't figure out how to get a DriveItem by path.

What is funny is the documentation has examples in c# for most things except for getting it by path, for that it only shows the HTTP option: https://learn.microsoft.com/en-us/graph/api/driveitem-list-children?view=graph-rest-beta&tabs=http#examples

I have tried graphClient.Drive.Items[Path].GetAsync() and graphClient.Drive.Root.Children[Path].GetAsync() all of which fail. i can see the official request should be root:/{item-path} but I don't know how to do that in c#. There is no Root object this handler so you can't do Root[Path]

I could maybe abuse the Root.GetAsync() and add a header to the path but that seems wrong.

I do realize it sounds similar to #1524 but that sounded like the issue was the lack of a Post handler and the example was for adding.

mitchcapper avatar Oct 16 '22 09:10 mitchcapper

I am sure this is a stupid question, but I can't figure out how to get a DriveItem by path.

What is funny is the documentation has examples in c# for most things except for getting it by path, for that it only shows the HTTP option: https://learn.microsoft.com/en-us/graph/api/driveitem-list-children?view=graph-rest-beta&tabs=http#examples

I have tried graphClient.Drive.Items[Path].GetAsync() and graphClient.Drive.Root.Children[Path].GetAsync() all of which fail. i can see the official request should be root:/{item-path} but I don't know how to do that in c#. There is no Root object this handler so you can't do Root[Path]

I could maybe abuse the Root.GetAsync() and add a header to the path but that seems wrong.

I do realize it sounds similar to #1524 but that sounded like the issue was the lack of a Post handler and the example was for adding.

I am also experiencing same issue. graphClient.Me.Drive and graph.Users["userId"].Drive does not contain field Items.

adamijak avatar Oct 18 '22 11:10 adamijak

@adamijak I found most of the old Me. endpoints should now be accessed without the Me. Me.Drive is more of a request to get the users root drive metadata. So you can do graphClient.Drive.Items["id"] where before you were doing Me.Items. The problem I have is the API is auto generated so paths like Drive.Items get directly translated into /drive/items for requests. I can't figure out how to do a root:/item-path query though.

mitchcapper avatar Oct 18 '22 14:10 mitchcapper

I am sure this is a stupid question, but I can't figure out how to get a DriveItem by path.

What is funny is the documentation has examples in c# for most things except for getting it by path, for that it only shows the HTTP option: https://learn.microsoft.com/en-us/graph/api/driveitem-list-children?view=graph-rest-beta&tabs=http#examples

I have tried graphClient.Drive.Items[Path].GetAsync() and graphClient.Drive.Root.Children[Path].GetAsync() all of which fail. i can see the official request should be root:/{item-path} but I don't know how to do that in c#. There is no Root object this handler so you can't do Root[Path]

I could maybe abuse the Root.GetAsync() and add a header to the path but that seems wrong.

I do realize it sounds similar to #1524 but that sounded like the issue was the lack of a Post handler and the example was for adding.

It should be possible to do the following with the latest previews.

            var item = await graphServiceClient.Drives["drive-id"].Items["item-id"]
                .ItemWithPath(Path.GetFileName("data/sample.pdf"))
                .Content
                .GetAsync();

            var item2 = await graphServiceClient.Drives["ils"].Root
                .ItemWithPath(Path.GetFileName("sample.pdf"))
                .Content
                .GetAsync();

More information on the drive paths is documented at the link below.

https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/feature/5.0/docs/upgrade-to-v5.md#drive-item-paths

andrueastman avatar Dec 05 '22 08:12 andrueastman

Let's assume that I have the following code for v4

client.Users[userId].CalendarView.Request(queryOptions).Filter(filterQuery).Expand(expandOptions).Select(SelectQuery).GetAsync()

The code for v5 looks like this but there is no Expand property in CalendarViewRequestBuilderGetQueryParameters class

client
    .Users[userId]
    .CalendarView
    .GetAsync(cfg =>
    {
        cfg.QueryParameters.StartDateTime = from;
        cfg.QueryParameters.EndDateTime = to;
        cfg.QueryParameters.Filter = filterQuery;
        cfg.QueryParameters.Select = SelectQuery;
    })

Is it a bug or is there any other reason why Expand property is missing in CalendarViewRequestBuilderGetQueryParameters?

MartinM85 avatar Dec 10 '22 15:12 MartinM85

Greetings,

I am receiving the error message "Microsoft.Graph.Models.ODataErrors.ODataError: 'Exception of type 'Microsoft.Graph.Models.ODataErrors.ODataError' was thrown.'" leveraging .NET MAUI 7.0 with Microsoft.Graph to execute WindowsAutoPilotDeviceIdentity.UpdateDeviceProperties. I submitted the below to stackoverflow when running 5.0.0 preview 14, though, I am still getting the same error after the update to 5.0.0-rc.1. Is there an issue with my code, or is this not supported with maui?

Stackoverflow question URL: https://stackoverflow.com/questions/74816802/how-do-i-leverage-microsoft-graph-to-update-autopilot-information

public async Task<bool> UpdateAutopilotDeviceAsync(string managedDeviceId, UpdateDevicePropertiesPostRequestBody updateParameters)
        {
            if (_graphServiceClient == null)
            {
                await SignInAndInitializeGraphServiceClient();
            }
            try
            {
//LINE THROWING ERROR HERE
                await _graphServiceClient.DeviceManagement.WindowsAutopilotDeviceIdentities[managedDeviceId].UpdateDeviceProperties.PostAsync(updateParameters);
//LINE THROWING ERROR HERE
                return await Task.FromResult(true);
            }
            catch { }
        private async void Save_Clicked(object sender, EventArgs e)
        {
            string managedDeviceId = Device.ManagedDeviceId;

            UpdateDevicePropertiesPostRequestBody updateParameters = new()
            {
                UserPrincipalName = Device.UserPrincipalName,
                AddressableUserName = Device.AddressableUserName,
                GroupTag = Device.GroupTag,
                DisplayName = Device.DisplayName
            };

            await PublicClientSingleton.Instance.MSGraphHelper.UpdateAutopilotDeviceAsync(managedDeviceId, updateParameters);
        }

Stack trace:

    0x1A in Android.Runtime.JNINativeWrapper._unhandled_exception at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:12,5 C#
    0x1D in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:23,26    C#
    0x17 in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw    C#
    0x6 in System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0 C#
    0xC in Android.App.SyncContext. at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.App/SyncContext.cs:36,19 C#
    0xE in Java.Lang.Thread.RunnableImplementor.Run at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:36,6 C#
    0x8 in Java.Lang.IRunnableInvoker.n_Run at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Java.Lang.IRunnable.cs:84,4    C#
    0x8 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:22,5  C#
]```

mrhls2312 avatar Dec 27 '22 16:12 mrhls2312

Let's assume that I have the following code for v4

client.Users[userId].CalendarView.Request(queryOptions).Filter(filterQuery).Expand(expandOptions).Select(SelectQuery).GetAsync()

The code for v5 looks like this but there is no Expand property in CalendarViewRequestBuilderGetQueryParameters class

client
    .Users[userId]
    .CalendarView
    .GetAsync(cfg =>
    {
        cfg.QueryParameters.StartDateTime = from;
        cfg.QueryParameters.EndDateTime = to;
        cfg.QueryParameters.Filter = filterQuery;
        cfg.QueryParameters.Select = SelectQuery;
    })

Is it a bug or is there any other reason why Expand property is missing in CalendarViewRequestBuilderGetQueryParameters?

Metadata issue tracked via https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/1581

andrueastman avatar Jan 05 '23 06:01 andrueastman

Greetings,

I am receiving the error message "Microsoft.Graph.Models.ODataErrors.ODataError: 'Exception of type 'Microsoft.Graph.Models.ODataErrors.ODataError' was thrown.'" leveraging .NET MAUI 7.0 with Microsoft.Graph to execute WindowsAutoPilotDeviceIdentity.UpdateDeviceProperties. I submitted the below to stackoverflow when running 5.0.0 preview 14, though, I am still getting the same error after the update to 5.0.0-rc.1. Is there an issue with my code, or is this not supported with maui?

Stackoverflow question URL: https://stackoverflow.com/questions/74816802/how-do-i-leverage-microsoft-graph-to-update-autopilot-information

public async Task<bool> UpdateAutopilotDeviceAsync(string managedDeviceId, UpdateDevicePropertiesPostRequestBody updateParameters)
        {
            if (_graphServiceClient == null)
            {
                await SignInAndInitializeGraphServiceClient();
            }
            try
            {
//LINE THROWING ERROR HERE
                await _graphServiceClient.DeviceManagement.WindowsAutopilotDeviceIdentities[managedDeviceId].UpdateDeviceProperties.PostAsync(updateParameters);
//LINE THROWING ERROR HERE
                return await Task.FromResult(true);
            }
            catch { }
        private async void Save_Clicked(object sender, EventArgs e)
        {
            string managedDeviceId = Device.ManagedDeviceId;

            UpdateDevicePropertiesPostRequestBody updateParameters = new()
            {
                UserPrincipalName = Device.UserPrincipalName,
                AddressableUserName = Device.AddressableUserName,
                GroupTag = Device.GroupTag,
                DisplayName = Device.DisplayName
            };

            await PublicClientSingleton.Instance.MSGraphHelper.UpdateAutopilotDeviceAsync(managedDeviceId, updateParameters);
        }

Stack trace:

    0x1A in Android.Runtime.JNINativeWrapper._unhandled_exception at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:12,5 C#
    0x1D in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:23,26    C#
    0x17 in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw    C#
    0x6 in System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0 C#
    0xC in Android.App.SyncContext. at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.App/SyncContext.cs:36,19 C#
    0xE in Java.Lang.Thread.RunnableImplementor.Run at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:36,6 C#
    0x8 in Java.Lang.IRunnableInvoker.n_Run at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Java.Lang.IRunnable.cs:84,4    C#
    0x8 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:22,5  C#
]```

We're following up on the linked Stack overflow question

andrueastman avatar Jan 05 '23 06:01 andrueastman

            var item = await graphServiceClient.Drives["drive-id"].Items["item-id"]
                .ItemWithPath(Path.GetFileName("data/sample.pdf"))
                .Content
                .GetAsync();

            var item2 = await graphServiceClient.Drives["ils"].Root
                .ItemWithPath(Path.GetFileName("sample.pdf"))
                .Content
                .GetAsync();

More information on the drive paths is documented at the link below.

https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/feature/5.0/docs/upgrade-to-v5.md#drive-item-paths

Thanks. So officially there are the endpoints:

GET /me/drive/root:/{item-path}
GET /drives/{drive-id}/root:/{item-path}

The .me I was not able to figure out a way to generate although it does work with a manually composed request. The second one does work, but there seems to be a 3rd option and that is using "Me" for the drive ID which works and eliminates the extra request.

// The below two commented lines do work, but you can also just do the active line below them instead.
//var myDrive = await graphClient.Me.Drive.GetAsync();
//var file = await graphClient.Drives[myDrive.Id].Root
var file = await graphClient.Drives["Me"].Root
						.ItemWithPath(path)
						.GetAsync()

mitchcapper avatar Jan 27 '23 01:01 mitchcapper

How to get id of uploaded file?

I have the following code to upload file.

PutAsync() doesn't return any response but PUT /drives/{drive-id}/items/{parent-id}:/{filename}:/content returns driveItem

await _graphServiceClient.Drives[{drive-id}].Root.ItemWithPath({filename}).Content.PutAsync(file);

now I need to make one extra request

var driveItem = await _graphServiceClient.Drives[{drive-id}].Root.ItemWithPath({filename}).GetAsync();

MartinM85 avatar Feb 26 '23 14:02 MartinM85

To create a new table I can call

POST https://graph.microsoft.com/v1.0/me/drive/items/{id}/workbook/tables/add
Content-type: application/json

{
  "address": "Sheet1!A1:D5",
  "hasHeaders": true
}

In code I can call

await _graphServiceClient.Drives[driveId].Items[itemId].Workbook.Tables.PostAsync(WorkbookTable);

but WorkbookTable doesn't have address and hasHeaders properties.

I don't see any way how to add data to a worksheet. There is no PostAsync() method for MicrosoftGraphRange

await _graphServiceClient.Drives[driveId].Items[itemId].Workbook.Worksheets[sheetId].Tables[tableId].MicrosoftGraphRange.PostAsync();

MartinM85 avatar Feb 26 '23 15:02 MartinM85

Cannot expand attachments for messages. There is no Expand property

var messagesResponse = await _client.Me.Messages.GetAsync(x=>
{
    x.QueryParameters.Select = new string[] { "id", "createdDateTime" };
    x.QueryParameters.Expand = new string[] { "attachments" };
});

@andrueastman

MartinM85 avatar Mar 02 '23 06:03 MartinM85

There is tens of CreateUploadSessionPostRequestBody classes in different namespaces with very very long names.

It's quite complicated to use the correct CreateUploadSessionPostRequestBody class. If I use more than one CreateUploadSessionPostRequestBody from different namespace then I need to specify the class like this and it makes the code unreadable

var uploadSessionOne = new Microsoft.Graph.Drives.Item.Items.Item.MicrosoftGraphCreateUploadSession.CreateUploadSessionPostRequestBody{};

var uploadSessionTwo = new Microsoft.Graph.Users.Item.Todo.Lists.Item.Tasks.Item.Attachments.MicrosoftGraphCreateUploadSession.CreateUploadSessionPostRequestBody {};

https://github.com/microsoftgraph/msgraph-sdk-dotnet/search?p=2&q=CreateUploadSessionPostRequestBody&type=code

MartinM85 avatar Mar 02 '23 12:03 MartinM85

hi there, i started using ms graph .net sdk last week and implemented my requirements with v4 (wasn't avare of v5 until it was released). after a very short ride with v5 today, i got stuck: i need to consume delta functions and could not find a way to send $deltatoken on v5. i searched the docs but could not find anything relevant (sorry if i missed it); where can i get guidance on this?

akurone avatar Mar 02 '23 21:03 akurone

Cannot expand attachments for messages. There is no Expand property

var messagesResponse = await _client.Me.Messages.GetAsync(x=>
{
    x.QueryParameters.Select = new string[] { "id", "createdDateTime" };
    x.QueryParameters.Expand = new string[] { "attachments" };
});

@andrueastman

Tracked via https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/1672

andrueastman avatar Mar 03 '23 05:03 andrueastman

To create a new table I can call

POST https://graph.microsoft.com/v1.0/me/drive/items/{id}/workbook/tables/add
Content-type: application/json

{
  "address": "Sheet1!A1:D5",
  "hasHeaders": true
}

In code I can call

await _graphServiceClient.Drives[driveId].Items[itemId].Workbook.Tables.PostAsync(WorkbookTable);

but WorkbookTable doesn't have address and hasHeaders properties.

I don't see any way how to add data to a worksheet. There is no PostAsync() method for MicrosoftGraphRange

await _graphServiceClient.Drives[driveId].Items[itemId].Workbook.Worksheets[sheetId].Tables[tableId].MicrosoftGraphRange.PostAsync();

Tracked via https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/1672

andrueastman avatar Mar 03 '23 05:03 andrueastman

Thanks for the feedback and trying out the preview everyone. We'll close this issue and track any new issues raised by creating new issues on the repo.

Thanks again!

andrueastman avatar Mar 03 '23 06:03 andrueastman