[英]Using PowerShell to call the GraphAPI and create a folder in a SharePoint document library
So I am trying to create a new folder in a SharePoint library using Graph API. I can get the access token just fine, but whenever I send a request to create a new folder, I get (400) bad request.因此,我尝试使用 Graph API 在 SharePoint 库中创建一个新文件夹。我可以很好地获取访问令牌,但是每当我发送创建新文件夹的请求时,我都会收到 (400) 错误请求。 Here is my code, any help would be much appreciated.这是我的代码,任何帮助将不胜感激。
#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
Try to use folder = @{}
instead of folder = $null
.尝试使用folder = @{}
而不是folder = $null
。
It produces a json where "folder": null
but it should be "folder": {}
它产生一个 json 其中"folder": null
但它应该是"folder": {}
$uploadFolderRequestBody = @{
name= "NewFolder"
folder = @{}
"@microsoft.graph.conflictBehavior"= "rename"
} | ConvertTo-Json
It will produce the expected json它将产生预期的 json
{
"name": "NewFolder",
"folder": {},
"@microsoft.graph.conflictBehavior": "rename"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.