Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Get SharePoint user id #136

Closed
Karthickraju2690 opened this issue Oct 22, 2019 · 5 comments
Closed

Question: Get SharePoint user id #136

Karthickraju2690 opened this issue Oct 22, 2019 · 5 comments
Labels

Comments

@Karthickraju2690
Copy link

I have the below rest api query to fetch SharePoint online's user id, but not sure how can I execute with the library.

https://url/sites/list/_api/Web/siteusers#?$filter=substringof('|userloginname',LoginName) eq true

Can you share example on how to run above REST api query?

@vgrem vgrem added the question label Oct 22, 2019
@vgrem
Copy link
Owner

vgrem commented Oct 22, 2019

Surely, $filter along with another OData query operations are supported.
Here is an example:

client = ClientContext(url, ctx_auth)
user_name = user.properties['UserPrincipalName']
users = client.web.site_users\
            .filter("substringof('|{0}',LoginName) eq true".format(user_name))
client.load(users)
client.execute_query()

@vgrem vgrem closed this as completed Oct 22, 2019
@Karthickraju2690
Copy link
Author

Thank you Vadim. I could read the details now. Have used your code like below:

    client = ClientContext(url, context_auth)
    users = client.web.site_users\
                .filter("substringof('|{0}',LoginName) eq true".format('LoginName'))
    client.load(users)
    client.execute_query()
    for user in users:
        print('User : {0}, Id: {1}'.format(user.properties["Title"], user.properties["Id"]))

Again, thanks much for your help

@sachinez731
Copy link

Hello, I tried to use above code. Two errors,
1)

File "C:\Users\ez731\Documents_hopper\Tracker_prefill.py", line 87, in
users = client.web.site_users\

AttributeError: 'Web' object has no attribute 'site_users'

  1. When I uncommented -- from office365.runtime.utilities.request_options import RequestOptions

File "C:\Users\ez731\Documents_hopper\Tracker_prefill.py", line 16, in
from office365.runtime.utilities.request_options import RequestOptions

ModuleNotFoundError: No module named 'office365.runtime.utilities.request_options'

Can you please guide me

@iglimanaj
Copy link

Regarding the first point, try siteUsers instead of site_users

@sachinez731
Copy link

Yeap That helps! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants