Can we create folder and file upload at same time(in one request) using sharepoint api?

Purvesh Tejani 0 Reputation points
2023-02-09T04:20:47.2266667+00:00

We need to create a folder and upload the file at the same time can it be possible. In any circumstances it is possible can you provide us with code or documentation about this? We want to create a folder and upload files in one API request.

Microsoft 365 and Office SharePoint For business Windows
Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2023-02-09T06:58:59.8066667+00:00

    Hi @Purvesh Tejani

    I don't think this is possible via Rest API or Graph API. We have different api for create folder and upload files. The request body are different too.

    When you create a folder in sharepoint via Graph, you will need to use following api and request body

    POST /sites/{site-id}/drive/items/{parent-item-id}/children
    {
      "name": "New Folder",
      "folder": { },
      "@microsoft.graph.conflictBehavior": "rename"
    }
    
    

    When you upload a file by Graph, you can use following api

    PUT /sites/{site-id}/drive/items/{parent-id}:/{filename}:/content
    
    

    Here is the document for reference

    Create a new folder in a drive

    Upload or replace the contents of a DriveItem


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.