Hi @Mwinia
Depending on your context, batching shouldn't work for you. Although batch processing can handle multiple requests, each request is independent of each other, and you want to call the /devices
endpoint to get the id of each device, and then get the owner of each device according to the id, which shows that the two API endpoints are not independent of each other but are inherited.
You can only meet this requirement using code, first calling the /devices
endpoint and then traversal through the result set of that endpoint to get the ids of all devices, then passing the ids of the devices to the /devices/{id}/registeredOwners
endpoint. I have written the complete code for you, please refer to:
using Azure.Identity;
using Microsoft.Graph;
using Newtonsoft.Json;
var scopes = new[] { "https://graph.microsoft.com/.default" };
// Multi-tenant apps can use "common",
// single-tenant apps must use the tenant ID from the Azure portal
var tenantId = "tenant id";
// Values from app registration
var clientId = "client id";
var clientSecret = "client secret";
// using Azure.Identity;
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
// https://learn.microsoft.com/dotnet/api/azure.identity.clientsecretcredential
var clientSecretCredential = new ClientSecretCredential(
tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var devices = await graphClient.Devices
.Request()
.GetAsync();
for (int i = 0; i < devices.Count; i++) {
var deviceId = devices[i].Id.ToString();
var registeredOwners = await graphClient.Devices[deviceId].RegisteredOwners
.Request()
.GetAsync();
Console.WriteLine("registeredOwners:" + JsonConvert.SerializeObject(registeredOwners));
}
Console.ReadLine();
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.