SharePointVault ~/gotchas/rest-api ⌕ Search 404 pages, error messages, scripts…Ctrl K ★ Star
M↓ README.mdM↓ delete-group-by-name-no-removebyname.md
sharepoint-vault›gotchas›rest-api›delete-group-by-name-no-removebyname.mdhistoryedit on GitHub
● GOTCHArest-api· 2 min read

There is no sitegroups/removebyname — delete a group by Id

applies to: SharePoint Online, SharePoint Serverreviewed: 2026-07-24#rest-api#groups#permissions#spfx

GroupCollection has GetByName (read) but no RemoveByName. To delete a group when you only know its name, resolve the Id with getbyname first, then POST .../sitegroups/removebyid(<id>).

GroupCollection má GetByName (čtení), ale RemoveByName NE. Když znáš jen jméno skupiny, nejdřív si přes getbyname zjisti Id a teprve pak POST .../sitegroups/removebyid(<id>).

Symptom

Code deletes a site group by posting to a name-based endpoint:

POST /_api/web/sitegroups/removebyname('My Group')

The call returns without throwing, but the group is still there — a follow-up getbyname('My Group') keeps returning it (same Id, only the updated timestamp moves). If the failure is swallowed (return resp.ok inside a try/catch), nothing surfaces in the UI: the surrounding action looks like it succeeded.

Cause

SP.GroupCollection exposes GetById, GetByName, Add, and — for removal — only RemoveById(id) (plus RemoveByLoginName, which removes a user from a group, not a group). RemoveByName does not exist. The read method GetByName tempts you into assuming a symmetric RemoveByName; there is none, so SharePoint rejects the call with a non-2xx status and the group survives.

Fix

Resolve the Id, then remove by Id:

// 1. name -> Id
const g = await sp.get(
  `${web}/_api/web/sitegroups/getbyname('${encodeURIComponent(name)}')?$select=Id`, ...);
if (g.status === 404) return true;              // already gone = done (idempotent)
if (!g.ok) return false;
const { Id } = await g.json();

// 2. delete by Id (POST needs a fresh X-RequestDigest)
const res = await sp.post(
  `${web}/_api/web/sitegroups/removebyid(${Id})`,
  { headers: { 'X-RequestDigest': digest, ... }, body: '' });
return res.ok;

Notes

  • getbyname (GET) working is not proof that removebyname (POST) exists — the read and write method sets differ on the same collection. Check the actual GroupCollection methods, don't infer a delete endpoint from the read one.
  • A REST endpoint is just a string; TypeScript won't flag a non-existent method name. The only safety net is a live smoke test that verifies the resulting state (getbyname → 404), not merely that the request came back. "Save succeeded" ≠ "the delete happened."
  • The POST to removebyid needs a valid X-RequestDigest; a stale page digest 403s after ~30 min (see request-digest-expires-mid-session).
  • Deleting a group is destructive and requires Manage Permissions (site owner / Full Control); a Contributor gets 403.
Was this helpful?ask or add your experience on GitHub →
Saved you an hour? A star on GitHub helps other SharePoint people find the vault.★ Star on GitHub
last reviewed: 2026-07-24last updated: 2026-09-24historyedit on GitHubview source