msgraph-sdk-powershell
msgraph-sdk-powershell copied to clipboard
Cannot create new drive item folder - property folder not included in HTTP request body
Describe the bug Cannot create new drive item folder.
As you can see from the debug, the property folder is missing in json body
To Reproduce Steps to reproduce the behavior:
Attempt to create a folder
Import-Module Microsoft.Graph.Files
$params = @{
name = "New Folder"
folder = @{
}
"@microsoft.graph.conflictBehavior" = "rename"
}
New-MgDriveItemChild -DriveId $driveId -DriveItemId $driveItemId -BodyParameter $params
Fails with the exception
New-MgDriveItemChild : You must provide either a file facet if creating a file or a folder facet if creating a folder or a remoteItem facet if adding a shared folder Status: 400 (BadRequest) ErrorCode: invalidRequest Date: 2023-11-24T14:28:49 Headers: Transfer-Encoding : chunked Vary : Accept-Encoding Strict-Transport-Security : max-age=31536000 request-id : 9a656197-3963-4f37-8cb8-74cf6b6ed02f client-request-id : 90b6b522-b151-43ad-86af-85e6cbf4026b x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"Germany West Central","Slice":"E","Ring":"5","ScaleUnit":"001","RoleInstance":"FR2PEPF000001E1"}} Cache-Control : no-store, no-cache Date : Fri, 24 Nov 2023 14:28:49 GMT At line:12 char:1
- New-MgDriveItemChild -DriveId $driveId -DriveItemId $driveItemId -Bod ...
+ CategoryInfo : InvalidOperation: ({ DriveId = b!C...raphDriveItem }:<>f__AnonymousType3`3) [New-MgDriveItemChild_C reate], Exception + FullyQualifiedErrorId : invalidRequest,Microsoft.Graph.PowerShell.Cmdlets.NewMgDriveItemChild_Create
Expected behavior
Folder is created
Debug Output DEBUG: [CmdletBeginProcessing]: - New-MgDriveItemChild begin processing with parameterSet 'Create'. DEBUG: [Authentication]: - AuthType: 'Delegated', TokenCredentialType: 'InteractiveBrowser', ContextScope: 'CurrentUser', AppName: 'Microsoft Graph Command Line Tools'. DEBUG: [Authentication]: - Scopes: [Directory.Read.All, openid, profile, User.Read, email, Files.ReadWrite]. DEBUG: ============================ HTTP REQUEST ============================
HTTP Method: POST
Absolute Uri: https://graph.microsoft.com/v1.0/drives/xxx/items/xxx/children
Headers: FeatureFlag : 00000043 Cache-Control : no-store, no-cache User-Agent : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.22621; en-US),PowerShell/5.1.22621.2506 Accept-Encoding : gzip SdkVersion : graph-powershell/2.9.1 client-request-id : 45c6e360-45db-4fd2-a356-4c0334b65f93
Body: { "@microsoft.graph.conflictBehavior": "rename", "name": "New Folder" }
DEBUG: ============================ HTTP RESPONSE ============================
Status Code: BadRequest
Headers: Transfer-Encoding : chunked Vary : Accept-Encoding Strict-Transport-Security : max-age=31536000 request-id : f92fbceb-04c1-4f04-8844-313df82bfafb client-request-id : 45c6e360-45db-4fd2-a356-4c0334b65f93 x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"Germany West Central","Slice":"E","Ring":"5","ScaleUnit":"002","RoleIn stance":"FR3PEPF00000311"}} Cache-Control : no-store, no-cache Date : Fri, 24 Nov 2023 14:38:44 GMT
Body: { "error": { "code": "invalidRequest", "message": "You must provide either a file facet if creating a file or a folder facet if creating a folder or a remoteItem face t if adding a shared folder", "innerError": { "date": "2023-11-24T14:38:44", "request-id": "f92fbceb-04c1-4f04-8844-313df82bfafb", "client-request-id": "45c6e360-45db-4fd2-a356-4c0334b65f93" } } }
New-MgDriveItemChild : You must provide either a file facet if creating a file or a folder facet if creating a folder or a remoteItem facet if adding a shared folder Status: 400 (BadRequest) ErrorCode: invalidRequest Date: 2023-11-24T14:38:44 Headers: Transfer-Encoding : chunked Vary : Accept-Encoding Strict-Transport-Security : max-age=31536000 request-id : f92fbceb-04c1-4f04-8844-313df82bfafb client-request-id : 45c6e360-45db-4fd2-a356-4c0334b65f93 x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"Germany West Central","Slice":"E","Ring":"5","ScaleUnit":"002","RoleInstance":"FR3PEPF00000311"}} Cache-Control : no-store, no-cache Date : Fri, 24 Nov 2023 14:38:44 GMT At line:14 char:1
- New-MgDriveItemChild -DriveId $driveId -DriveItemId $driveItemId -Bod ...
-
+ CategoryInfo : InvalidOperation: ({ DriveId = b!C...raphDriveItem }:<>f__AnonymousType3`3) [New-MgDriveItemChild_C reate], Exception + FullyQualifiedErrorId : invalidRequest,Microsoft.Graph.PowerShell.Cmdlets.NewMgDriveItemChild_Create
DEBUG: [CmdletEndProcessing]: - New-MgDriveItemChild end processing.
Module Version At least latest version affected
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context Workaround is to add some fake property to folder facet
Import-Module Microsoft.Graph.Files
$params = @{
name = "New Folder"
folder = @{
x = 'x'
}
"@microsoft.graph.conflictBehavior" = "rename"
}
New-MgDriveItemChild -DriveId $driveId -DriveItemId $driveItemId -BodyParameter $params
@MartinM85 thanks for identifying and logging this issue. Indeed, there is an issue with how the SDK packages the request body especially when a nested object doesn't have a key-value pair. Thank you for also providing a workaround 👍