msgraph-beta-sdk-dotnet
msgraph-beta-sdk-dotnet copied to clipboard
Graph SDK V5: _graphClient.DeviceAppManagement.MobileApps[appId].PatchAsync(mobileApp) throw an Exception
I try to update a property of a MobileApp using PatchAsync and receive an Exception: ModelValidationFailure with message: Exception has been thrown by the target of an invocation.
var mobileApp = await _graphClient.DeviceAppManagement.MobileApps[appId].GetAsync();
mobileApp!.Description = "New Description";
await _graphClient.DeviceAppManagement.MobileApps[appId].PatchAsync(mobileApp);
What am I doing wrong?
I suspect that this may be caused by the API return type being abstract i.e. MobileApp
and you need to send back a concrete derived type.
Any chance you have any change if you something like this?
var mobileApp = await _graphClient.DeviceAppManagement.MobileApps[appId].GetAsync();
var win32LobApp = new Win32LobApp{ Description = "New Description"}; // use a derived instance
await _graphClient.DeviceAppManagement.MobileApps[appId].PatchAsync(win32LobApp);
Thanks for your feedback. It works as long as I don’t try to PATCH navigation properties (like Categories). If I try, I get this error message:
Cannot apply PATCH to navigation property 'categories' on entity type 'microsoft.management.services.api.mobileApp'.
How can I PATCH the Categories property?
Thanks.
The correct way to read/delete/update the categories is through the methods outlined in the documentation at https://learn.microsoft.com/en-us/graph/api/resources/intune-apps-mobileappcategory?view=graph-rest-1.0#methods
Thanks for your feedback. Unfortunately, the link you provide describes how to work with Categories. What I want is to add a Category to a MobileApp. So, PATCH the Categories property of the Win32LobApp class. My current workaround is:
var requestInfo = new RequestInformation()
{
HttpMethod = Method.POST,
URI = new Uri($"{_graphClient.RequestAdapter.BaseUrl}/deviceAppManagement/mobileApps/{appId}/categories/$ref"),
};
requestInfo.SetContentFromParsable(_graphClient.RequestAdapter, "application/json", new CategoryId(categoryId));
await _graphClient.RequestAdapter.SendNoContentAsync(requestInfo, _errorMapping, default);
Thanks for clearing this up.
To confirm what you are saying is that the SDK is missing a path to call the path
https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/{appId}/categories/$ref
. Which would be an issue with the metadata used to generate the SDK any chance you can share if there is any supporting documentation for this? Or would the docs also need to be updated to capture this as well?
To my knowledge, there is no documentation about that. Besides, I see there are PostAsync() and DeleteAsync() for Assignments:
- _graphClient.DeviceAppManagement.MobileApps[appId].Assignments.PostAsync(assignment);
- _graphClient.DeviceAppManagement.MobileApps[appId].Assignments[assignmentId].DeleteAsync();
Can we get the same for Categories?
@DCourtel Just to recap what you are saying is that we need
- A path to add category references - https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/{appId}/categories/$ref
- A path to add a category via the
mobileApps
- POST https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/{appId}/categories - A path to delete a category via the
mobileApps
- POST https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/{appId}/categories/{category-Id}
Any chance this has been captured correctly?
@andrueastman, 3. The HTTP verb would be DELETE not POST.
Thanks. We've created https://github.com/microsoftgraph/msgraph-metadata/issues/510 so that the metadata can be updated so that the paths can be looked into in the metadata used to generated the SDK.