Microsoft Graph API - Large File Upload Failing with Bad Request Response

Roshan Raj A K 20 Reputation points
2025-04-02T16:10:35.9133333+00:00

Hi All,

We are attempting to upload large files to SharePoint using the createUploadSession and UploadBytes APIs. While we have successfully uploaded files to the root directory of the SharePoint drive, we are encountering a 400 Bad Request error when attempting to upload files to a specific folder.

Here are the APIs we are using:

Successful Upload (Root Directory): https://graph.microsoft.com/v1.0/drives/{{driveId}}/root:/{{File-Name}}:/createUploadSession

Issue Faced (Specific Folder Upload): https://graph.microsoft.com/v1.0/sites/{{siteId}}/drive/items/{{itemId}}/createUploadSession

For the itemId, we are retrieving the list of items in the drive using the GetDriveItems API and selecting an ID corresponding to the target folder.

On hitting the url for the Specific Folder Upload API, we are facing issues with the 400 Bad request

We would appreciate any insights or solutions to resolve this issue.

Thanks & Regards,

Roshan Raj A K

Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Saranya Madhu-MSFT 2,375 Reputation points Microsoft External Staff
    2025-04-03T05:12:13.5533333+00:00

    Hi Roshan Raj A K,

    Thanks for reaching out to Microsoft!

    The error code 400 typically indicates a bad request. This could be due to an incorrect URL or missing parameters. In your case, it seems like the URL for creating the upload session might be incorrect. The URL should point to the specific item in the drive where you want to upload the file.

    I tried from my end and was able to successfully get a success response. I retrieved the itemId by using the following API:

    GET https://graph.microsoft.com/v1.0/sites/{siteId}/drive/root/children
    

    User's image

    This API lists all items in the root directory, from which you can select the itemId corresponding to the target folder. Ensure that you replace {siteId} with the actual site ID.

    Once you have the correct itemId, you can use it in the URL for creating the upload session:

    POST https://graph.microsoft.com/v1.0/sites/{siteId}/drive/items/{itemId}/createUploadSession
    

    User's image

    Make sure all required headers and parameters are included in your request.

    Hope this helps.

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


  2. Roshan Raj A K 20 Reputation points
    2025-04-08T12:36:11.0933333+00:00

    Hello Everyone,

    I wanted to share an approach that helped us resolve the "Bad Request" error we encountered previously. Here's the API we used:

    POST https://graph.microsoft.com/v1.0/sites/{{site_id}}/drives/{{drive_id}}/items/{{item_id}}:/{{file_name}}:/createUploadSession
    

    Headers:

    • Bearer Token
    • Content-Type: application/JSON

    Request Body:

    {
      "item": {
        "@microsoft.graph.conflictBehavior": "rename",
        "name": "FileName"
      }
    }
    

    After ensuring that the parameters in the URL were correctly parsed, we no longer faced the "Bad Request" error.

    I hope this approach is helpful to anyone facing a similar issue.

    Best regards,

    Roshan Raj A K

    0 comments No comments

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.