none
REST API uploading a document fails 400 bad request RRS feed

  • Question

  • I came across a strange situation last week and have been unable to figure out what the problem is.  I have some c# code that copies files from a network share and puts them in various different document libraries in a site collection.  Well one of the libraries is either corrupt or somehow configured differently because any attempt to upload to it fails with a 400 Bad request.  All 5 other document libraries work so I doubt its code.

    Things verified so far:

    Versioning isn't set up to do anything silly.

    Less than 5000 documents

    Libraries that are working are the same content type as the one that fails.

    Inheritance isn't broken

    API's used:

    /_api/web/GetFolderByServerRelativeUrl(decodedurl='" + libraryName + "')/Files/Add(url='" + fileInfo.Name + "', overwrite=true)";

    "/_api/web/lists/getbytitle('" + libraryName + "')/rootfolder/files/Add(url='" + fileInfo.Name + "', overwrite=true)";

    These endpoints work on all other document libraries in the site collection

    I've tried via graph and it fails with the same error

    Anyone have an thoughts or ideas on how to trouble shoot this?

    Thanks




    • Edited by Dangkohler Tuesday, November 5, 2019 5:57 PM
    Tuesday, November 5, 2019 5:40 PM

All replies

  • The strange thing is that all the configuration works with CSOM i can confirm there aren't typos.  I also tested endpoints that get the list by id those work for the libraries that work but fail for the one troublesome one
    Tuesday, November 5, 2019 7:00 PM
  • After MS fixed whatever they did with connectivity issues at 2pm this code got 1 file in.  now its back to 400 errors and no code changes
    Tuesday, November 5, 2019 8:43 PM
  • Does anyone know if CSOM uses the same REST enpoints?
    Tuesday, November 5, 2019 8:56 PM
  • Hi,

    As far as I know, CSOM doesn’t use the same REST endpoints. These two are different client-side friendly API methods.

    Quoting the official document, to access SharePoint resources using REST, you need to construct a RESTful HTTP request by using the REST/OData standard, which corresponds to the desired client object model API.

    Please refer to the links below for further information.

    Get to know the SharePoint REST service.

    https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/get-to-know-the-sharepoint-rest-service

    SharePoint .NET Server, CSOM, JSOM, and REST API index.

    https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/sharepoint-net-server-csom-jsom-and-rest-api-index

    .NET client API reference for SharePoint Online.

    https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-csom/jj193041(v=office.15)?redirectedfrom=MSDN

    Best regards,

    Chelsea Wu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Wednesday, November 6, 2019 8:14 AM
  • Thanks for the effort, it doesn't really help.  I know CSOM, JSOM, REST and Graph endpoints.  I Posted this to see if anyone has any insights or thoughts why this could happen.  If anyone has any thoughts please respond but dont respond with links like above as i've read them years ago i'm looking for a solution with REST if able.  I think its a problem with the document library but i haven't yet figured it out.  I do have access to a DSE and top tier MS support so i guess i'll go there unless someone can help.   thanks all 
    Friday, November 8, 2019 8:43 PM
  • Hi,

    If you decide to open a ticket with Microsoft, please remember to update the thread if you have any progress.

    Thank you for your understanding.

    Best regards,

    Chelsea Wu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, November 12, 2019 7:24 AM
  • ***UPDATE***

    Although I don't have a root cause yet I believe I have narrowed down the issue.  First a little background about the document library.  It was created over 4 years ago.  Its had an automated process uploading files from a network share when there are changes every 15 minutes for the past 4 years.  It was configured to keep the last 100 major versions.  

    If you try to view version history for any file in the document library you get "Sorry something went wrong"

    The current process uploading documents is written with CSOM and it can upload these files.

    The new process that uses REST cannot upload these files and fails with 400 Bad request and a message of invalid parameter fileVersion.

    If I delete the problem file the REST code works as expected, version history then starts working as expected.

    So now I'm wondering if things break down when the version number gets too high?  These files are in the major version number area of +60,000.

    It seems the fix is either recreate the list or delete every file (resetting version history, i think).

    Friday, November 15, 2019 1:16 PM
  • Hi,

    Thanks for sharing the update with us.

    According to this Official document, SharePoint Online has a service limit of 50,000 major versions. So I agree with your suspicion, it might be the direct cause of this issue.

    You can mark your latest reply as the answer if it is confirmed to be the solution. It will help others who meet similar question in this forum.

    Thanks again for your contribution.

    Best regards,

    Chelsea Wu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, November 18, 2019 7:41 AM