Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DCourtel opened this issue Jul 19, 2023 · 10 comments

Comments

@DCourtel
Copy link

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?

@andrueastman
Copy link
Member

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 andrueastman added Question: SDK Not actionable. Question related to the SDK. Needs: Author Feedback Question: API Not actionable. Question related to the API functionality. labels Jul 20, 2023
@DCourtel
Copy link
Author

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.

@andrueastman
Copy link
Member

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

@DCourtel
Copy link
Author

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

@andrueastman
Copy link
Member

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?

@DCourtel
Copy link
Author

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?

@andrueastman
Copy link
Member

@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?

@DCourtel
Copy link
Author

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

Copy link
Contributor

No description provided.

@andrueastman
Copy link
Member

Thanks. We've created microsoftgraph/msgraph-metadata#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 andrueastman removed Question: SDK Not actionable. Question related to the SDK. Needs: Attention 👋 Question: API Not actionable. Question related to the API functionality. labels Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants