SharePoint online: Get site user id using Office365-REST-Python-Client library

Viewed 1007

I am using SharePoint online and trying to get Site's user id using below REST API:

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

I've tried many libraries, but could successfully athenticate SharePoint online only with Office365-REST-Python-Client. So, would like to stick with same library.

I have gone through the examples provided on GitHub here. Provided examples are only for list item. But, I want to get site user details.

Has anyone done this with Office365-REST-Python-Client library?

Thanks in advance

1 Answers

I have posted this question on Office365-REST-Python-Client and author has replied with answer. I just have to change a bit for my requirement. Below is the working code. Hope it may be helpful to someone.

 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"]))
Related