SharePoint Managed Metadata Services Rest API

Overview

 
This blog will help us understand how to use Managed Metadata Services (MMS) REST API in an SPFx solution and what endpoints are available in MMS REST API

In the latest release of SharePoint Online, REST APIs Microsoft Team came up with REST APIs for MMS. They came up with below entities in TermStore which can be manipulated:
  1. Groups
  2. Term Sets
  3. Terms 
Let's see all the CRUD Operations available for the entities.
 

Groups

 
We can do all the CRUD operations on Groups. For all the below operations, we require a Bearer Token. To fetch this bearer token, please follow my below blog.
 
For SPFx sample Code, use this link.
 
Read
  1. Endpoint : https://testinglala.sharepoint.com/_api/v2.1/termStore/groups  
  2. Method : GET  
  3. Headers : {"Content-Type": "application/json",
  4.            "Authorization": "Bearer <Bearer Token>"}
Output
  1. {  
  2.     "@odata.context""https://testinglala.sharepoint.com/_api/v2.1/$metadata#termStores('root')/groups",  
  3.     "value": [  
  4.         {  
  5.             "id""f27b8ac4-c866-4f3c-8d12-9848809e983a",  
  6.             "description""From Code",  
  7.             "name""New Group",  
  8.             "createdDateTime""2020-05-16T07:54:11.1Z",  
  9.             "lastModifiedDateTime""2020-05-16T07:54:11.11Z",  
  10.             "type""RegularGroup"  
  11.         },  
  12.         {  
  13.             "id""122d92ab-d7a8-479f-9888-8d4421f8218f",  
  14.             "description""",  
  15.             "name""People",  
  16.             "createdDateTime""2019-11-05T02:32:07.853Z",  
  17.             "lastModifiedDateTime""2020-05-16T06:48:46.76Z",  
  18.             "type""RegularGroup"  
  19.         },  
  20.         {  
  21.             "id""d87b6a37-c801-4a36-9046-6296d4779c87",  
  22.             "description""",  
  23.             "name""Search Dictionaries",  
  24.             "createdDateTime""2020-04-21T11:49:57.587Z",  
  25.             "lastModifiedDateTime""2020-05-16T06:48:41.65Z",  
  26.             "type""RegularGroup"  
  27.         }  
  28.     ]  
  29. }  
Create
  1. Endpoint : https://testinglala.sharepoint.com/_api/v2.1/termStore/groups    
  2. Method : POST    
  3. Headers : {"Content-Type""application/json",  
  4.            "Authorization""Bearer <Bearer Token>"}
  5. Body : {"name":"FromRESTAPI", "description":"Description For FromRESTAPI"}  
 
Update
  1. Endpoint : https://testinglala.sharepoint.com/_api/v2.1/termStore/groups/bea867f8-9348-4ea4-976e-21f79f4f3212   
  2. Method : PATCH      
  3. Headers : {"Content-Type""application/json",    
  4.            "Authorization""Bearer <Bearer Token>"}  
  5. Body : {"name":"FromRESTAPI", "description":"Updated Description For FromRESTAPI"}    
 
Delete
  1. Endpoint : https://testinglala.sharepoint.com/_api/v2.1/termStore/groups/bea867f8-9348-4ea4-976e-21f79f4f3212     
  2. Method : DELETE       
  3. Headers : {"Content-Type""application/json",      
  4.            "Authorization""Bearer <Bearer Token>"}    
Please note that the response code is 204 when successfully executed.
 

Term Sets

 
We can do all the CRUD operations on Term Sets. Please note that for example purposes, we are using People Group which can be viewed in the first image in the Groups REST API.
 
Read
  1. Endpoint : https://testinglala.sharepoint.com/_api/v2.1/termStore/groups/122d92ab-d7a8-479f-9888-8d4421f8218f/sets    
  2. Method : GET    
  3. Headers : {"Content-Type""application/json",  
  4.            "Authorization""Bearer <Bearer Token>"}  
Output
  1. {  
  2.     "@odata.context""https://testinglala.sharepoint.com/_api/v2.1/$metadata#termStores('root')/groups('122d92ab-d7a8-479f-9888-8d4421f8218f')/sets",  
  3.     "value": [  
  4.         {  
  5.             "id""8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f",  
  6.             "description""",  
  7.             "childrenCount": 1,  
  8.             "createdDateTime""2019-11-05T02:32:07.89Z",  
  9.             "isOpen"true,  
  10.             "groupId""122d92ab-d7a8-479f-9888-8d4421f8218f",  
  11.             "localizedNames": [  
  12.                 {  
  13.                     "name""Department",  
  14.                     "languageTag""en-US"  
  15.                 }  
  16.             ]  
  17.         },  
  18.         {  
  19.             "id""386095d1-c68d-4c6d-b587-48ddaf1aecc9",  
  20.             "description""",  
  21.             "childrenCount": 2,  
  22.             "createdDateTime""2019-11-05T02:32:07.887Z",  
  23.             "isOpen"true,  
  24.             "groupId""122d92ab-d7a8-479f-9888-8d4421f8218f",  
  25.             "localizedNames": [  
  26.                 {  
  27.                     "name""Job Title",  
  28.                     "languageTag""en-US"  
  29.                 }  
  30.             ]  
  31.         },  
  32.         {  
  33.             "id""b49f64b3-4722-4336-9a5c-56c326b344d4",  
  34.             "description""",  
  35.             "childrenCount": 0,  
  36.             "createdDateTime""2019-11-05T02:32:07.89Z",  
  37.             "isOpen"true,  
  38.             "groupId""122d92ab-d7a8-479f-9888-8d4421f8218f",  
  39.             "localizedNames": [  
  40.                 {  
  41.                     "name""Location",  
  42.                     "languageTag""en-US"  
  43.                 }  
  44.             ]  
  45.         }  
  46.     ]  
  47. }  
Create
  1. Endpoint : https://testinglala.sharepoint.com/_api/v2.1/termStore/groups/122d92ab-d7a8-479f-9888-8d4421f8218f/sets      
  2. Method : POST      
  3. Headers : {"Content-Type""application/json",    
  4.            "Authorization""Bearer <Bearer Token>"}
  5. Body : {"description": "","localizedNames": [{"name": "OperationLevel","languageTag": "en-US"}]}   
 
Update
  1. Endpoint : https://testinglala.sharepoint.com/_api/v2.1/termStore/groups/122d92ab-d7a8-479f-9888-8d4421f8218f/sets/dbc06a0b-7f38-42dc-84a7-0b734f350303          
  2. Method : PATCH         
  3. Headers : {"Content-Type""application/json",        
  4.            "Authorization""Bearer <Bearer Token>"}    
  5. Body : {"description""Added description","localizedNames": [{"name""OperationLevelUpdated","languageTag""en-US"}]}     
Delete
  1. Endpoint : https://testinglala.sharepoint.com/_api/v2.1/termStore/groups/122d92ab-d7a8-479f-9888-8d4421f8218f/sets/dbc06a0b-7f38-42dc-84a7-0b734f350303            
  2. Method : DELETE          
  3. Headers : {"Content-Type""application/json",          
  4.            "Authorization""Bearer <Bearer Token>"}   

Terms

 
Read
  1. Endpoint : https://testinglala.sharepoint.com/_api/v2.1/termStore/groups/122d92ab-d7a8-479f-9888-8d4421f8218f/sets/8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f/terms      
  2. Method : GET      
  3. Headers : {"Content-Type""application/json",    
  4.            "Authorization""Bearer <Bearer Token>"}    
Output
  1. {  
  2.     "@odata.context""https://testinglala.sharepoint.com/_api/v2.1/$metadata#termStores('root')/groups('122d92ab-d7a8-479f-9888-8d4421f8218f')/sets('8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f')/terms",  
  3.     "value": [  
  4.         {  
  5.             "id""4ac622b1-330b-4aaa-a4fc-6946260948b7",  
  6.             "isDeprecated"false,  
  7.             "childrenCount": 0,  
  8.             "createdDateTime""2020-04-05T04:34:48.203Z",  
  9.             "lastModifiedDateTime""2020-05-16T02:52:39.5Z",  
  10.             "labels": [  
  11.                 {  
  12.                     "name""Digital",  
  13.                     "isDefault"true,  
  14.                     "languageTag""en-US"  
  15.                 }  
  16.             ],  
  17.             "descriptions": [  
  18.                 {  
  19.                     "description""Digital Innovation",  
  20.                     "languageTag""en-US"  
  21.                 }  
  22.             ],  
  23.             "isAvailableForTagging": [  
  24.                 {  
  25.                     "setId""8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f",  
  26.                     "isAvailable"true  
  27.                 }  
  28.             ]  
  29.         }  
  30.     ]  
  31. }  
Create
 
Note
The endpoint use in this REST API is different compared to the others here. You can see that "children" is used instead of "terms"
  1. Endpoint : https://testinglala.sharepoint.com/_api/v2.1/termStore/groups/122d92ab-d7a8-479f-9888-8d4421f8218f/sets/8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f/children        
  2. Method : POST        
  3. Headers : {"Content-Type""application/json",      
  4.            "Authorization""Bearer <Bearer Token>"}   
  5. Body : {"labels": [{"name""AI","isDefault":true,"languageTag""en-US"}],"descriptions": [{"description""AI Innovation","languageTag""en-US"}]}  
Update
  1. Endpoint : https://testinglala.sharepoint.com/_api/v2.1/termStore/groups/122d92ab-d7a8-479f-9888-8d4421f8218f/sets/8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f/terms/b8b3e828-cdf7-46b2-889e-f5f797a05aa3          
  2. Method : PATCH          
  3. Headers : {"Content-Type""application/json",        
  4.            "Authorization""Bearer <Bearer Token>"}     
  5. Body : {"labels": [{"name""AI Updated","isDefault":true,"languageTag""en-US"}],"descriptions": [{"description""AI Innovation Updated","languageTag""en-US"}]}   
Delete
  1. Endpoint : https://testinglala.sharepoint.com/_api/v2.1/termStore/groups/122d92ab-d7a8-479f-9888-8d4421f8218f/sets/8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f/terms/b8b3e828-cdf7-46b2-889e-f5f797a05aa3            
  2. Method : DELETE            
  3. Headers : {"Content-Type""application/json",          
  4.            "Authorization""Bearer <Bearer Token>"}