【问题标题】:Resolving the response from Microsoft Graph API解析来自 Microsoft Graph API 的响应
【发布时间】:2020-05-20 07:37:24
【问题描述】:

我有点卡住了,所以基本上我调用了 graph api/resources/plannertaskdetails

$apiUrl = $('https://graph.microsoft.com/v1.0/planner/tasks/' + $taskId +'/details')
$response = Invoke-RestMethod -Headers @{Authorization = "Bearer $($token.access_token)"} -Uri $apiUrl -Method Get

我得到了回复,类似这样:

@{@odata.context=xxxx/details/$entity; description=value 1; previewType=automatic; id=bxxxxm; references=; checklist=}

references 和 checklist 是列表 (https://docs.microsoft.com/en-us/graph/api/resources/plannertaskdetails?view=graph-rest-1.0)

所以当我执行 $response.checklist 时,我看到 @{18907=; 35669=; 41911=}(代表列表项)

所以当我这样做时,例如$response.checklist.18907 我看到@{@odata.type=#microsoft.graph.plannerChecklistItem; isChecked=True; title=Step 1; orderHint=; lastModifiedDateTime=; lastModifiedBy=}

现在我的问题是,如何轻松访问其中的那些列表对象。

做类似的事情

foreach($option in $response.checklist)
{
    $option.Title= ....;
}

在这个 $response 中,我可以得到例如描述 ($response.discription or $description.id),但不能得到清单和参考。

否则我有点卡住了,如果我尝试 | ConvertFrom-Json,我得到一个错误无效的 JSON 原语等。

任何建议将不胜感激。

【问题讨论】:

    标签: json powershell rest graph microsoft-graph-api


    【解决方案1】:

    我认为这应该可行:

    foreach($checklistId in $response.checklist.Keys)
    {
        $response.checklist[$checklistId].title= ....;
    }
    

    AFAIK,Invoke-WebRequest 通过解析 JSON 输出在 PowerShell 中返回解析字典结构。

    【讨论】:

      猜你喜欢
      • 2013-05-29
      • 1970-01-01
      • 1970-01-01
      • 2014-01-21
      • 2017-06-14
      • 1970-01-01
      • 2018-08-17
      • 1970-01-01
      • 2015-04-03
      相关资源
      最近更新 更多