Retrieving the Content Type in a REST Call in SharePoint 2013 On Premises
I’m working in a SharePoint 2013 on premises installation, and I needed to get the ContentType back from a REST call. Content Type is often the most important piece of metadata in a list or library, with the detailed metadata for the Content Type coming in as secondary. It certainly matters which Content Type you have if you’re building custom UIs like I am.
On SharePoint Online, this works:
/_api/web/lists/getbytitle('MyList')/items? $select=ContentType/Name&$expand=ContentType
But on premises, it doesn’t. Nothing comes back for the ContentType at all.
I found this great little tip from eko buried in a StackExchange comment – with no up votes. Up votes matter, people, so make sure you use them.
Simply add ContentTypeId to the $select and you’re in business:
/_api/web/lists/getbytitle('MyList')/items? $select=ContentTypeId,ContentType/Name&$expand=ContentType
We shouldn’t need to do this sort of workaround, but it’s great when we can!
Upvoted
I dont think it is possible to use “ContentType/Name” as a filter in the oData. Is there any work around to use that as part of the filter?. I am talking about on-prem.
@SANDEEP:
On premi s a little behind, so yuo will run into this sort of thing. I’ve used the ContentType GUID in the past and it seems to work.
M.