Site themes via Rest.

%3CLINGO-SUB%20id%3D%22lingo-sub-298566%22%20slang%3D%22en-US%22%3ESite%20themes%20via%20Rest.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-298566%22%20slang%3D%22en-US%22%3E%3CP%3EI%20tried%20following%20at%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fdeclarative-customization%2Fsite-theming%2Fsharepoint-site-theming-rest-api%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fdeclarative-customization%2Fsite-theming%2Fsharepoint-site-theming-rest-api%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3EI%20keep%20getting%20the%20following%20response%3A%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%26lt%3Bmeta%20charset%3D%22%22utf-8%22%22%20%2F%26gt%3B%3CBR%20%2F%3E%3CTITLE%3EError%3C%2FTITLE%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CPRE%3ECannot%20POST%20%2F_api%2Fthememanager%2FAddTenantTheme%3C%2FPRE%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-298566%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EREST%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EScript%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-299014%22%20slang%3D%22en-US%22%3ERe%3A%20Site%20themes%20via%20Rest.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-299014%22%20slang%3D%22en-US%22%3E%3CP%3ESorry%20I%20apologize%20for%20providing%20the%20wrong%20article.%20I%20meant%20to%20provide%20the%20one%20you%20actually%20shared.%20I%20followed%20those%20instructions.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-298643%22%20slang%3D%22en-US%22%3ERe%3A%20Site%20themes%20via%20Rest.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-298643%22%20slang%3D%22en-US%22%3ENot%20sure%20If%20I'm%20following%20you%20here...the%20URL%20you%20have%20provided%20refers%20to%20Site%20Designs%20REST%20API%20that%20is%20just%20to%20work%20with%20Site%20Designs%20and%20not%20with%20site%20themes...to%20work%20with%20themes%20using%20REST%20API%20take%20a%20look%20at%20this%3A%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fdeclarative-customization%2Fsite-theming%2Fsharepoint-site-theming-rest-api%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fdeclarative-customization%2Fsite-theming%2Fsharepoint-site-theming-rest-api%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-298567%22%20slang%3D%22en-US%22%3ERe%3A%20Site%20themes%20via%20Rest.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-298567%22%20slang%3D%22en-US%22%3Econst%20XMLHttpRequest%20%3D%20require(%22xmlhttprequest%22).XMLHttpRequest%3B%3CBR%20%2F%3Econst%20spauth%20%3D%20require(%22node-sp-auth%22)%3B%3CBR%20%2F%3Econst%20rp%20%3D%20require(%22request-promise%22)%3B%3CBR%20%2F%3E%3CBR%20%2F%3Econst%20express%20%3D%20require(%22express%22)%3B%3CBR%20%2F%3Econst%20app%20%3D%20express()%3B%3CBR%20%2F%3E%3CBR%20%2F%3Econst%20url%20%3D%20require(%22.%2Fconfig%22).url%3B%3CBR%20%2F%3Econst%20credentialOptions%20%3D%20require(%22.%2Fconfig%22).credentialOptions%3B%3CBR%20%2F%3Econst%20port%20%3D%2080%3B%3CBR%20%2F%3E%3CBR%20%2F%3ERestRequest%20%3D%20(url%2C%20params)%20%3D%26gt%3B%20%7B%3CBR%20%2F%3Econst%20_spPageContextInfo%20%3D%20url%3B%3CBR%20%2F%3Elet%20req%20%3D%20new%20XMLHttpRequest()%3B%3CBR%20%2F%3Ereq.onreadystatechange%20%3D%20function()%20%7B%3CBR%20%2F%3Eif%20(req.readyState%20!%3D%204)%3CBR%20%2F%3E%2F%2F%20Loaded%3CBR%20%2F%3Ereturn%3B%3CBR%20%2F%3Econsole.log(req.responseText)%3B%3CBR%20%2F%3E%7D%3B%3CBR%20%2F%3Ereq.open(%22POST%22%2C%20url%2C%20true)%3B%3CBR%20%2F%3Ereq.setRequestHeader(%22Content-Type%22%2C%20%22application%2Fjson%3Bcharset%3Dutf-8%22)%3B%3CBR%20%2F%3Ereq.setRequestHeader(%22ACCEPT%22%2C%20%22application%2Fjson%3B%20odata.metadata%3Dminimal%22)%3B%3CBR%20%2F%3Ereq.setRequestHeader(%22x-requestdigest%22%2C%20_spPageContextInfo)%3B%3CBR%20%2F%3Ereq.setRequestHeader(%22ODATA-VERSION%22%2C%20%224.0%22)%3B%3CBR%20%2F%3Ereq.send(params%20%3F%20JSON.stringify(params)%20%3A%20void%200)%3B%3CBR%20%2F%3E%7D%3B%3CBR%20%2F%3ERestRequest(%22%2F_api%2Fthememanager%2FGetTenantThemingOptions%22)%3B%3CBR%20%2F%3E%3CBR%20%2F%3Econst%20pal%20%3D%20%7B%3CBR%20%2F%3Epalette%3A%20%7B%3CBR%20%2F%3EthemePrimary%3A%20%22%2300ffff%22%2C%3CBR%20%2F%3EthemeLighterAlt%3A%20%22%23f3fcfc%22%2C%3CBR%20%2F%3EthemeLighter%3A%20%22%23daffff%22%2C%3CBR%20%2F%3EthemeLight%3A%20%22%23affefe%22%2C%3CBR%20%2F%3EthemeTertiary%3A%20%22%2376ffff%22%2C%3CBR%20%2F%3EthemeSecondary%3A%20%22%2339ffff%22%2C%3CBR%20%2F%3EthemeDarkAlt%3A%20%22%2300c4c4%22%2C%3CBR%20%2F%3EthemeDark%3A%20%22%23009090%22%2C%3CBR%20%2F%3EthemeDarker%3A%20%22%23005252%22%2C%3CBR%20%2F%3EneutralLighterAlt%3A%20%22%23f8f8f8%22%2C%3CBR%20%2F%3EneutralLighter%3A%20%22%23f4f4f4%22%2C%3CBR%20%2F%3EneutralLight%3A%20%22%23eaeaea%22%2C%3CBR%20%2F%3EneutralQuaternaryAlt%3A%20%22%23dadada%22%2C%3CBR%20%2F%3EneutralQuaternary%3A%20%22%23d0d0d0%22%2C%3CBR%20%2F%3EneutralTertiaryAlt%3A%20%22%23c8c8c8%22%2C%3CBR%20%2F%3EneutralTertiary%3A%20%22%23a6a6a6%22%2C%3CBR%20%2F%3EneutralSecondaryAlt%3A%20%22%23767676%22%2C%3CBR%20%2F%3EneutralSecondary%3A%20%22%23666666%22%2C%3CBR%20%2F%3EneutralPrimary%3A%20%22%23333%22%2C%3CBR%20%2F%3EneutralPrimaryAlt%3A%20%22%233c3c3c%22%2C%3CBR%20%2F%3EneutralDark%3A%20%22%23212121%22%2C%3CBR%20%2F%3Eblack%3A%20%22%23000000%22%2C%3CBR%20%2F%3Ewhite%3A%20%22%23fff%22%2C%3CBR%20%2F%3EprimaryBackground%3A%20%22%23fff%22%2C%3CBR%20%2F%3EprimaryText%3A%20%22%23333%22%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3B%3CBR%20%2F%3E%3CBR%20%2F%3Eapp.listen(port%2C%20()%20%3D%26gt%3B%20%7B%3CBR%20%2F%3Econsole.log(%60App%20listening%20on%20port%20%24%7Bport%7D%60)%3B%3CBR%20%2F%3E%7D)%3B%3CBR%20%2F%3E%3CBR%20%2F%3Eapp.get(%22%2F%22%2C%20(req%2C%20res)%20%3D%26gt%3B%20%7B%3CBR%20%2F%3E%2F%2Fget%20auth%20options%3CBR%20%2F%3Espauth.getAuth(url%2C%20credentialOptions).then(options%20%3D%26gt%3B%20%7B%3CBR%20%2F%3E%2F%2Fperform%20request%20with%20any%20http-enabled%20library%20(request-promise%20in%20a%20sample%20below)%3A%3CBR%20%2F%3Elet%20headers%20%3D%20options.headers%3B%3CBR%20%2F%3Eheaders%5B%22Accept%22%5D%20%3D%20%22application%2Fjson%3Bodata%3Dverbose%22%3B%3CBR%20%2F%3E%3CBR%20%2F%3Erp.get(%7B%3CBR%20%2F%3Eurl%3A%20url%2C%3CBR%20%2F%3Eheaders%3A%20headers%3CBR%20%2F%3E%7D).then(response%20%3D%26gt%3B%20%7B%3CBR%20%2F%3Eres.send(response)%3B%3CBR%20%2F%3E%3CBR%20%2F%3ERestRequest(%22%2F_api%2Fthememanager%2FAddTenantTheme%22%2C%20%7B%3CBR%20%2F%3Ename%3A%20%22DPT%20Cyna%22%2C%3CBR%20%2F%3EthemeJson%3A%20JSON.stringify(pal)%3CBR%20%2F%3E%7D)%3B%3CBR%20%2F%3E%7D)%3B%3CBR%20%2F%3E%7D)%3B%3CBR%20%2F%3E%7D)%3B%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

I tried following at https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/site-theming/sharepoint-si...

 

 

 
I keep getting the following response: 
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot POST /_api/thememanager/AddTenantTheme</pre>
</body>
</html>
3 Replies
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
const spauth = require("node-sp-auth");
const rp = require("request-promise");

const express = require("express");
const app = express();

const url = require("./config").url;
const credentialOptions = require("./config").credentialOptions;
const port = 80;

RestRequest = (url, params) => {
const _spPageContextInfo = url;
let req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState != 4)
// Loaded
return;
console.log(req.responseText);
};
req.open("POST", url, true);
req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
req.setRequestHeader("ACCEPT", "application/json; odata.metadata=minimal");
req.setRequestHeader("x-requestdigest", _spPageContextInfo);
req.setRequestHeader("ODATA-VERSION", "4.0");
req.send(params ? JSON.stringify(params) : void 0);
};
RestRequest("/_api/thememanager/GetTenantThemingOptions");

const pal = {
palette: {
themePrimary: "#00ffff",
themeLighterAlt: "#f3fcfc",
themeLighter: "#daffff",
themeLight: "#affefe",
themeTertiary: "#76ffff",
themeSecondary: "#39ffff",
themeDarkAlt: "#00c4c4",
themeDark: "#009090",
themeDarker: "#005252",
neutralLighterAlt: "#f8f8f8",
neutralLighter: "#f4f4f4",
neutralLight: "#eaeaea",
neutralQuaternaryAlt: "#dadada",
neutralQuaternary: "#d0d0d0",
neutralTertiaryAlt: "#c8c8c8",
neutralTertiary: "#a6a6a6",
neutralSecondaryAlt: "#767676",
neutralSecondary: "#666666",
neutralPrimary: "#333",
neutralPrimaryAlt: "#3c3c3c",
neutralDark: "#212121",
black: "#000000",
white: "#fff",
primaryBackground: "#fff",
primaryText: "#333"
}
};

app.listen(port, () => {
console.log(`App listening on port ${port}`);
});

app.get("/", (req, res) => {
//get auth options
spauth.getAuth(url, credentialOptions).then(options => {
//perform request with any http-enabled library (request-promise in a sample below):
let headers = options.headers;
headers["Accept"] = "application/json;odata=verbose";

rp.get({
url: url,
headers: headers
}).then(response => {
res.send(response);

RestRequest("/_api/thememanager/AddTenantTheme", {
name: "DPT Cyna",
themeJson: JSON.stringify(pal)
});
});
});
});
Highlighted
Not sure If I'm following you here...the URL you have provided refers to Site Designs REST API that is just to work with Site Designs and not with site themes...to work with themes using REST API take a look at this: https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/site-theming/sharepoint-si...
Highlighted

Sorry I apologize for providing the wrong article. I meant to provide the one you actually shared. I followed those instructions.