使用 PowerShell 调用 GraphAPI 并在 SharePoint 文档库中创建文件夹

Using PowerShell to call the GraphAPI and create a folder in a SharePoint document library

所以我正在尝试使用 Graph API 在 SharePoint 库中创建一个新文件夹。我可以很好地获得访问令牌,但是每当我发送创建新文件夹的请求时,我都会收到 (400) 错误请求。这是我的代码,将不胜感激。

#header containing access token
$header = @{
    Authorization = "Bearer " + $resp.access_token
}

$CreateFolderURL = "https://graph.microsoft.com/v1.0/drives/(Here I write the drive ID)/items/root/children"

$uploadFolderRequestBody = @{
name= "NewFolder"
folder = $null
"@microsoft.graph.conflictBehavior"= "rename"
} | ConvertTo-Json

Invoke-RestMethod -Headers $header -Method Post -Body $uploadFolderRequestBody -ContentType "application/json" -Uri $CreateFolderURL

尝试使用 folder = @{} 而不是 folder = $null

它产生一个 json,其中 "folder" : null 但它应该是 "folder" : {}

$uploadFolderRequestBody = @{
name= "NewFolder"
folder = @{}
"@microsoft.graph.conflictBehavior"= "rename"
} | ConvertTo-Json

它将产生预期的 json

{
    "name":  "NewFolder",
    "folder":  {},
    "@microsoft.graph.conflictBehavior":  "rename"
}