I don’t think that there is an api for that currently.. but here’s how it’s done:
This is partly copied from WebSignup snippet and some of it was written to this post, so there might be typos as I didn’t test it..
<?php
# setup key
$key = 0;
if (isset($username)) {
$sql = "SELECT id FROM ".$modx->getFullTableName("web_users")." WHERE username='$username'";
$rs = $modx->db->query($sql);
if(!$rs){
return "Could not find username: $username";
} else {
$userinfo = $modx->fetchRow($rs);
$key = $userinfo['id'];
}
} else {
$key = $_SESSION['webInternalKey'];
}
# setup web groups
$groups = isset($groups) ? explode(',',$groups) : array();
for($i=0;$i<count($groups);$i++) $groups[$i] = trim($groups[$i]);
// add user to web groups
if(count($groups)>0 && $key != 0) {
$ds = $modx->db->query("SELECT id FROM ".$modx->getFullTableName("webgroup_names")." WHERE name IN ('".implode("','",$groups)."')");
if(!$ds) return "Could not find some of the web groups";
else {
while ($row = $modx->fetchRow($ds)) {
$wg = $row["id"];
$modx->db->query("REPLACE INTO ".$modx->getFullTableName("web_groups")." (webgroup,webuser) VALUES('$wg','$key')");
}
}
}
?>
And you would call that using [[YourSnippetName? &groups=`thegroups,toset,theuser,to` &username=`someusername`]], or if you don’t specify the username, it would change the groups of the logged in web user..
But ofcourse the snippet isn’t any good like that, you would need to do maybe a button to activate it or include that code into some other snippet or a plugin.. or whatever.