diff --git a/worker/jobs/graphFetch.ts b/worker/jobs/graphFetch.ts index d834985..28753d4 100644 --- a/worker/jobs/graphFetch.ts +++ b/worker/jobs/graphFetch.ts @@ -3,6 +3,19 @@ import { withRetry, isTransientError } from '../utils/retry'; type GraphRecord = Record; +// Certain Intune resources exist only on the beta Graph surface. +const BETA_ENDPOINTS = new Set([ + '/deviceManagement/configurationPolicies', + '/deviceManagement/intents', +]); + +function baseUrlFor(endpoint: string) { + for (const beta of BETA_ENDPOINTS) { + if (endpoint.startsWith(beta)) return 'https://graph.microsoft.com/beta'; + } + return 'https://graph.microsoft.com/v1.0'; +} + /** * Fetch a Graph endpoint with pagination support for @odata.nextLink * Returns an array of items aggregated across pages. @@ -71,7 +84,8 @@ export async function fetchWithPagination( */ export async function fetchFromGraph(endpoint: string) { const token = await getGraphAccessToken(); - return fetchWithPagination(endpoint, token); + const baseUrl = baseUrlFor(endpoint); + return fetchWithPagination(endpoint, token, baseUrl); } export default fetchFromGraph;