SharePoint itself provides a REST API for each site you create. It is such wonderful thing to help the developers manipulate maximum areas of SharePoint like accessing lists, settings, users, user groups, navigation, etc. through the application that you built.
Please refer to the REST API reference and samples from Microsoft Office Dev Center to get into the details of the possibilities through REST API.
Since there are 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 web service methodology (until Microsoft deprecated it).
Let’s see the workaround to use SharePoint’s old web service 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.
Step 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
The 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 these SspId and TermSetId, we need to make a SOAP call to invoke SharePoint web service to get the Term Set Data. 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.
The post body will look like below. Replace the highlighted values with respective ids.
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>
- <sspIds><sspId>{SSPID}</sspId></sspIds>
- </sharedServiceIds>
- <termSetIds>
- <termSetIds><termSetId>{TERMSETID}</termSetId></termSetIds>
- </termSetIds>
- <lcid>1033</lcid>
- <clientTimeStamps><dateTimes><dateTime>1900-01-01T00:00:00</dateTime></dateTimes></clientTimeStamps>
- <clientVersions><versions><version>0</version></versions></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>
- <Container>
- <TermStore>
- <TS a9="8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f" a17="true" a11="" a16="true" a12="Department" a68="" />
- <T a9="7722fca2-757b-4428-b306-36138c756ca6" a21="false" a61="0">
- <LS>
- <TL a32="HR" a31="true" />
- </LS>
- <DS />
- <TMS>
- <TM a24="8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f" a12="Department" a40="" a17="true" a67="" a45="7722fca2-757b-4428-b306-36138c756ca6" />
- </TMS>
- </T>
- <T a9="27ca61aa-6215-493f-a8a6-3a35ed19ed51" a21="false" a61="0">
- <LS>
- <TL a32="Product Engineering" a31="true" />
- </LS>
- <DS />
- <TMS>
- <TM a24="8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f" a12="Department" a40="" a17="true" a67="" a45="27ca61aa-6215-493f-a8a6-3a35ed19ed51" />
- </TMS>
- </T>
- <T a9="e0ab7f9e-3f1f-484e-a5aa-165b7eacd6f2" a21="false" a61="0">
- <LS>
- <TL a32="Creative Head" a31="true" />
- </LS>
- <DS />
- <TMS>
- <TM a24="8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f" a12="Department" a40="" a17="true" a67="" a45="e0ab7f9e-3f1f-484e-a5aa-165b7eacd6f2" />
- </TMS>
- </T>
- </TermStore>
- </Container>
- </GetTermSetsResult>
- <serverTermSetTimeStampXml><Container><Node Time="636627502984900000" Version="1" TermId="8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f" /></Container></serverTermSetTimeStampXml>
- </GetTermSetsResponse>
- </soap:Body>
- </soap:Envelope>