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:
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
- Endpoint : https:
- Method : GET
- Headers : {"Content-Type": "application/json",
- "Authorization": "Bearer <Bearer Token>"}
Output
- {
- "@odata.context": "https://testinglala.sharepoint.com/_api/v2.1/$metadata#termStores('root')/groups",
- "value": [
- {
- "id": "f27b8ac4-c866-4f3c-8d12-9848809e983a",
- "description": "From Code",
- "name": "New Group",
- "createdDateTime": "2020-05-16T07:54:11.1Z",
- "lastModifiedDateTime": "2020-05-16T07:54:11.11Z",
- "type": "RegularGroup"
- },
- {
- "id": "122d92ab-d7a8-479f-9888-8d4421f8218f",
- "description": "",
- "name": "People",
- "createdDateTime": "2019-11-05T02:32:07.853Z",
- "lastModifiedDateTime": "2020-05-16T06:48:46.76Z",
- "type": "RegularGroup"
- },
- {
- "id": "d87b6a37-c801-4a36-9046-6296d4779c87",
- "description": "",
- "name": "Search Dictionaries",
- "createdDateTime": "2020-04-21T11:49:57.587Z",
- "lastModifiedDateTime": "2020-05-16T06:48:41.65Z",
- "type": "RegularGroup"
- }
- ]
- }
Create
- Endpoint : https:
- Method : POST
- Headers : {"Content-Type": "application/json",
- "Authorization": "Bearer <Bearer Token>"}
- Body : {"name":"FromRESTAPI", "description":"Description For FromRESTAPI"}
Update
- Endpoint : https:bea867f8-9348-4ea4-976e-21f79f4f3212
- Method : PATCH
- Headers : {"Content-Type": "application/json",
- "Authorization": "Bearer <Bearer Token>"}
- Body : {"name":"FromRESTAPI", "description":"Updated Description For FromRESTAPI"}
Delete
- Endpoint : https:
- Method : DELETE
- Headers : {"Content-Type": "application/json",
- "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
- Endpoint : https:
- Method : GET
- Headers : {"Content-Type": "application/json",
- "Authorization": "Bearer <Bearer Token>"}
Output
- {
- "@odata.context": "https://testinglala.sharepoint.com/_api/v2.1/$metadata#termStores('root')/groups('122d92ab-d7a8-479f-9888-8d4421f8218f')/sets",
- "value": [
- {
- "id": "8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f",
- "description": "",
- "childrenCount": 1,
- "createdDateTime": "2019-11-05T02:32:07.89Z",
- "isOpen": true,
- "groupId": "122d92ab-d7a8-479f-9888-8d4421f8218f",
- "localizedNames": [
- {
- "name": "Department",
- "languageTag": "en-US"
- }
- ]
- },
- {
- "id": "386095d1-c68d-4c6d-b587-48ddaf1aecc9",
- "description": "",
- "childrenCount": 2,
- "createdDateTime": "2019-11-05T02:32:07.887Z",
- "isOpen": true,
- "groupId": "122d92ab-d7a8-479f-9888-8d4421f8218f",
- "localizedNames": [
- {
- "name": "Job Title",
- "languageTag": "en-US"
- }
- ]
- },
- {
- "id": "b49f64b3-4722-4336-9a5c-56c326b344d4",
- "description": "",
- "childrenCount": 0,
- "createdDateTime": "2019-11-05T02:32:07.89Z",
- "isOpen": true,
- "groupId": "122d92ab-d7a8-479f-9888-8d4421f8218f",
- "localizedNames": [
- {
- "name": "Location",
- "languageTag": "en-US"
- }
- ]
- }
- ]
- }
Create
- Endpoint : https:
- Method : POST
- Headers : {"Content-Type": "application/json",
- "Authorization": "Bearer <Bearer Token>"}
- Body : {"description": "","localizedNames": [{"name": "OperationLevel","languageTag": "en-US"}]}
Update
- Endpoint : https:
- Method : PATCH
- Headers : {"Content-Type": "application/json",
- "Authorization": "Bearer <Bearer Token>"}
- Body : {"description": "Added description","localizedNames": [{"name": "OperationLevelUpdated","languageTag": "en-US"}]}
Delete
- Endpoint : https:
- Method : DELETE
- Headers : {"Content-Type": "application/json",
- "Authorization": "Bearer <Bearer Token>"}
Terms
Read
- Endpoint : https:
- Method : GET
- Headers : {"Content-Type": "application/json",
- "Authorization": "Bearer <Bearer Token>"}
Output
- {
- "@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",
- "value": [
- {
- "id": "4ac622b1-330b-4aaa-a4fc-6946260948b7",
- "isDeprecated": false,
- "childrenCount": 0,
- "createdDateTime": "2020-04-05T04:34:48.203Z",
- "lastModifiedDateTime": "2020-05-16T02:52:39.5Z",
- "labels": [
- {
- "name": "Digital",
- "isDefault": true,
- "languageTag": "en-US"
- }
- ],
- "descriptions": [
- {
- "description": "Digital Innovation",
- "languageTag": "en-US"
- }
- ],
- "isAvailableForTagging": [
- {
- "setId": "8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f",
- "isAvailable": true
- }
- ]
- }
- ]
- }
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"
- Endpoint : https:
- Method : POST
- Headers : {"Content-Type": "application/json",
- "Authorization": "Bearer <Bearer Token>"}
- Body : {"labels": [{"name": "AI","isDefault":true,"languageTag": "en-US"}],"descriptions": [{"description": "AI Innovation","languageTag": "en-US"}]}
Update
- Endpoint : https:
- Method : PATCH
- Headers : {"Content-Type": "application/json",
- "Authorization": "Bearer <Bearer Token>"}
- Body : {"labels": [{"name": "AI Updated","isDefault":true,"languageTag": "en-US"}],"descriptions": [{"description": "AI Innovation Updated","languageTag": "en-US"}]}
- Endpoint : https:
- Method : DELETE
- Headers : {"Content-Type": "application/json",
- "Authorization": "Bearer <Bearer Token>"}