Skip to content
Menu
SharePoint Gems
  • Power Platform
  • Development
    • SharePoint 2013
  • Migration
  • Administration
  • SP Online
  • Contact
  • About
    • Privacy Policy
SharePoint Gems
SharePoint REST API

SharePoint REST API: Check if the current user is present in SharePoint Group or not

Posted on February 24, 2020September 29, 2021

Hello SharePointers,
In this blog, we will be using the SharePoint REST API to check if any user is present in the SharePoint group or not.

In my recent development, there was a requirnment to check the user from perticular group and manage his access to the document Library.

So I have used a REST API to do this functionality.

For example, We will check, if the user is present in the “Owners” group or not.

/** Check if the current user is in the Owners group **/
function isOwnerGroupMember() {
    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups/getByName('Owners')/Users?$filter=Id eq " + _spPageContextInfo.userId,
        method: "GET",
        headers: {
            "Accept": "application/json; odata=verbose"
        },
        success: function(data) {
            if (data.d.results.length == 0) {
                console.log("User not in group : Owners");                
            } else {
                console.log("User in group : Owners");                
            }
        },
        error: function(err) {
            console.log("Error while checking user in Owner's group");            
        }
    });
}

The above code meets the exact requirement of our coding. If you understand above code, it is well and good.

If not then don’t worriy, I have explained all details about this code as below. Please go through it and understand the code at your best.

In the above function, we are getting a response for the users present in “Owners” group and filtering users with currently logged in user id (_spPageContextInfo.userId).

If the user is present, it should provide a response with 1 or 0. We are checking this condition using if statement (data.d.results.length)

If data.d.results.length is 0, it means the user is not present in the specified permission group and if the data.d.results.length is 1, it means the user is present in the specified permission group

I hope you liked this article. If you have any queries, please use below comments section for the same.

Happy Coding…
For more reference for SharePoint REST API visit here
For more SharePoint tutorials please visit SharePointGems

Contents hide
1 Share this:
2 Like this:
3 Related

Share this:

  • Print
  • Twitter
  • Facebook
  • LinkedIn
  • WhatsApp
  • Telegram
  • Pinterest
  • Reddit

Like this:

Like Loading...

Related

2 thoughts on “SharePoint REST API: Check if the current user is present in SharePoint Group or not”

  1. SharePointGems says:
    February 24, 2020 at 7:16 AM

    Very Good Article .. thank you very much..

    Loading...
    Reply
  2. cbd oil tincture says:
    July 18, 2020 at 10:57 PM

    I’m the manager of JustCBD label (justcbdstore.com) and am looking to broaden my wholesale side of business. It would be great if anybody at targetdomain is able to provide some guidance . I considered that the very best way to accomplish this would be to reach out to vape companies and cbd retail stores. I was hoping if anybody could suggest a reliable web site where I can get CBD Shops B2B Data List I am already reviewing creativebeartech.com, theeliquidboutique.co.uk and wowitloveithaveit.com. On the fence which one would be the most ideal choice and would appreciate any advice on this. Or would it be much simpler for me to scrape my own leads? Ideas?

    Loading...
    Reply

Leave a ReplyCancel reply

  • Development
  • Migration
  • Poweer Apps
  • Power Automate
  • Power Platform
  • SharePoint 2013
  • SharePoint Administration
  • SharePoint Online
  • Tips
  • Uncategorized

Best of Computers

Blog Stats

  • 67,509 hits

Subscribe

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,433 other subscribers
Buy Me Coffee
©2025 SharePoint Gems | Powered by WordPress and Superb Themes!
%d