如何通过Microsoft Graph批量创建并更新Planner任务?
Combine Planner Task Creation & Updates into a Single JSON Batch Call
Got it, let's walk through how to bundle those three Planner task operations into one single JSON batch request using OData's entity referencing feature—no need to make three separate calls or manually extract IDs and ETags. Here's a complete, working example plus a breakdown of how everything fits together:
Full Batch Request Body
{ "requests": [ { "id": "1", "method": "POST", "url": "/planner/tasks", "headers": { "Content-Type": "application/json" }, "body": { "planId": "YOUR_PLAN_ID", "bucketId": "YOUR_BUCKET_ID", "title": "New Planner Task" } }, { "id": "2", "method": "GET", "url": "$1@odata.id/details", "headers": { "Prefer": "return=representation" } }, { "id": "3", "method": "PATCH", "url": "$1@odata.id/details", "headers": { "Content-Type": "application/json", "If-Match": "$2@odata.etag" }, "body": { "description": "Updated task details via batch call", "previewType": "description" } } ] }
Breakdown of Each Request
- Request 1 (Create Base Task): This is your initial
POST /planner/taskscall. We assign it anid: "1"so we can dynamically reference the newly created task in the next two requests using the$1syntax. Don't forget to replaceYOUR_PLAN_IDandYOUR_BUCKET_IDwith your actual values. - Request 2 (Fetch Task Details): Instead of hardcoding the task ID we just created, we use
$1@odata.id/detailsto point directly to the new task's details endpoint. ThePrefer: return=representationheader ensures we get the full details object back, which includes the ETag we need for the PATCH operation. - Request 3 (Update Task Details): We again reference the new task's details with
$1@odata.id/details. The critical part here is theIf-Matchheader: we use$2@odata.etagto pull the ETag directly from the second request's response—no manual parsing required!
Important Tips
- Send this entire batch as a
POSTrequest to the Graph API's/batchendpoint. - Request order is non-negotiable: the POST has to come first, followed by the GET, then the PATCH, since each step depends on the one before it.
- Ensure each individual request in the batch has the required headers—like
Content-Type: application/jsonfor POST and PATCH calls.
内容的提问来源于stack exchange,提问作者AbdulKareem
相关产品推荐
相关产品推荐

