Tuesday, April 14, 2015

An approach to list all external users in your SharePoint Online enviroment

image

Kirk Liemohn recently asked a question on the Office 365 Yammer network if there was an API to list all the external users on his tenant. Being the search guy I am, I suggested using the search API to do this.
If I want to list all external users on the Puzzlepart tenant I can fire off the following REST query:

https://tenant.sharepoint.com/_api/search/query?querytext=%27-accountname:puzzlepart.com%27&selectproperties=%27AccountName%2cPreferredName%27&rowlimit=500&properties=%27SourceName:Local%20People%20Results%27

The above query will get the top 500 external users, which happens to be accounts without puzzlepart.com in the AccountName managed property. I’m also just retrieving AccountName and preferredname to limit data transfer, but include any property you need.

1 comment:

  1. Thanks! I couldn't get the 'SourceName:Local People Results' to work, but I could get it to work with the sourceid:

    https://testenv.sharepoint.com/_api/search/query?querytext=%27-accountname:testenv.onmicrosoft.com%27&selectProperties=%27AccountName%2cPreferredName%27&rowlimit=500&sourceid=%27b09a7990-05ea-4af9-81ef-edfab16c4e31%27

    ReplyDelete