Value does not fall within the expected range in SharePoint Rest API

This Rest API SharePoint tutorial explains, how to resolve the error “Value does not fall within the expected range” which comes while working with Rest API in SharePoint 2013/2016/Online

Recently when I was trying to create a folder inside Shared Documents folder using Rest API I got the below error: System.ArgumentException. Value does not fall within the expected range.

Value does not fall within the expected range in SharePoint Rest API
Value does not fall within the expected range in SharePoint Rest API

Value does not fall within the expected range in SharePoint Rest API

Below is the code which I was writing to create folder inside document library in SharePoint.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(function(){
$("#btnClick").click(function(){
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/folders";
$.ajax({
url: requestUri,
type: "POST",
data:JSON.stringify({'__metadata': { 'type': 'SP.Folder' }, 'ServerRelativeUrl': '/Shared Documents/Folder1'}),
headers: {
"accept":"application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest":$("#_REQUESTDIGEST").val()
},
success: onSuccess,
error: onError
});

The problem was with the below line. The backslash (/) we have given before /Shared Documents was causing the issue.

data:JSON.stringify({'__metadata': { 'type': 'SP.Folder' }, 'ServerRelativeUrl': '/Shared Documents/Folder1'}),

To resolve the issue follow the below solution.

The path should take without backslash (/) and it worked.

data:JSON.stringify({'__metadata': { 'type': 'SP.Folder' }, 'ServerRelativeUrl': 'Shared Documents/Folder1'}),

You may like following SharePoint rest api tutorials:

Hope this Rest API tutorial helps to learn how to solve Value does not fall within the expected range in SharePoint Rest API.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>