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!
by Marc D Anderson via Marc D Anderson's Blog
No comments:
Post a Comment