Please assist me to get SharePoint group collection using JavaScript. please provide me whats steps I need to follow in order to use that in my code.

2 Answers 2


You can use REST API to query SharePoint Group Collection.

  url: "<app web url>/_api/SP.AppContextSite(@target)/web
    ?@target='<host web url>'",
  method: "GET",
  headers: { "accept": "application/json; odata=verbose" },
  success: successHandler,
  error: errorHandler

Refer this msdn article



There are two ways to do so. One way is to use the JavaScript Object Model. This requires you to learn that API. The other way is through the REST api, which only requires you to know a little bit of Javascript (bonus if you know jQuery and oData) and the structures SharePoint uses to hold data.

What you want to do is basically a request to the following URI:


Where "foobar" is the whole path to your web site.

If you go to that URI through your browser, you will get the data for all groups within the site in XML. It's barely human readable, but it's all there.

You can also make an Ajax request with jQuery. You can dynamically get the URL for the request like this:

var url = L_Menu_BaseUrl + "/_api/web/sitegroups";

L_Menu_BaseUrl is a global variable that SharePoint gets into all its pages. It contains the path to the site.

Let's continue with the following code:

    dataType: "json",
    headers: {
        "accept": "application/json;odata=verbose",
        "content-type": "application/json;odata=verbose"
    type: "GET",
    url: url,
    beforeSend: function (xhr) {
        xhr.withCredentials = true; // this is the best cross-browser way to send credentials.
}).done(function (data) {
    // jackpot! The data argument will contain all your group collections data!
}).fail(function (data, xhr, message) {
    // some error occurred, handle it.

If you make this request successfully, the data argument from the function you passed to the done method will contain the data you want. Explore this object from within your browser's console :)

For the whole set of properties and operations you can get for groups, see the official documentation for the GroupCollection resource.

Learning oData is required for more advanced things like filtering what data you get from the request. I highly recommend it.

Good luck and have fun!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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