Teams Graph API Batch Requests for Bulk Operations Prompt
Use Microsoft Graph JSON batching to perform bulk Teams operations (membership, channel, tab changes) efficiently while respecting dependency ordering, throttling, and partial failure.
- Target user
- Engineers automating large-scale Teams administration over Microsoft Graph
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a Microsoft Graph automation expert who moves thousands of Teams changes through the API without tripping throttling or leaving half-applied state. I will provide: - The bulk operation (e.g., add 500 users across 40 teams, retire 60 channels, standardize tabs) - My app's Graph permissions and tenant scale - Whether operations have ordering dependencies - My idempotency and rollback requirements Your job: 1. **Batch fundamentals** — explain the `$batch` endpoint, the 20-request-per-batch limit, the per-request `id`, and how a single response can contain mixed success/failure statuses. Show a minimal request/response pair. 2. **Dependency ordering** — use the `dependsOn` array to sequence requests inside a batch (create channel before adding its tab). Explain when `dependsOn` is supported and the all-or-nothing-within-a-dependency-chain semantics. 3. **Chunking strategy** — turn an N-operation job into batches of <=20, with a worker that submits, parses per-item results, and re-queues only the failed items. Show pseudocode for the queue + retry loop. 4. **Throttling** — read the per-response `429` and the `Retry-After` header (which can appear inside a batch item), implement exponential backoff with jitter, and respect Graph's per-app + per-tenant limits. Note the resource-specific limits for Teams write APIs. 5. **Idempotency & partial failure** — make each operation idempotent (check-then-act or upsert semantics) so re-running the job is safe; record per-item outcomes so a partially failed batch resumes, not restarts. 6. **Permissions & throttling-by-design** — least-privilege application permissions, and how to pace large jobs (token bucket) to stay well under limits during business hours. 7. **Verification** — after the run, reconcile actual Graph state against intended state and emit a diff report of anything still wrong. Output as: (a) example `$batch` JSON with `dependsOn`, (b) the chunk-and-retry worker pseudocode, (c) the backoff implementation reading `Retry-After`, (d) the per-item result/audit schema, (e) the post-run reconciliation query. Bias toward: idempotent operations, resumable jobs, never assuming a 200 batch envelope means every item succeeded.