Came across another Clumsy Ninja SharePoint feature recently concerning the ListData.svc REST API which is found in both SharePoint 2010 and 2013.
This issue does not occur if you’re using the new _API REST interface for SharePoint 2013.
The issue concerns the list or library name which you use in a REST call;
ListData.svc REST Call:
Usually when you use a list or library name with ListData.svc, you use the list ‘Title’ and remove spaces from it, so given a list name of ‘My Cool List’ your REST call using ListData.svc would look like so;
http://team.pdogs.local/_vti_bin/ListData.svc/MyCoolList
And so to the problem
So, lets say you have a list whose title begins with 1 or more digit characters, lets say ‘3 Year Plan’,
Naturally, you create your REST call like this;
http://team.pdogs.local/_vti_bin/ListData.svc/3YearPlan
You execute your call, but it fails with the following error “Resource not found for the segment ‘3YearPlan'”;
What gives?
The problem is nothing to do with the list name and everything to do with how SharePoints LINQ DataServiceDataContext
handles list names.
The DataServiceDataContext class is found in assembly
Microsoft.SharePoint.Linq.DataService, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c
The class constructor maps SharePoint list titles in the addressed SPWeb;
Notice the call to Util.GetFriendlyName(...)
, its here that ‘friendly’ list names are created from the SharePoint list names and it’s these which are matched against the list name supplied by you in the REST call;
So as you can see, if a SharePoint list name starts with 1 or more digit characters, the letters "c_"
are prepended to the list name.
This means that you need to know (or detect) in advance of making your REST call that a list name is like this, so you can adjust the list name supplied in your REST call accordingly, and when you do, all works as expected;
So, from REST call to “/_vti_bin/ListData.svc/” I get internal list names – how can I get friendly name using REST API ?
The list name used in a REST query is the lists display name without spaces
Really? Can you provide a query string? I didn’t manage to find it
THE DATASERVICEDATACONTEXT CLASS IS FOUND IN ASSEMBLY
Microsoft.SharePoint.Linq.DataService, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c
Can you tell me Where Assembly is ?
I try see in C:\Windows\assembly but i dont see it.
Thanks you in advandce!
Thanks it really helped me 🙂
Excellent post thankyou.
SP2013+ REST is much better but I have a client still running SP2010 and they had several hundred lists that started with numerals that I wanted to run my queries against.
To solve just run the REST query without the list name and it will list all the lists and their collection hrefs and atom:titles. My issue was that some have capital C’s then underscores others have lower case c’s then underscores – yeah ‘Friendly names’ pfft!
so, we just applied the August 2016 CU (our last one was Nov 2015)to our stage and uat enviroments and it appears the listdata.svc prepending of “c_” changed to “C_”. This “broke” one of our Windows Services. I have let them know, but thought I should post this here too.
Great article.
Thanks for this post! Great write up!
thanks for this! I wish there is a portal that contains list of all gotchas!