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

Graph SDK V5: _graphClient.DeviceAppManagement.MobileApps[appId].PatchAsync(mobileApp) throw an Exception

Open DCourtel opened this issue 1 year ago • 10 comments

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?

DCourtel avatar Jul 19 '23 14:07 DCourtel

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);

andrueastman avatar Jul 20 '23 10:07 andrueastman

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.

DCourtel avatar Jul 20 '23 13:07 DCourtel

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

andrueastman avatar Nov 16 '23 12:11 andrueastman

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);

DCourtel avatar Nov 16 '23 13:11 DCourtel

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?

andrueastman avatar Nov 17 '23 08:11 andrueastman

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 avatar Nov 20 '23 08:11 DCourtel

@DCourtel Just to recap what you are saying is that we need

  1. A path to add category references - https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/{appId}/categories/$ref
  2. A path to add a category via the mobileApps - POST https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/{appId}/categories
  3. 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 avatar Nov 22 '23 06:11 andrueastman

@andrueastman, 3. The HTTP verb would be DELETE not POST.

DCourtel avatar Nov 22 '23 09:11 DCourtel

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.

andrueastman avatar Nov 22 '23 10:11 andrueastman