How do you re-assign a primary user to an Intune device using Graph

Jason Pelletier 21 Reputation points
2025-01-31T19:14:03.61+00:00

We're struggling with finding a way to use the Graph API to re-assign a primary user to a device in Intune. We've built a custom loaning center application where we'd need to replace the primary user whenever a device is checked out so that the customer can access the Company Portal.

We've tried a variety of API actions, most of which existed in the beta version of the API, which no longer exist or are no longer options. Including:

https://graph.microsoft.com/v1.0/deviceManagement/windowsAutopilotDeviceIdentities/{windowsAutopilotDeviceIdentityId}/assignUserToDevice


Patching this with the body of the request being the userPrincipalName:

https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/{managedDeviceId}

The last one looks like it should work, but we get an error when running it. Does anyone have thoughts on how to get this to work, assuming it can or we should be able to do it?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,003 questions
Microsoft Intune
Microsoft Intune
A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.
5,531 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Xenia-MSFT 3,900 Reputation points Microsoft Vendor
    2025-02-03T02:38:08.6133333+00:00

    @Jason Pelletier Thanks for posting in our Q&A.

    For this issue, did you consider using PowerShell scripts to make it? If yes, please refer to the following link:

    https://github.com/Mr-Tbone/Intune/blob/master/Intune-Set-PrimaryUsers.ps1

    Note: Non-Microsoft link, just for the reference.

    Hope it will help.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Xenia-MSFT 3,900 Reputation points Microsoft Vendor
    2025-02-06T00:51:08.3833333+00:00

    @Jason Pelletier Thanks for your update.

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A forum has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer.

    Issue:

    How do you re-assign a primary user to an Intune device using Graph? Try this request URL (https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/{managedDeviceId}) but get an error.

    Solution:

    The following Request is working.

    POST https://graph.microsoft.com/v1.0/deviceManagement/managedDevices('{deviceId}')/users/$ref
    

    and a body of

    {"@odata.id": "https://graph.microsoft.com/v1.0/users/{userID}"}
    

    Thanks again for your sharing.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.