ListData.svc REST Gotcha in SharePoint 2010 / 2013


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’,

rest-listdatasvc-list

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'”;

rest-listdatasvc-listreq-postman

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;

rest-listdatasvc-microsoft.sharepoint.linq.dataservice.dataservicedatacontext

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;

rest-listdatasvc-microsoft.sharepoint.linq.dataservice-util.getfriendlyname

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;

rest-listdatasvc-listreq-postman-ok

 

Published by

Phil Harding

SharePoint Consultant, Developer, Father, Husband and Climber.

9 thoughts on “ListData.svc REST Gotcha in SharePoint 2010 / 2013

  1. So, from REST call to “/_vti_bin/ListData.svc/” I get internal list names – how can I get friendly name using REST API ?

  2. 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!

  3. 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!

  4. 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.

  5. thanks for this! I wish there is a portal that contains list of all gotchas!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.