An Overview of the SharePoint User Profile Search API

You can query user characteristics like name, email, job title, and department using the SharePoint Search API, which provides a robust method of accessing user profile data. Here’s how to retrieve user profiles using the SharePoint Search API.

  1. What It Does: The SharePoint Search API allows you to search for people (user profiles) in the organization, using specific keywords or filters.
  2. Common Use Cases: Retrieving a user directory, displaying employee profiles, creating people search features, and filtering users based on department or location.

Here are the steps to get SharePoint User’s Profile properties using Search REST API.

Step 1. Setting Up Authentication.

  1. Registering an App in Azure AD: Register an application in Azure Active Directory to use the SharePoint API securely.
    • Generate the Client ID and Client Secret.
    • Grant Sites.Read.All and User.ReadBasic.All permissions for basic profile information, or User.Read.All if you need detailed profiles.
  2. Obtaining an Access Token: Use the OAuth 2.0 flow to authenticate and get an access token, which is required for each API call.

Step 2. Constructing the Search API Request for User Profiles.

The URL format for SharePoint Online.

https://<tenant-name>.sharepoint.com/_api/search/postquery

Request Body for User Profile Search

JavaScript Code Example with Fetch API

Key parts of the request

  1. Authorization Header: The Authorization header includes the OAuth 2.0 Bearer token needed to authenticate with the API.
  2. Content-Type: The header Content-Type: application/json;odata=verbose ensures that the API receives and interprets the request as JSON.
  3. Body Content: The request body includes.
    • Query text: Set to * to retrieve all users or customize the query with a filter (e.g., JobTitle: Manager).
    • SourceId: Specifies the people’s result source.
    • SelectProperties: Lists the properties to retrieve for each user profile, such as PreferredName, WorkEmail, and JobTitle.
    • RowLimit: Limits the number of results returned (e.g., 10).

Note. We can add filtering and pagination options too.

  1. Filtering Results: Change Querytext to filter by specific user properties (e.g., Querytext=’Department: Sales’).
  2. Pagination: Add StartRow to the request body to retrieve results in batches for pagination.

Conclusion

Using POST /_api/search/postquery is effective when working with complex queries, avoiding URL length limits, and selecting multiple profile properties. This approach can be extended to search for other types of data within SharePoint by changing the SourceId and adjusting the SelectProperties to meet your needs.

HostForLIFEASP.NET is The Best and Cheap SharePoint 2013 Hosting

HostForLIFEASP.NET has been Microsoft recommended hosting provider. In their best and cheap SharePoint 2010 hosting recommendation plan, they offer Support Custom WebParts, SharePoint Site Usage Reports, Support SSL, Users Administration, Intl Language Packs, Public-Facing Access. Get organized with their best and cheap SharePoint Foundation 2013 Hosting, the leading Microsoft web hosting solution for secure document management, content management, and workflow features for your intranet or extranet requirements. Their best and cheap SharePoint 2013 hosting plan is starting from $9.99/mo.

HostForLIFEASP.NET – 99.99% Uptime Guarantee

Does HostForLIFEASP.NET really give 99.99% up time? The answer is yes. HostForLIFEASP.NET Windows Hosting servers are capable enough to make your website 99.99% available. HostForLIFEASP.NET has established a world-class infrastructure making it possible to guarantee such a high uptime percentage. Of course there is always the possibility that some factor beyond the control of the HostForLIFEASP.NET Company will result in more downtime. Fortunately, this does not occur too often. Upgrades and maintenance downtime are acceptable and do not impact the uptime guarantee.

You may also like...

Popular Posts