Forum Discussion
Rest API Error:"The parameter Members does not exist in method AddTenantTheme"
Using the following code.
$colorPairs = @{
"themePrimary" = "#003538";
"themeLighterAlt" = "#cbe6e7";
"themeLighter" = "#a1cfd1";
"themeLight" = "#7cb8bb";
"themeTertiary" = "#5ba2a5";
"themeSecondary" = "#3f8c90";
"themeDarkAlt" = "#28767a";
"themeDark" = "#166064";
"themeDarker" = "#094b4e";
"neutralLighterAlt" = "#f8f8f8";
"neutralLighter" = "#f4f4f4";
"neutralLight" = "#eaeaea";
"neutralQuaternaryAlt" = "#dadada";
"neutralQuaternary" = "#d0d0d0";
"neutralTertiaryAlt" = "#c8c8c8";
"neutralTertiary" = "#98a9da";
"neutralSecondary" = "#4863b4";
"neutralPrimaryAlt" = "#113191";
"neutralPrimary" = "#002081";
"neutralDark" = "#001963";
"black" = "#001249";
"white" = "#ffffff";
}
$content = @{
"name" = "MyCustomTheme"
"themeJson" = $jsonBody
} | ConvertTo-Json
$apiUrl = "https://<<domain>>-admin.sharepoint.com/_api/thememanager/AddTenantTheme"
Invoke-PnPSPRestMethod -Url $apiUrl -Method "Post" -Content $content
Tried many different combinations but kept getting
Invoke-PnPSPRestMethod: {"odata.error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"The parameter Members does not exist in method AddTenantTheme."}}}
Wondering if somebody can run this code successfully and let me know what I am missing.
2 Replies
The call reaches AddTenantTheme, but the request body does not match the method contract. In the shown script, themeJson references $jsonBody, yet that variable is never created from $colorPairs. Build the legacy theme object with isInverted and palette properties, convert that complete object to compressed JSON, and pass the resulting string as themeJson. The outer body for AddTenantTheme must contain name and themeJson, then be serialized once before the POST. Microsoft’s REST sample follows that exact pattern. If your data is actually in the newer color-pair format, use AddTenantThemeAdvanced and include shouldParseColorPair instead. The supported PowerShell alternative is Add-SPOTheme with the palette hashtable, which avoids manually constructing the REST payload. Also make the call against the tenant’s primary geography; Microsoft documents that tenant theme administration is not supported from a satellite geography. After correcting the object, inspect the final body to confirm themeJson contains a JSON string rather than null.
- AmarDhanCopper Contributor
Yes, I tried all what you suggested but for some reason I couldn't get Invoke-PnPSPRestMethod to work.
Strangely, I was able to get it to work when I used REST api directly but couldn't get it to work using
Invoke-PnPSPRestMethod in powershell.