Registering Devices for AutoPilot using Graph API

Clegg, Mark 21 Reputation points
2022-02-15T14:01:58.407+00:00

Hi

I'm trying to use the Graph API DeviceManagement.ImportedWindowsAutopilotDeivedIdentities in C# to register devices for Autopilot. I can create the GraphService object successfully, using an App registration, which has the correct permissions (DeviceManagementServiceConfig.ReadWrite.All) , but I can't get the new DeviceIdentity accepted.

extern alias MSGraphBeta;
using GraphBeta = MSGraphBeta.Microsoft.Graph;

public async void EnrolDevice(string newSerialNumber, string newHash)
{
    var GraphClient = Global.CreateBetaGraphServiceClient(); // Creates a GraphServiceClient object

    // Submit a registration request.

    var DeviceIdentity = new ImportedWindowsAutopilotDeviceIdentity()
    {
        SerialNumber = newSerialNumber,
        HardwareIdentifier = Encoding.ASCII.GetBytes(newHash),
        GroupTag = "",
        ProductKey = "",
        AssignedUserPrincipalName = "",
        State = new ImportedWindowsAutopilotDeviceIdentityState()
        {
            DeviceImportStatus = ImportedWindowsAutopilotDeviceIdentityImportStatus.Pending,
            DeviceRegistrationId = "",
            DeviceErrorCode = 0,
            DeviceErrorName = ""
        }
    };

    var ImportedDeviceIdentity = await GraphClient.DeviceManagement.ImportedWindowsAutopilotDeviceIdentities
        .Request()
        .AddAsync(DeviceIdentity); // <-- Exception thrown here.
}

On hitting the .addAsync() call, I get "An error has occurred", with very little to say why.

From the exception message:

Code: InternalError
Message: {
  "_version": 3,
  "Message": "An error has occurred - Operation ID (for customer support): 00000000-0000-0000-0000-000000000000 - Activity ID: *xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx* - Url: https://fef.msua01.manage.microsoft.com/DeviceEnrollmentFE_2201/StatelessDeviceEnrollmentFEService/deviceManagement/importedWindowsAutopilotDeviceIdentities?api-version=5021-11-23",
  "CustomApiErrorPhrase": "",
  "RetryAfter": null,
  "ErrorSourceService": "",
  "HttpHeaders": "{}"
}
Inner error:
    AdditionalData:
    date: 2022-02-15T13:28:34
    request-id: *guid*
    client-request-id: *guid*
ClientRequestId: *guid*

Has anybody had any experience doing this, and could offer any pointers?

The only thing that seems odd to me, is that the HardwareIdentifier has to be passed to the API as a byte[], where the value we get from WMI is a string, and the REST documentation also shows a string in the examples.

(I've tried both the v1.0 and Beta API entry points, with the same results).

Thanks.

Microsoft Intune
Microsoft Intune
A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.
5,109 questions
{count} votes

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.