Groups & Users
Managing groups, requesting users
Site groups and users can be requested via Web's .SiteGroups() and .SiteUsers() queriable collections correspondingly.
Getting users sample
users, err := sp.Web().SiteUsers().
Select("Email,Id").
Filter("Email ne ''").
OrderBy("Id", true).
Get()
if err != nil {
log.Fatal(err)
}
for _, user := range users.Data() {
fmt.Printf("%d: %s\n", user.Data().ID, user.Data().Email)
}Getting groups sample
groups, err := sp.Web().SiteGroups().Get()
if err != nil {
log.Fatal(err)
}
for _, group := range groups.Data() {
fmt.Printf("%d: %s\n", user.Data().ID)
}Ensuring a user
You can't add new user via SharePoint API, but a user who exists in AD/AAD can be added to a site by ensuring him/her by a logon name.
Associated groups
We love the "power of defaults". Each web by default has three predefined groups: Owners, Members and Visitors. But their IDs and names are different from web to web. Luckily there is a helper for getting associated groups.
Creating groups
Deleting groups
Adding user to a group
In group's .AddUser method the argument should be full and valid login name including security provider membership prefix. For instance, while you can ensure Jane using [email protected] the same as an .AddUser method will fail as Jane's login is actually different i:0#.f|membership|[email protected].
If you already know UserID but not sure about LoginName .AddUserByID helper is at the disposal.
Removing users from a group
Similarly as with adding users:
Managing group owner
Getting group's users
Summary
That's it, most of the common actions with groups and users are covered.
You'd probably will be interested with the connected topics:
PermissionsSearch APIUser ProfilesLast updated
Was this helpful?
