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 Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,715 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,737 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 31,681 Reputation points Microsoft Vendor
    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.