Graph API:更改计划名称-补丁语法

时间:2018-10-08 15:57:32

标签: powershell microsoft-graph

我正在尝试通过Powershell更改计划的标题,但我似乎做得不好:

1)我首先在标题中添加授权令牌和etag:

$headers = @{}
$headers.Add("If-Match",'etag goes here')
$headers.Add('Authorization',"Bearer $accessToken")

2)声明新标题

$newtitle = @{title = 'The new title'}
$json = $newtitle | ConvertTo-Json

3)调用api

$url = "https://graph.microsoft.com/v1.0/planner/tasks/task-id"
    $edittask = Invoke-RestMethod -Headers  @{Authorization = "Bearer $accessToken"} -Uri $url -Method 'PATCH' -ContentType 'application/json' -Body $json

此操作失败,并显示412-Precondition Failed,我对我缺少什么有任何想法吗?

1 个答案:

答案 0 :(得分:0)

根据您的描述,我假设您要更新计划或任务。

请参阅this document412 status code can be returned if the etag value specified in the request no longer matches a version of the resource in the service. In this case, the clients should read the resource again and obtain a new etag

因此,我们应该再次阅读资源并获取新的etag。