2

I'm trying to use the REST API in SharePoint 2013 to get the site groups.

I've been using this link for a little help... http://msdn.microsoft.com/en-us/library/jj245927.aspx

It's to do it with the Client Object Model and the REST API, I have tried both. The problem is that when I call to get Site Groups, with any of the below example urls (or using the JSOM) I seem to get every group in the whole site collection. Not just those specific to the site (SPWeb).

// I expect to get the groups in the root SPWeb

    http://{sitecollection}/_api/Web/SiteGroups 

I expect to get the groups in the SPWeb at <subsite>/<subsite2>, but I get the same result as the above call.

http://{sitecollection}/{subsite}/{subsite2}/_api/Web/SiteGroups 

The extra groups I am seeing are actually in subsite2, but even when I change to subsite/subsite3, I still get the same result?

It's like they are cached calls or something...is there something I am missing?? Is this call related to the calling user at all?

The server side object model does not have this problem and works as expected.

  • Funny how the reason pops up once you write it down! SiteGroups is not the same as Groups. However I cant seem to get Groups on the JSOM. Any ideas? – SteveCl Oct 24 '13 at 17:04
  • Yes. SiteGroups will give you all the groups from the Site Collection. msdn.microsoft.com/EN-US/library/jj246603.aspx – Vardhaman Deshpande Oct 27 '13 at 22:15
  • But is there a way (in the REST api or JSOM) to get the groups associated with a specific SPWeb? I can only think of doing something with Associations and Binding in some crazy loops!!? – SteveCl Oct 29 '13 at 13:15
  • hi @Eric , can you please tell how can i pass a group name which starts with or contains keyword in the method getgroups?in C#, SSOM, its available , but in JSOM/ REST is it possible to achieve ? – SaMolPP Dec 22 '16 at 8:12
7

Even though Web class does not expose Groups property like SPWeb class does, you could still retrieve a collection that contains all the groups for the website.

How to retrieve groups for a web

Use RoleAssignmentCollection.Groups property to get the groups that directly belong to the access control list (ACL). for this securable object.

CSOM

using (var ctx = new ClientContext(url))
{ 
    var web = ctx.Web;
    var webGroups = web.RoleAssignments.Groups;
}

REST

/_api/web/roleassignments/groups
  • 1
    Nice that you can use this on any securable object! – John-M Aug 26 '14 at 20:56
  • how to export these spgroups into a csv file or excel ? – SaMolPP May 31 '17 at 9:58
4

With REST you can filter based on the Title of the groups. However this depends on group names containing the site name. Naming should also be consistent e.g. starting all group names with site name. The url for such a request would be

http://{sitecollection}/_api/web/sitegroups?$filter=startswith(Title,'site name') eq true

For more information about filtering take a look at http://www.odata.org/documentation/odata-v2-documentation/uri-conventions/#45_Filter_System_Query_Option_filter

  • Thanks. That doesn't really give me the groups associated with a site, just a filter on group names. Like you said, it depends 100% on the site name in the group name, which rather pigeon holes that group. – SteveCl Dec 17 '13 at 15:49
  • dead link on there – Nicholas DiPiazza Jan 11 '17 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.