Thursday, 6 February 2020

SharePoint 2016 API Request getfolderbyserverrelativeurl 500 server error

I was recently asked to help troubleshoot a custom application which uses the SharePoint API to first check SharePoint for an item, and if it does not exist then to upload that file.

This was part of a migration from SharePoint 2013 to 2016, and the results differed for the same API request.

After trying the request in multiple SharePoint 2016 farms, I concluded that this was not down to a farm level issue/difference but likely a change in the way that SharePoint handles this particular event.

This may come in handy for those without a direct line to Microsoft, they have confirmed that SharePoint 2016 handles the event ID ay1r6 with a NullreferenceException as an unknown error and therefore the end user receives a 500 error rather than what would have been a 404 in SharePoint 2013.

So in my scenario, the code was trying to retrieve an item using the following API request: https://test.com/_api/web/getfolderbyserverrelativeurl('/Documents/2020 ')/

The logic is bad, but in the case of a 404 error for the location it would create that location and carry on but as 2016 throws a 500 the code no longer functioned.

SharePoint 2013 response to a non-existent library location:









SharePoint 2016 response to a non-existent library location:









Luckily there is an easy fix for this problem, as the developers should have already been using the ‘Exists’ method to return a value of true or false.


No comments:

Post a Comment