@@ -25,12 +25,16 @@ The following REST commands are available for working with site themes:
25
25
* __ AddTenantTheme__ &ndash ; create a new theme; similar to the Add-SPOTheme SharePoint cmdlet
26
26
* __ DeleteTenantTheme__ &ndash ; remove a theme from the tenant store; similar to the Remove-SPOTheme PowerShell cmdlet
27
27
* __ GetTenantThemingOptions__ &ndash ; read theme settings
28
+ * __ ApplyTheme__ &ndash ; apply tenant theme to site
29
+ * __ UpdateTenantTheme__ &ndash ; updates tenant theme definition
28
30
29
31
The URL for theme management REST commands is based on _ api/thememanager. For example, the following are the endpoints for the commands:
30
32
31
33
* ` http://<site url>/_api/thememanager/AddTenantTheme `
32
34
* ` http://<site url>/_api/thememanager/DeleteTenantTheme `
33
35
* ` http://<site url>/_api/thememanager/GetTenantThemingOptions `
36
+ * ` http://<site url>/_api/thememanager/ApplyTheme `
37
+ * ` http://<site url>/_api/thememanager/UpdateTenantTheme `
34
38
35
39
## AddTenantTheme
36
40
@@ -141,6 +145,111 @@ function RestRequest(url,params) {
141
145
RestRequest (" /_api/thememanager/GetTenantThemingOptions" );
142
146
```
143
147
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
+
144
253
## See also
145
254
146
255
* [ SharePoint site theming overview] ( sharepoint-site-theming-overview.md )
0 commit comments