Site themes via Rest.

Copper 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)
});
});
});
});
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...

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