Update device category via Graph API

This is a knowledge base item. Hope it helps you if you want to update the device category of your Intune-managed device via Graph API.

While working on one of my projects, I needed to update the device category for multiple devices. I am not a PowerShell guru, so I decided to use the Graph API in conjunction with Power Automate.

First, I opened Graph Explorer to do it manually. I opened a device via the Graph API and tried to update the device category via the post, patch, and put actions. All those actions did not work.

My next step was to check the documentation. The documentation did not really help me. So, I opened the developer tool in Edge and went to the network tab. I changed the device category in Intune and saved the device properties and checked which Graph API URL is being used by the portal.

In this KB I will show how the issues that I had and how to resolve those issues and change the device category of your devices via Graph API.

Get the Device category of a device via Graph API

To get the device category of a device use the following URL with the get option in Graph API.

URL:

https://graph.microsoft.com/v1.0/devicemanagement/manageddevices/{Device-ID}?$select=deviceCategoryDisplayName

Issues

For the first attempt, I tried to change the device category via the Graph API I used the put and post option and the below URL, but with both options, I got the same result.

 

URL:

https://graph.microsoft.com/v1.0/devicemanagement/manageddevices/{Device-ID}

Request body:

{
    "deviceCategoryDisplayName": "Laptop"
}

On the second attempt, I tried to change the device category via the Graph API, I used this time the patch option. But still, this was not the fix.

 

URL:

https://graph.microsoft.com/v1.0/devicemanagement/manageddevices/{Device-ID}

Request body:

{
    "deviceCategoryDisplayName": "Laptop"
}

On the third attempt, I tried to change the device category via the Graph API with another Graph API URL, I used again the patch option. But still, this was not the fix.

 

URL:

https://graph.microsoft.com/v1.0/devicemanagement/manageddevices/{Device-ID}/devicecategory

Request body:

{
    "deviceCategoryDisplayName": "Laptop"
}

On the fourth attempt, I tried to change the device category via the Graph API, the put and patch option, and the below URL, but with both options, I got the same result and still, this was not the fix.

 

URL:

https://graph.microsoft.com/v1.0/devicemanagement/manageddevices/{Device-ID}/devicecategory

Request body:

{
    "deviceCategoryDisplayName": "Laptop"
}

Still no luck, I changed the device category in Intune and saved the device properties, and checked which Graph API URL is being used by the Intune portal via the developer menu in Edge.

Get device category ID via Graph API

Now I had the right Graph API URL. I still needed the device category ID to set the right category for the devices. To get the ID of a device category, I use the following URL with the get option in Graph API.

 

URL:

https://graph.microsoft.com/v1.0/devicemanagement/devicecategories

The correct Graph API URL to update the device category

On the next attempt, I tried to change the device category via the put option and the below URL and body via the Graph API, this time I get a success 204 message back from the Graph API. With the correct Graph API URL and device category, I was able to create the Power Automate flow.

 

URL:

https://graph.microsoft.com/beta/deviceManagement/managedDevices/{Device-ID}/deviceCategory/$ref

Request body:

{
  "@odata.id": "https://graph.microsoft.com/beta/deviceManagement/deviceCategories/{Device Category ID}"
}
1 reply
  1. MD Wahib
    MD Wahib says:

    Can you share the power automate flow, I am facing an issue with putting @odata.id in the body of HTTP request

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.