Skip to content

Commit 6e9e238

Browse files
authored
Add endpoints: UpdateTenantTheme and ApplyTheme
Add documentation about 2 endpoints with sample code '/_api/thememanager/UpdateTenantTheme' and '/_api/thememanager/ApplyTheme'
1 parent 952e1e5 commit 6e9e238

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

docs/declarative-customization/site-theming/sharepoint-site-theming-rest-api.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ The following REST commands are available for working with site themes:
2525
* __AddTenantTheme__ – create a new theme; similar to the Add-SPOTheme SharePoint cmdlet
2626
* __DeleteTenantTheme__ – remove a theme from the tenant store; similar to the Remove-SPOTheme PowerShell cmdlet
2727
* __GetTenantThemingOptions__ – read theme settings
28+
* __ApplyTheme__ – apply tenant theme to site
29+
* __UpdateTenantTheme__ – updates tenant theme definition
2830

2931
The URL for theme management REST commands is based on _api/thememanager. For example, the following are the endpoints for the commands:
3032

3133
* `http://<site url>/_api/thememanager/AddTenantTheme`
3234
* `http://<site url>/_api/thememanager/DeleteTenantTheme`
3335
* `http://<site url>/_api/thememanager/GetTenantThemingOptions`
36+
* `http://<site url>/_api/thememanager/ApplyTheme`
37+
* `http://<site url>/_api/thememanager/UpdateTenantTheme`
3438

3539
## AddTenantTheme
3640

@@ -141,6 +145,111 @@ function RestRequest(url,params) {
141145
RestRequest("/_api/thememanager/GetTenantThemingOptions");
142146
```
143147

148+
## ApplyTheme
149+
150+
The following JavaScript sample code shows how to apply theme to the site.
151+
152+
```javascript
153+
function RestRequest(url,params) {
154+
var req = new XMLHttpRequest();
155+
req.onreadystatechange = function ()
156+
{
157+
if (req.readyState != 4) // Loaded
158+
return;
159+
console.log(req.responseText);
160+
};
161+
req.open("POST",url,true);
162+
req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
163+
req.setRequestHeader("ACCEPT", "application/json; odata.metadata=minimal");
164+
req.setRequestHeader("x-requestdigest", _spPageContextInfo.formDigestValue);
165+
req.setRequestHeader("ODATA-VERSION","4.0");
166+
req.send(params ? JSON.stringify(params) : void 0);
167+
}
168+
var pal = {
169+
"palette" : {
170+
"themePrimary": "#1BF242",
171+
"themeLighterAlt": "#0d0b00",
172+
"themeLighter": "#0b35bc",
173+
"themeLight": "#322d00",
174+
"themeTertiary": "#6a5f00",
175+
"themeSecondary": "#1B22F2",
176+
"themeDarkAlt": "#ffe817",
177+
"themeDark": "#ffed4b",
178+
"themeDarker": "#fff171",
179+
"neutralLighterAlt": "#252525",
180+
"neutralLighter": "#282828",
181+
"neutralLight": "#313131",
182+
"neutralQuaternaryAlt": "#3f3f3f",
183+
"neutralQuaternary": "#484848",
184+
"neutralTertiaryAlt": "#4f4f4f",
185+
"neutralTertiary": "#c8c8c8",
186+
"neutralSecondaryAlt": "#d0d0d0",
187+
"neutralSecondary": "#dadada",
188+
"neutralPrimary": "#ffffff",
189+
"neutralDark": "#eaeaea",
190+
"black": "#f8f8f8",
191+
"white": "#1f1f1f",
192+
"primaryBackground": "#1f1f1f",
193+
"primaryText": "#ffffff",
194+
"error": "#ff5f5f"
195+
}
196+
}
197+
RestRequest("/_api/thememanager/ApplyTheme", {name:"Sounders Rave Green", themeJson: JSON.stringify(pal)});
198+
```
199+
200+
## UpdateTenantTheme
201+
202+
The following JavaScript sample code shows how to update tenant theme.
203+
204+
```javascript
205+
function RestRequest(url,params) {
206+
var req = new XMLHttpRequest();
207+
req.onreadystatechange = function ()
208+
{
209+
if (req.readyState != 4) // Loaded
210+
return;
211+
console.log(req.responseText);
212+
};
213+
req.open("POST",url,true);
214+
req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
215+
req.setRequestHeader("ACCEPT", "application/json; odata.metadata=minimal");
216+
req.setRequestHeader("x-requestdigest", _spPageContextInfo.formDigestValue);
217+
req.setRequestHeader("ODATA-VERSION","4.0");
218+
req.send(params ? JSON.stringify(params) : void 0);
219+
}
220+
var pal = {
221+
"palette" : {
222+
"themePrimary": "#008cff",
223+
"themeLighterAlt": "#f5faff",
224+
"themeLighter": "#d6edff",
225+
"themeLight": "#b3ddff",
226+
"themeTertiary": "#66baff",
227+
"themeSecondary": "#1f9aff",
228+
"themeDarkAlt": "#007ee6",
229+
"themeDark": "#006bc2",
230+
"themeDarker": "#004f8f",
231+
"neutralLighterAlt": "#f8f8f8",
232+
"neutralLighter": "#f4f4f4",
233+
"neutralLight": "#eaeaea",
234+
"neutralQuaternaryAlt": "#dadada",
235+
"neutralQuaternary": "#d0d0d0",
236+
"neutralTertiaryAlt": "#c8c8c8",
237+
"neutralTertiary": "#595959",
238+
"neutralSecondary": "#373737",
239+
"neutralPrimaryAlt": "#2f2f2f",
240+
"neutralPrimary": "#000000",
241+
"neutralDark": "#151515",
242+
"black": "#0b0b0b",
243+
"white": "#ffffff",
244+
"primaryBackground": "#ffffff",
245+
"primaryText": "#000000",
246+
"disabledBackground": "#f4f4f4",
247+
"disabledText": "#c8c8c8"
248+
}
249+
}
250+
RestRequest("/_api/thememanager/UpdateTenantTheme", {name:"Sounders Rave Green", themeJson: JSON.stringify(pal)});
251+
```
252+
144253
## See also
145254

146255
* [SharePoint site theming overview](sharepoint-site-theming-overview.md)

0 commit comments

Comments
 (0)