Hi @Pankaj Kumar ,
According to my research and testing, please try to use the following code to get all groups:
function GetAllSiteGroups() {
$.ajax
({
// _spPageContextInfo.webAbsoluteUrl - will give absolute URL of the site where you are running the code.
// You can replace this with other site URL where you want to apply the function
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups",
type: "GET",
headers:
{
// Accept header: Specifies the format for response data from the server.
"Accept": "application/json;odata=verbose"
},
success: function (data, status, xhr) {
var dataresults = data.d.results;
for (var i = 0; i < dataresults.length; i++) {
console.log("Group Title - " + dataresults[i]["Title"]);
}
},
error: function (xhr, status, error) {
console.log("Failed");
}
});
}
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.