If you’re working with SharePoint and managing metadata, you’ve likely encountered the Term Store. This centralized taxonomy service allows organizations to maintain structured data, making content classification, search, and governance more efficient. However, updating Term Store values programmatically can be tricky if you’re not familiar with the right approaches.
Let’s explore how to update Term Store values using four methods:
- SharePoint REST API
- MS Graph API
- Pure JavaScript
- PnPjs (best practice approach)
What is the SharePoint Term Store?
The Term Store is a feature within SharePoint’s Managed Metadata Service (MMS) that allows users to create, manage, and apply metadata across SharePoint sites. It provides hierarchical structures for tagging content consistently, improving searchability and compliance.
Why Do We Need It?
- Consistency: The Term Store ensures that metadata remains uniform across different SharePoint sites, libraries, and lists. This is crucial for maintaining a standardized way of categorizing and retrieving information.
- Better Search & Filtering: Properly structured metadata enhances SharePoint search capabilities, making it easier for users to find relevant documents and items.
- Governance & Compliance: Organizations with strict regulatory requirements can enforce metadata rules through Term Store management, ensuring compliance with policies.
- Content Organization: Without a structured taxonomy, managing large amounts of content becomes chaotic. The Term Store provides a well-defined hierarchy, making information retrieval seamless.
Who Uses It?
- IT Administrators: They use it to configure and maintain a standardized metadata structure across an organization.
- Developers: Automating Term Store operations using APIs allows developers to create, update, and maintain term sets programmatically.
- Business Users: Content creators and managers use terms to tag documents, making it easier to classify and find relevant content.
- Information Architects: These professionals design the taxonomy that governs how metadata is structured within an organization.
What Applications Use It?
- SharePoint Online & On-Premises: The Term Store is natively integrated with SharePoint for metadata management.
- Microsoft Teams: Tags in Teams can be structured using Term Store-managed metadata.
- Power Platform (Power Automate and PowerApps): Many automation and business process solutions rely on structured metadata for workflows and app development.
- Microsoft Viva Topics: AI-powered topic management in Microsoft Viva utilizes metadata and structured taxonomies.
Approaches to Updating Term Store Values
1. Using SharePoint REST API
SharePoint provides REST API endpoints to interact with the Term Store. This approach is useful if you’re working with SharePoint Online directly without additional services like Microsoft Graph or PnPjs.
Endpoint:
/_api/v2.1/termStore/groups/{groupId}/sets/{setId}/terms/{termId}
Sample Implementation
fetch("https://yourtenant.sharepoint.com/sites/yoursite/_api/v2.1/termStore/groups/{groupId}/sets/{setId}/terms/{termId}", {
method: "PATCH",
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": "Bearer your_access_token"
},
body: JSON.stringify({
"labels": [{ "name": "Updated Term Name", "languageTag": "en-US" }]
})
})
.then(response => response.json())
.then(data => console.log("Updated Successfully", data))
.catch(error => console.error("Error updating term store", error));
Pros and Cons
- ✅ Directly interacts with SharePoint APIs, giving full control over Term Store operations.
- ✅ No external dependencies are required.
- ❌ Requires authentication setup (OAuth or MSAL) and permissions handling.
- ❌ More manual work compared to using libraries like PnPjs.
2. Using Microsoft Graph API
Microsoft Graph provides a modern and unified way to interact with various Microsoft 365 services, including the Term Store.
Endpoint:
https://graph.microsoft.com/v1.0/sites/{siteId}/termStore/sets/{setId}/terms/{termId}
Sample Implementation
fetch("https://graph.microsoft.com/v1.0/sites/{siteId}/termStore/sets/{setId}/terms/{termId}", {
method: "PATCH",
headers: {
"Authorization": "Bearer your_access_token",
"Content-Type": "application/json"
},
body: JSON.stringify({
"labels": [{ "name": "Updated Term Name", "languageTag": "en-US" }]
})
})
.then(response => response.json())
.then(data => console.log("Updated Successfully", data))
.catch(error => console.error("Error updating term store", error));
Pros and Cons
- ✅ Provides a more modern API structure compared to SharePoint REST API.
- ✅ Unified authentication with Microsoft 365 services.
- ❌ Requires Microsoft Graph permissions setup in Azure AD.
- ❌ Not always the fastest approach due to Graph API rate limits.
3. Using Pure JavaScript
This approach is similar to using the SharePoint REST API but requires manually handling API requests and authentication.
Sample Implementation
async function updateTerm(termId, groupId, setId) {
const requestUrl = `https://yourtenant.sharepoint.com/sites/yoursite/_api/v2.1/termStore/groups/${groupId}/sets/${setId}/terms/${termId}`;
const headers = new Headers({
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": "Bearer your_access_token"
});
const body = JSON.stringify({
"labels": [{ "name": "Updated Term Name", "languageTag": "en-US" }]
});
try {
let response = await fetch(requestUrl, { method: "PATCH", headers, body });
let data = await response.json();
console.log("Updated Successfully", data);
} catch (error) {
console.error("Error updating term store", error);
}
}
Pros and Cons
- ✅ No dependencies.
- ✅ Flexible and customizable.
- ❌ Requires manual handling of authentication and API structure.
Comparison of Implementations
Approach | Ease of Use | Dependencies | Best for |
---|---|---|---|
REST API | Medium | No external dependencies | API-first implementations |
MS Graph API | Medium | Requires Graph permissions | Unified Microsoft 365 management |
Pure JavaScript | Hard | No dependencies | Custom implementations |
PnPjs | Easy | Requires PnPjs library | Modern, scalable projects |
Updating Term Store values programmatically can be done in multiple ways, but the best approach depends on your project’s needs. Microsoft Graph API is useful for unified Microsoft 365 management, whereas PnPjs simplifies interactions with SharePoint. Understanding the pros and cons of each method will help you choose the best one for your use case.
Happy coding! 🚀
AD Groups Authentication Automation Backup Compliance Content Type CSS DocumentSet Flows Google GULP Javascript Levels Limitations Metadata MFA Microsoft Node NodeJs O365 OneDrive Permissions PnP PnPJS Policy Power Automate PowerAutomate PowerShell React ReactJs Rest API Rest Endpoint Send an HTTP Request to SharePoint SharePoint SharePoint Groups SharePoint List SharePoint Modern SharePoint Online SPFX SPO Sync Tags Teams Termstore Versioning