How do you re-assign a primary user to an Intune device with the Graph API

Samuel Tarr 0 Reputation points
2025-02-03T14:20:18.62+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.
12,988 questions
Microsoft Intune
Microsoft Intune
A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.
5,522 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Xenia-MSFT 3,900 Reputation points Microsoft Vendor
    2025-02-04T01:34:08.51+00:00

    @Samuel Tarr 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.

    0 comments No comments

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

    @Samuel Tarr I find someone else provided a solution. Please try and check if it is helpful.

    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}"}
    

    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.

    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.