Search…
Feature management
Operations for features management
You can activate and deactivate features on sites and webs using REST API. However, there are a few nuances to know knowing which makes it simple to manage the features.
You should know specific feature definition ID to add or remove it.
Unfortunately, there is no way of getting features list with names and descriptions programmatically. When getting features list on the web or site you receive a list of activated features definition IDs and nothing else.

Getting activated features

1
res, err := sp.Web().Features().Get()
2
if err != nil {
3
log.Fatal(err)
4
}
5
​
6
for _, f := range res {
7
fmt.Printf("%+v\n", f)
8
}
9
​
10
// &{DefinitionID:b77b6484-364e-4356-8c72-1bb55b81c6b3}
11
// &{DefinitionID:a7a2793e-67cd-4dc1-9fd0-43f61581207a}
12
// &{DefinitionID:d5a4ed08-27b9-4142-9804-45dec6fda126}
13
// &{DefinitionID:780ac353-eaf8-4ac2-8c47-536d93c03fd6}
14
// &{DefinitionID:8c6f9096-388d-4eed-96ff-698b3ec46fc4}
15
// ...
Copied!
Luckily, nowadays one almost always deal only with OOTB features, if not probably something is terribly wrong on a project. 😝

Feature activating

1
mds := "87294c72-f260-42f3-a41b-981a2ffce37a"
2
if err := sp.Web().Features().Add(mds, true); err != nil {
3
log.Fatal(err)
4
}
Copied!
The first argument stands for Feature Definition ID, the second one is force mode.

Feature deactivating

1
mds := "87294c72-f260-42f3-a41b-981a2ffce37a"
2
if err := sp.Web().Features().Remove(mds, true); err != nil {
3
log.Fatal(err)
4
}
Copied!
Arguments are identical.
When a feature was not activated before removing it an error message is expected ("Feature is not activated at this scope").
Site level actions are absolutely identical, the only difference is sp.Site() entry point.
Last modified 1yr ago