You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过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/tasks call. We assign it an id: "1" so we can dynamically reference the newly created task in the next two requests using the $1 syntax. Don't forget to replace YOUR_PLAN_ID and YOUR_BUCKET_ID with your actual values.
  • Request 2 (Fetch Task Details): Instead of hardcoding the task ID we just created, we use $1@odata.id/details to point directly to the new task's details endpoint. The Prefer: return=representation header 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 the If-Match header: we use $2@odata.etag to pull the ETag directly from the second request's response—no manual parsing required!

Important Tips

  • Send this entire batch as a POST request to the Graph API's /batch endpoint.
  • 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/json for POST and PATCH calls.

内容的提问来源于stack exchange,提问作者AbdulKareem

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 06:18:53