Problem
In one of our projects we were using SharePoint client People picker web service to fetch all users and groups to populate a people picker field in SPFx, below is the web service we used. The web service accepts query parameters as shown below and suddenly stopped working in the first two weeks of Apr 2021.
~site/_api/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerSearchUser
Actual code
- const userRequestUrl = `${this.props.siteUrl}/_api/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerSearchUser`;
- const userQueryParams = {
- 'queryParams': {
- 'AllowEmailAddresses': true,
- 'AllowMultipleEntities': false,
- 'AllUrlZones': false,
- 'MaximumEntitySuggestions': 15,
- 'QueryString': terms
- }
- };
- return this.props.spHttpClient.post(userRequestUrl, SPHttpClient.configurations.v1, {
- body: JSON.stringify(userQueryParams)
- }).then((httpResponse: SPHttpClientResponse) => {
- return httpResponse.json();
- })
There were no (empty array) results when we pass any search terms.
Solution
Upon research we found that there was a recent change by Microsoft which made this combination of parameters to this API not work. We had to change the query parameters to include principle source and principle type. Folllowing is the updated query paramters which we used with the same API and it started working.
- const userQueryParams = {
- 'queryParams': {
- 'AllowEmailAddresses': true,
- 'AllowMultipleEntities': false,
- 'AllUrlZones': false,
- 'MaximumEntitySuggestions': 15,
- 'QueryString': terms,
- 'PrincipalSource': 15,
- 'PrincipalType': 13
- }
Code after changes,
- const userRequestUrl = `${this.props.siteUrl}/_api/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerSearchUser`;
- const userQueryParams = {
- 'queryParams': {
- 'AllowEmailAddresses': true,
- 'AllowMultipleEntities': false,
- 'AllUrlZones': false,
- 'MaximumEntitySuggestions': 15,
- 'QueryString': terms,
- 'PrincipalSource': 15,
- 'PrincipalType': 13
- }
- };
- return this.props.spHttpClient.post(userRequestUrl, SPHttpClient.configurations.v1, {
- body: JSON.stringify(userQueryParams)
- }).then((httpResponse: SPHttpClientResponse) => {
- return httpResponse.json();
- }
There are no documentations found on this issue and hence I'm writing my first one!
Sagar SontakkePosted Apr 23, 2021, 11:04 AM
You saved my day brother. It suddenly stopped working for me on production and this resolved the issue. Thanks again.
Vinay AyinapurapuPosted Apr 21, 2021, 8:26 PM
Thanks for sharing.. good one