Written by

Jayakumar Balasubramaniam

Share

  

Category

see all categories
intranet as a service

How to read SharePoint TermStore (Managed Metadata) using REST API

SharePoint itself provides REST API for each site you create. It is such wonderful thing to help the developers to manipulate maximum areas of the SharePoint like accessing lists, settings, users, user groups, navigation, etc. through the application that you built.

Please refer the REST API reference and samples from Microsoft Office Dev Centre to get into details of the possibilities through REST API. In my previous blog I have explained how to read termstore in SharePoint Framework.

Since there is some restrictions and threshold limits are always there in SharePoint to improve performance we cannot access some areas of SharePoint through Rest API. But still it is possible to access it by using SharePoint’s old webservice methodology (until Microsoft Deprecate it).

Let’s see the workaround to use SharePoint’s old webservice methodology to get the TermStore Data with step by step instructions.

Step 1:

            Create a Managed Metadata field in any List and map the respective term set item with it like below,

Create a Managed Metadata fieldStep 2:

            Now using REST API get the field information of the Managed Metadata column which you have created in the previous step so we could be able to get the SspId and TermSetId in the field xml of the list

Rest API Url :

{HostUrl}/_api/Web/Lists/getbytitle('{ListName}')/fields/getbytitle('{FieldInternalName}')?$select=SspId,TermSetId

Output will be like below: (SspId and TermSetId were highlighted)

{

   "SspId": "905b427f-399b-4815-bdb0-d9f8a6f829eb",

    "TermSetId": "8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f",

}

Note: Since we need only these two values I have queried only those fields in ODATA query  $select=SspId,TermSetId in above url, if you want to read all field information you can use ,*

Step 3:

Now by passing this SspId and TermSetId we need to make a SOAP call to invoke SharePoint webservice to get the Term Set Data

Leaderboard_CDR

Here we are going to post the input data in xml format so please mention the content-type in the headers as “text/xml” along with the authorization headers

Post Body will look like below, replace the highlighted values with respective id’s

WebService URL: {HostUrl}/_vti_bin/taxonomyclientservice.asmx?op=GetTermSets

Request Body:

<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'  xmlns:xsd='http://www.w3.org/2001/XMLSchema'>

  <soap:Body>

    <GetTermSets xmlns='http://schemas.microsoft.com/sharepoint/taxonomy/soap/'>

      <sharedServiceIds>

        &lt;sspIds&gt;&lt;sspId&gt;{SSPID}&lt;/sspId&gt;&lt;/sspIds&gt;

      </sharedServiceIds>

      <termSetIds>

        &lt;termSetIds&gt;&lt;termSetId&gt;{TERMSETID}&lt;/termSetId&gt;&lt;/termSetIds&gt;

      </termSetIds>

      <lcid>1033</lcid>

      <clientTimeStamps>&lt;dateTimes&gt;&lt;dateTime&gt;1900-01-01T00:00:00&lt;/dateTime&gt;&lt;/dateTimes&gt;</clientTimeStamps>

      <clientVersions>&lt;versions&gt;&lt;version&gt;0&lt;/version&gt;&lt;/versions&gt;</clientVersions>

    </GetTermSets>

  </soap:Body>

</soap:Envelope>

Finally, we will get the expected output in xml format and parse the xml to deserialize API response, sample output format is mentioned below.

<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <soap:Body>

    <GetTermSetsResponse xmlns="http://schemas.microsoft.com/sharepoint/taxonomy/soap/">

      <GetTermSetsResult>

        &lt;Container&gt;

        &lt;TermStore&gt;

        &lt;TS a9=&quot;8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f&quot; a17=&quot;true&quot; a11=&quot;&quot; a16=&quot;true&quot; a12=&quot;Department&quot; a68=&quot;&quot; /&gt;

        &lt;T a9=&quot;7722fca2-757b-4428-b306-36138c756ca6&quot; a21=&quot;false&quot; a61=&quot;0&quot;&gt;

        &lt;LS&gt;

        &lt;TL a32=&quot;HR&quot; a31=&quot;true&quot; /&gt;

        &lt;/LS&gt;

        &lt;DS /&gt;

        &lt;TMS&gt;

        &lt;TM a24=&quot;8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f&quot; a12=&quot;Department&quot; a40=&quot;&quot; a17=&quot;true&quot; a67=&quot;&quot; a45=&quot;7722fca2-757b-4428-b306-36138c756ca6&quot; /&gt;

        &lt;/TMS&gt;

        &lt;/T&gt;

        &lt;T a9=&quot;27ca61aa-6215-493f-a8a6-3a35ed19ed51&quot; a21=&quot;false&quot; a61=&quot;0&quot;&gt;

        &lt;LS&gt;

        &lt;TL a32=&quot;Product Engineering&quot; a31=&quot;true&quot; /&gt;

        &lt;/LS&gt;

        &lt;DS /&gt;

        &lt;TMS&gt;

        &lt;TM a24=&quot;8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f&quot; a12=&quot;Department&quot; a40=&quot;&quot; a17=&quot;true&quot; a67=&quot;&quot; a45=&quot;27ca61aa-6215-493f-a8a6-3a35ed19ed51&quot; /&gt;

        &lt;/TMS&gt;

        &lt;/T&gt;

        &lt;T a9=&quot;e0ab7f9e-3f1f-484e-a5aa-165b7eacd6f2&quot; a21=&quot;false&quot; a61=&quot;0&quot;&gt;

        &lt;LS&gt;

        &lt;TL a32=&quot;Creative Head&quot; a31=&quot;true&quot; /&gt;

        &lt;/LS&gt;

        &lt;DS /&gt;

        &lt;TMS&gt;

        &lt;TM a24=&quot;8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f&quot; a12=&quot;Department&quot; a40=&quot;&quot; a17=&quot;true&quot; a67=&quot;&quot; a45=&quot;e0ab7f9e-3f1f-484e-a5aa-165b7eacd6f2&quot; /&gt;

        &lt;/TMS&gt;

        &lt;/T&gt;

        &lt;/TermStore&gt;

        &lt;/Container&gt;

      </GetTermSetsResult>

      <serverTermSetTimeStampXml>&lt;Container&gt;&lt;Node Time="636627502984900000" Version="1" TermId="8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f" /&gt;&lt;/Container&gt;</serverTermSetTimeStampXml>

    </GetTermSetsResponse>

  </soap:Body>

</soap:Envelope>

Please let me know if this has helped you. I would be happy if it did. Feel free to reach out to me if you need any specific assistance. I will try to help you out.

Jayakumar Balasubramaniam

Written by Jayakumar Balasubramaniam

A technology evangelist working on Microsoft 365, SharePoint & Azure. Gets my hands dirty with latest and greatest of SharePoint, Azure & front-end frameworks. Currently working with “Hubfly – A unified digital workplace” as a Product Engineer. Getting in to the depth of the domain & technology, with my eyes for perfection, ensures that the product releases go right every time.