Invalid Request Error When Creating A New DriveItem

Emre Turkis 1 Reputation point

We're getting the following error when we try to create a new driveItem(file). I checked the documentation but everything seems fine. I'm not experienced with this API but can it be that something changed recently? It says the 'parentReference' was not allowed there but it clearly is, looking at the documentation of driveItem. We didn't change the code too. Any ideas?


SdkVersion : graph-java/v1.5.0

{ "file": {}, "name": "....pdf", "parentReference": { "driveId": "b!CI0Uhi...", "id": "01BRIXMT..." } }


400 : Bad Request
Transfer-Encoding : chunked
Strict-Transport-Security : max-age=31536000
Cache-Control : no-store, no-cache
x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"South Central US","Slice":"E","Ring":"5","ScaleUnit":"005","RoleInstance":"SN4PEPF0000085A"}}
client-request-id : 535b6eab-c9ad-45a2-9bc9-7264c935014d
Vary : Accept-Encoding
request-id : 202ce588-4f71-436c-b9f2-28e95a572eda
Date : Fri, 11 Nov 2022 20:18:32 GMT
Content-Type : application/json

{ "error": { "code": "invalidRequest", "message": "The item cannot contain a parentReference", "innerError": { "date": "2022-11-11T20:18:33", "request-id": "202ce588-4f71-436c-b9f2-28e95a572eda", "client-request-id": "535b6eab-c9ad-45a2-9bc9-7264c935014d" } } }

Microsoft Graph Files API
Microsoft Graph Files API
A Microsoft API to create an app that connects with files across OneDrive, OneDrive for Business, and SharePoint document libraries.
351 questions
Microsoft Graph SDK
Microsoft Graph SDK
A Microsoft software developer kit designed to simplify building high-quality, efficient, and resilient applications that access Microsoft Graph.
882 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Srinivasa Rao Darna 6,461 Reputation points

    Hi ,

    Using driveitem-post-children you can only create a new file with a simple request body.

        "name": "New_Doc1.dox",  
        "file": {},  
        "@microsoft.graph.conflictBehavior": "rename"  

    You don't have to use parentReference in request body as the same is defined with items/{item-id} suggesting creating file under folder with item-id.
    Hope this helps.
    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

  2. Grzegorz Orda 46 Reputation points

    Looks like MS made some clean up when it comes to unnecessary properties.

    I had same issue with
    await _graphClient.Sites[SiteId].Drive.Root.Children.Request().AddAsync(driveItem);

    but when commented out ParentReferences stated work.


    In order to create folder with deeper structure it's necessary to use

    await _graphClient.Sites[SiteId].Drive.Root.ItemWithPath(rootFolder).Children.Request().AddAsync(driveItem);