$tenantId]); // Try primary endpoint $assignments = $this->fetchPrimary($policyId, $requestOptions); if (! empty($assignments)) { Log::debug('Fetched assignments via primary endpoint', [ 'tenant_id' => $tenantId, 'policy_id' => $policyId, 'count' => count($assignments), ]); return $assignments; } // Try fallback with $expand Log::debug('Primary endpoint returned empty, trying fallback', [ 'tenant_id' => $tenantId, 'policy_id' => $policyId, ]); $assignments = $this->fetchWithExpand($policyId, $requestOptions); if (! empty($assignments)) { Log::debug('Fetched assignments via fallback endpoint', [ 'tenant_id' => $tenantId, 'policy_id' => $policyId, 'count' => count($assignments), ]); return $assignments; } // Both methods returned empty Log::debug('No assignments found for policy', [ 'tenant_id' => $tenantId, 'policy_id' => $policyId, ]); return []; } catch (GraphException $e) { Log::warning('Failed to fetch assignments', [ 'tenant_id' => $tenantId, 'policy_id' => $policyId, 'error' => $e->getMessage(), 'context' => $e->context, ]); return []; } } /** * Fetch assignments using primary endpoint. */ private function fetchPrimary(string $policyId, array $options): array { $path = "/deviceManagement/configurationPolicies/{$policyId}/assignments"; $response = $this->graphClient->request('GET', $path, $options); return $response->data['value'] ?? []; } /** * Fetch assignments using $expand fallback. */ private function fetchWithExpand(string $policyId, array $options): array { $path = '/deviceManagement/configurationPolicies'; $params = [ '$expand' => 'assignments', '$filter' => "id eq '{$policyId}'", ]; $response = $this->graphClient->request('GET', $path, array_merge($options, [ 'query' => $params, ])); $policies = $response->data['value'] ?? []; if (empty($policies)) { return []; } return $policies[0]['assignments'] ?? []; } }