Freigeben über


SharePoint-Websitedesign: REST-API

Mithilfe der SharePoint-REST-Schnittstelle können Sie grundlegende CRUD-Operationen auf Websitedesigns anwenden, d. h: Erstellen, Lesen, Aktualisieren und Löschen (Create, Read, Update, Delete).

Der REST-Dienst in SharePoint Online (sowie in lokalen Bereitstellungen von SharePoint 2016 und höher) erlaubt die Zusammenfassung mehrerer Anforderungen in einem einzigen Aufruf an den Service mittels der ODATA-Abfrageoption „$batch“. Einzelheiten und Links zu Codebeispielen finden Sie unter Durchführen von Batchanforderungen mit den REST-APIs.

Voraussetzungen

Lesen Sie vor der Umsetzung der Beispiele in diesem Artikel zunächst die folgenden Artikel:

REST-Befehle für Websitedesigns

Für Websitedesigns stehen die folgenden REST-Befehle zur Verfügung:

  • AddTenantTheme – erstellen Sie ein neues Design. ähnlich wie das Add-SPOTheme SharePoint-Cmdlet
  • DeleteTenantTheme : Entfernen sie ein Design aus dem Mandantenspeicher. ähnlich wie das Remove-SPOTheme PowerShell-Cmdlet
  • GetTenantThemingOptions – Designeinstellungen lesen
  • ApplyTheme – Mandantendesign auf Website anwenden
  • UpdateTenantTheme – Aktualisiert die Mandantendesigndefinition

Basis für die URL von REST-Befehlen zur Designverwaltung ist die Zeichenfolge „_api/thememanager“. Die Endpunkte für die oben aufgeführten Befehle beispielsweise sehen wie folgt aus:

  • http://<site url>/_api/thememanager/AddTenantTheme
  • http://<site url>/_api/thememanager/DeleteTenantTheme
  • http://<site url>/_api/thememanager/GetTenantThemingOptions
  • http://<site url>/_api/thememanager/ApplyTheme
  • http://<site url>/_api/thememanager/UpdateTenantTheme

AddTenantTheme

Der folgende JavaScript-Beispielcode demonstriert, wie Sie einem Mandanten ein neues Design hinzufügen können:

function RestRequest(url,params) {
  var req = new XMLHttpRequest();
  req.onreadystatechange = function ()
  {
    if (req.readyState != 4) // Loaded
      return;
    console.log(req.responseText);
  };
  // Prepend web URL to url and remove duplicated slashes.
  var webBasedUrl = (_spPageContextInfo.webServerRelativeUrl + "//" + url).replace(/\/{2,}/,"/");
  req.open("POST",webBasedUrl,true);
  req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
  req.setRequestHeader("ACCEPT", "application/json; odata.metadata=minimal");
  req.setRequestHeader("x-requestdigest", _spPageContextInfo.formDigestValue);
  req.setRequestHeader("ODATA-VERSION","4.0");
  req.send(params ? JSON.stringify(params) : void 0);
}


RestRequest("/_api/thememanager/AddTenantTheme");

var pal = {
    "palette" : {
        "themePrimary": "#1BF242",
        "themeLighterAlt": "#0d0b00",
        "themeLighter": "#0b35bc",
        "themeLight": "#322d00",
        "themeTertiary": "#6a5f00",
       "themeSecondary": "#1B22F2",
        "themeDarkAlt": "#ffe817",
        "themeDark": "#ffed4b",
        "themeDarker": "#fff171",
        "neutralLighterAlt": "#252525",
        "neutralLighter": "#282828",
        "neutralLight": "#313131",
        "neutralQuaternaryAlt": "#3f3f3f",
        "neutralQuaternary": "#484848",
        "neutralTertiaryAlt": "#4f4f4f",
        "neutralTertiary": "#c8c8c8",
        "neutralSecondaryAlt": "#d0d0d0",
        "neutralSecondary": "#dadada",
        "neutralPrimary": "#ffffff",
        "neutralDark": "#eaeaea",
        "black": "#f8f8f8",
        "white": "#1f1f1f",
        "primaryBackground": "#1f1f1f",
        "primaryText": "#ffffff",
        "error": "#ff5f5f"
    }
}
RestRequest("/_api/thememanager/AddTenantTheme", {name:"Sounders Rave Green", themeJson: JSON.stringify(pal)});

DeleteTenantTheme

Der folgende JavaScript-Beispielcode demonstriert, wie Sie Designs entfernen können:

function RestRequest(url,params) {
  var req = new XMLHttpRequest();
  req.onreadystatechange = function ()
  {
    if (req.readyState != 4) // Loaded
      return;
    console.log(req.responseText);
  };
  // Prepend web URL to url and remove duplicated slashes.
  var webBasedUrl = (_spPageContextInfo.webServerRelativeUrl + "//" + url).replace(/\/{2,}/,"/");
  req.open("POST",webBasedUrl,true);
  req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
  req.setRequestHeader("ACCEPT", "application/json; odata.metadata=minimal");
  req.setRequestHeader("x-requestdigest", _spPageContextInfo.formDigestValue);
  req.setRequestHeader("ODATA-VERSION","4.0");
  req.send(params ? JSON.stringify(params) : void 0);
}


RestRequest("/_api/thememanager/DeleteTenantTheme", { name:"Sounders Rave Green" });

GetTenantThemingOptions

Der folgende JavaScript-Beispielcode demonstriert, wie Sie die Einstellungen eines Designs auslesen können.

function RestRequest(url,params) {
  var req = new XMLHttpRequest();
  req.onreadystatechange = function ()
  {
    if (req.readyState != 4) // Loaded
      return;
    console.log(req.responseText);
  };
  // Prepend web URL to url and remove duplicated slashes.
  var webBasedUrl = (_spPageContextInfo.webServerRelativeUrl + "//" + url).replace(/\/{2,}/,"/");
  req.open("POST",webBasedUrl,true);
  req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
  req.setRequestHeader("ACCEPT", "application/json; odata.metadata=minimal");
  req.setRequestHeader("x-requestdigest", _spPageContextInfo.formDigestValue);
  req.setRequestHeader("ODATA-VERSION","4.0");
  req.send(params ? JSON.stringify(params) : void 0);
}

RestRequest("/_api/thememanager/GetTenantThemingOptions");

ApplyTheme

Der folgende JavaScript-Beispielcode demonstriert, wie Sie ein Design auf die Website anwenden.

function RestRequest(url,params) {
  var req = new XMLHttpRequest();
  req.onreadystatechange = function ()
  {
    if (req.readyState != 4) // Loaded
      return;
    console.log(req.responseText);
  };
  // Prepend web URL to url and remove duplicated slashes.
  var webBasedUrl = (_spPageContextInfo.webServerRelativeUrl + "//" + url).replace(/\/{2,}/,"/");
  req.open("POST",webBasedUrl,true);
  req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
  req.setRequestHeader("ACCEPT", "application/json; odata.metadata=minimal");
  req.setRequestHeader("x-requestdigest", _spPageContextInfo.formDigestValue);
  req.setRequestHeader("ODATA-VERSION","4.0");
  req.send(params ? JSON.stringify(params) : void 0);
}

var pal = {
    "palette" : {
        "themePrimary": "#1BF242",
        "themeLighterAlt": "#0d0b00",
        "themeLighter": "#0b35bc",
        "themeLight": "#322d00",
        "themeTertiary": "#6a5f00",
       "themeSecondary": "#1B22F2",
        "themeDarkAlt": "#ffe817",
        "themeDark": "#ffed4b",
        "themeDarker": "#fff171",
        "neutralLighterAlt": "#252525",
        "neutralLighter": "#282828",
        "neutralLight": "#313131",
        "neutralQuaternaryAlt": "#3f3f3f",
        "neutralQuaternary": "#484848",
        "neutralTertiaryAlt": "#4f4f4f",
        "neutralTertiary": "#c8c8c8",
        "neutralSecondaryAlt": "#d0d0d0",
        "neutralSecondary": "#dadada",
        "neutralPrimary": "#ffffff",
        "neutralDark": "#eaeaea",
        "black": "#f8f8f8",
        "white": "#1f1f1f",
        "primaryBackground": "#1f1f1f",
        "primaryText": "#ffffff",
        "error": "#ff5f5f"
    }
}
RestRequest("/_api/thememanager/ApplyTheme", {name:"Sounders Rave Green", themeJson: JSON.stringify(pal)});

UpdateTenantTheme

Der folgende JavaScript-Beispielcode demonstriert, wie Sie ein Mandantendesign aktualisieren.

function RestRequest(url,params) {
  var req = new XMLHttpRequest();
  req.onreadystatechange = function ()
  {
    if (req.readyState != 4) // Loaded
      return;
    console.log(req.responseText);
  };
  // Prepend web URL to url and remove duplicated slashes.
  var webBasedUrl = (_spPageContextInfo.webServerRelativeUrl + "//" + url).replace(/\/{2,}/,"/");
  req.open("POST",webBasedUrl,true);
  req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
  req.setRequestHeader("ACCEPT", "application/json; odata.metadata=minimal");
  req.setRequestHeader("x-requestdigest", _spPageContextInfo.formDigestValue);
  req.setRequestHeader("ODATA-VERSION","4.0");
  req.send(params ? JSON.stringify(params) : void 0);
}


var pal = {
    "palette" : {
			"themePrimary": "#008cff",
			"themeLighterAlt": "#f5faff",
			"themeLighter": "#d6edff",
			"themeLight": "#b3ddff",
			"themeTertiary": "#66baff",
			"themeSecondary": "#1f9aff",
			"themeDarkAlt": "#007ee6",
			"themeDark": "#006bc2",
			"themeDarker": "#004f8f",
			"neutralLighterAlt": "#f8f8f8",
			"neutralLighter": "#f4f4f4",
			"neutralLight": "#eaeaea",
			"neutralQuaternaryAlt": "#dadada",
			"neutralQuaternary": "#d0d0d0",
			"neutralTertiaryAlt": "#c8c8c8",
			"neutralTertiary": "#595959",
			"neutralSecondary": "#373737",
			"neutralPrimaryAlt": "#2f2f2f",
			"neutralPrimary": "#000000",
			"neutralDark": "#151515",
			"black": "#0b0b0b",
			"white": "#ffffff",
			"primaryBackground": "#ffffff",
			"primaryText": "#000000",
			"disabledBackground": "#f4f4f4",
			"disabledText": "#c8c8c8"
    }
}
RestRequest("/_api/thememanager/UpdateTenantTheme", {name:"Sounders Rave Green", themeJson: JSON.stringify(pal)});

Siehe auch