简体   繁体   English

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

[英]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.

相关问题 使用SharePoint Online PowerShell从模板创建文档库 - Create a Document Library from a Template using SharePoint Online PowerShell 使用 powershell 将文件上传到 SharePoint 文档库 - Upload file to SharePoint Document library using powershell 使用Powershell授予对Sharepoint库中文件夹的权限? - Grant permissions to folder in Sharepoint library using Powershell? 使用 Powershell PNP 获取 Sharepoint 在线文档库中特定文件夹中的项目 - Get items in specific folder in Sharepoint online document library with Powershell PNP Sharepoint PowerShell库文件夹权限 - Sharepoint PowerShell Library Folder permissions 使用PowerShell在SharePoint共享文档列表中创建“文档链接” - Create a 'Link to a Document' in a SharePoint Shared Document List using PowerShell 使用Windows PowerShell脚本访问Sharepoint文档库列表 - Accessing Sharepoint document library list using Windows PowerShell script 在SharePoint中使用PowerShell从文档库中获取项目列表 - Getting a list of items from document library using PowerShell in SharePoint 使用PnP PowerShell for SharePoint Online在文档库上设置“说明” - Setting the “Description” on a Document Library using PnP PowerShell for SharePoint Online 使用 pnp 更新 SharePoint 在线文档库列属性 PowerShell - update SharePoint online document library column property using pnp PowerShell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM