SharePoint People Picker REST API

This post will cover the people picker api available in the SharePoint 2013+ environments.

Overview

The SharePoint REST API has a people picker endpoint, which is pretty powerful. I haven’t found much documentation, but here is the research I have. There are two available methods which take the same query parameters.:

Client People Picker Query Parameters

Principal Type

A great tip by Paul Tavares about the principal type value. It supports multiple flags by using bitwise. Setting the value to 13 or 1101 in binary, which translates as flags 1, 4, & 8 true set to true and flag 2 set to false. These flags relates to the Principal Type “User”, “SecurityGroup” and “SharePointGroup” flags to be selected.

React Component

The gd-sprest-react library contains SharePoint components, including a people picker component.

Demo

I will be using the gd-sprest framework to demonstrate the execution of the calls. For this example, I have the library referenced on the page and am using the browser’s console window to execute the available methods.

clientPeoplePickerSearchUser

For this example, I’m searching for myself in a SharePoint Online environment. This will target the “Display Name” of the user.

JS Code:
$REST.PeoplePicker().clientPeoplePickerSearchUser({
    MaximumEntitySuggestions: 10,
    PrincipalSource: 15,
    PrincipalType: 15,
    QueryString: "Gunjan Datta"
}).executeAndWait();

Request

For those who don’t want to use the library, the request is a POST. The query parameters are passed in the body of the request:

{
    "queryParams": {
        "__metadata": {
            "type": "SP.UI.ApplicationPages.ClientPeoplePickerQueryParameters"
        },
        "MaximumEntitySuggestions":10,
        "PrincipalSource":15,
        "PrincipalType":15,
        "QueryString":"Gunjan Datta"
    }
}

Output

The output of the query returned the correct user account. Search User

clientPeoplePickerResolveUser

For this example, I’m resolving a user by their email address.

JS Code:
$REST.PeoplePicker().clientPeoplePickerResolveUser({
    AllowEmailAddresses: true,
    MaximumEntitySuggestions: 10,
    PrincipalSource: 15,
    PrincipalType: 15,
    QueryString: "me@dattabase.com"
}).executeAndWait();

Request

For those who don’t want to use the library, the request is a POST. The query parameters are passed in the body of the request:

{
    "queryParams": {
        "__metadata": {
            "type": "SP.UI.ApplicationPages.ClientPeoplePickerQueryParameters"
        },
        "AllowEmailAddresses":true,
        "MaximumEntitySuggestions":10,
        "PrincipalSource":15,
        "PrincipalType":15,
        "QueryString":"me@dattabase.com"
    }
}

Output

The output of the query returned the correct user account. Resolve User