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. 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
.
It produces a json where "folder" : null
but it should be "folder" : {}
$uploadFolderRequestBody = @{
name= "NewFolder"
folder = @{}
"@microsoft.graph.conflictBehavior"= "rename"
} | ConvertTo-Json
It will produce the expected json
{
"name": "NewFolder",
"folder": {},
"@microsoft.graph.conflictBehavior": "rename"
}