Graph API ManagedDevice update call failure

I’m trying to make a call to Microsoft’s Graph api to update device ownership types for the company I’m working for. We have over 4,000 devices so this is something that needs to be automated. I’m writing a .NET app that uses a GraphServiceClient to connect to the api and make requests.

For some reason I keep receiving the following error as soon as I make the call, and I’m struggling to understand why?? (Device id and other information has been replaced with x’s)

Microsoft.Graph.Models.ODataErrors.ODataError: {
  "_version": 3,
  "Message": "An error has occurred - Operation ID (for customer support): 00000000-0000-0000-0000-000000000000 - Activity ID: xxxx-xxxx-xxxx-xxxx - Url: https://fef.msua06.manage.microsoft.com/DeviceFE/StatelessDeviceFEService/deviceManagement/managedDevices('XXXXXXXXXX')?api-version=2023-10-19",
  "CustomApiErrorPhrase": "",
  "RetryAfter": null,
  "ErrorSourceService": "",
  "HttpHeaders": "{}"
}
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.ThrowIfFailedResponse(HttpResponseMessage response, Dictionary`2 errorMapping, Activity activityForAttributes, CancellationToken cancellationToken)
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
   at Microsoft.Graph.DeviceManagement.ManagedDevices.Item.ManagedDeviceItemRequestBuilder.GetAsync(Action`1 requestConfiguration, CancellationToken cancellationToken)
   at GraphAuth.GraphHelper.UpdateDeviceOwnershipAsync(String deviceId) in C:Usersa49592DesktopGraphAuthGraphHelper.cs:line 80

Interestingly, I have already used the client to make api calls and grab user information. I’ve tested these functions to verify that the client can make authorized calls and receive the correct data. I have also updatef my api permissions so that DeviceManagementManagedDevices.ReadWrite.All is set.

My expectation was to pull down the managed device and update the ManagedDeviceOwnerType to company. Here is the current function I’m using:

public async static Task UpdateDeviceOwnershipAsync(string deviceId)
{
    // Ensure client isn't null
    _ = _appClient ??
        throw new System.NullReferenceException("Graph has not been initialized for app-only auth.");

    try
    {
        // Error occurs here, believe it has something to do
        // with API permissions, as the data isn't getting
        // sent back down
        ManagedDevice? device = await _appClient.DeviceManagement.ManagedDevices[deviceId].GetAsync();
    }
    catch (Exception ex)
    {
        Console.WriteLine($"ERROR:n{ex.ToString()}");
    }
}

And here is how I’m calling it inside my Program.cs file:

static async Task UpdateDeviceAsync()
{
    Console.WriteLine("Enter the device ID to update:");

    string? deviceId = Console.ReadLine();

    if (string.IsNullOrEmpty(deviceId))
    {
        Console.WriteLine("Device ID cannot be empty.");
        return;
    }

    try
    {
        await GraphHelper.UpdateDeviceOwnershipAsync(deviceId);
        Console.WriteLine("Device ownership type updated successfully.");
    }
    catch (Exception ex)
    {
        Console.WriteLine($"Error updating device ownership type:n{ex.Message}");
    }
}

Please let me know if there is any other info I can pass along to help debug my issue. Like I said, I would have assumed my api permissions may not be correct, but I have already checked that correct permission type has been set and I’m not sure what else it could be.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật