I got a question on one of my recent posts –Retrieving Multiple SharePoint Managed Metadata Columns via REST – from Chris Parker (@ChrispyBites) about whether the same technique would work in SharePoint 2013. I wanted to know the answer, so I borrowed Julie’s SharePoint 2013 VM and gave it a whirl. It was a little odd, so I figured I’d document what I saw here.
Using the trusty /_vti_pvt/service.cnf endpoint (See Christophe Humbert’s [@pathtosharepoint] post How to get your Office 365 version number – it works on premises, too), I found that Julie’s VM is running this version:
vti_encoding:SR|utf8-nl vti_extenderversion:SR|15.0.0.4797
The REST APIs were rolled out and enhanced over time to SharePoint 2013, so check your version before you take anything I say here as “fact”.
I created a new Site Collection and added a simple Custom List with two Managed Metadata columns: Tax1 and Tax2. Julie already had some Term Sets set up, so I simply pointed at them for testing.
I did a REST call in the browser to see what I could see. Note that I said “in the browser”. Before I put a new REST call I need to think through in my code, I’ll often just fiddle with it in the browser. The use the free XML Tree extension in Chrome so I can make sense of the XML I get back. This only works for GETs, but that’s the most common thing we usually do.
/_api/web/lists/getbytitle('Taxonomy%20Test')/items
I saw that my columns existed, but they had weird InternalNames:
- Tax1 = OData__x0054_ax1
- Tax2 = OData__x0054_ax2
Once I knew the weird column names, I could do this:
/_api/web/lists/getbytitle('Taxonomy%20Test')/items?$select=OData__x0054_ax1,OData__x0054_ax2
Who would have guessed at those column names???
This REST call gave me the data I expected, albeit with the weird column names:
<m:properties> <d:OData__x0054_ax1 m:type="SP.Taxonomy.TaxonomyFieldValue"> <d:Label>1</d:Label> <d:TermGuid>beba4549-fdce-4229-9fb9-fd32428cccb8</d:TermGuid> <d:WssId m:type="Edm.Int32">1</d:WssId> </d:OData__x0054_ax1> <d:OData__x0054_ax2 m:type="SP.Taxonomy.TaxonomyFieldValue"> <d:Label>2</d:Label> <d:TermGuid>095b8a7b-6578-4d97-8604-dac930e85e50</d:TermGuid> <d:WssId m:type="Edm.Int32">2</d:WssId> </d:OData__x0054_ax2> </m:properties>
Still sort of worthless, just like in SharePoint Online. Adding in the
TaxCatchAllcolumn with
$expand:
/_api/web/lists/getbytitle('Taxonomy%20Test')/items?$select=OData__x0054_ax1,OData__x0054_ax2,TaxCatchAll/ID,TaxCatchAll/Term&$expand=TaxCatchAll
got me to a much more useful place, just as in my prior post.
<entry> <id>d70660e1-70d6-4ad7-9f1c-443e8fd70778</id> <category term="SP.Data.TaxonomyHiddenListListItem" scheme="http://ift.tt/1aFoa69" /> <title/> <updated>2017-07-07T14:49:55Z</updated> <author> <name/> </author> <content type="application/xml"> <m:properties> <d:ID m:type="Edm.Int32">2</d:ID> <d:Term>Vendor A</d:Term> </m:properties> </content> </entry> <entry> <id>59d3588a-dbb3-4a8e-9705-9e14af5ab57c</id> <category term="SP.Data.TaxonomyHiddenListListItem" scheme="http://ift.tt/1aFoa69" /> <title/> <updated>2017-07-07T14:49:55Z</updated> <author> <name/> </author> <content type="application/xml"> <m:properties> <d:ID m:type="Edm.Int32">1</d:ID> <d:Term>Hedged Equity</d:Term> </m:properties> </content> </entry>
So yes, the trick works in SharePoint 2013, but you may need to make some adjustments. Have a nice REST!
by Marc D Anderson via Marc D Anderson's Blog
No comments:
Post a Comment