Managing user profiles in SharePoint Online is more than just fetching or updating properties like Department
or JobTitle
. Modern SPFx solutions often need deep integration with SharePoint’s social features, follow APIs, and people search . With PnPjs v3, you can access advanced profile endpoints to power personalized experiences, recommendations, and collaboration scenarios.
In this article, we’ll explore the advanced APIs available in @pnp/sp/profiles
.
Set up in SPFx
Make sure you have the latest PnPjs installed:
npm install @pnp/sp @pnp/sp/profiles @pnp/logging @pnp/queryable @pnp/core
Configure PnPjs in your SPFx component:
import { spfi } from "@pnp/sp";
import { SPFx } from "@pnp/sp";
import "@pnp/sp/profiles";
const sp = spfi().using(SPFx(this.context));
Trending Documents for a User
const trendingDocs = await sp.profiles.trendingDocuments();
trendingDocs.forEach(doc => { console.log(doc.Title, doc.Url); });
User People Suggestions
const suggestions = await sp.profiles.getPeopleFollowedBy("[email protected]");
suggestions.forEach(person => { console.log(person.DisplayName, person.Email); });
User’s Followers & Following
const followers = await sp.profiles.myFollowers();
const following = await sp.profiles.peopleFollowedByMe();
console.log("Followers:", followers.length); console.log("Following:", following.length);
People Recommendations
const recommendations = await sp.profiles.peopleRecommendations();
recommendations.forEach(r => { console.log(r.DisplayName, r.JobTitle); });
Profile Image Retrieval
const photoUrl = await sp.profiles.getUserProfilePicture("[email protected]");
console.log(photoUrl); // Returns image blob URL
Search for People Across the Tenant
const results = await sp.profiles.clientPeoplePickerSearchUser({
QueryString: "John",
MaximumEntitySuggestions: 10,
PrincipalType: 1, // Users only
});
console.log("People Search:", results);
👉 Perfect for building custom people pickers in forms or organization directories.
Best Practices
✅ Cache results (session/local storage) to reduce Graph/SharePoint calls.
✅ Respect privacy — don’t over-expose profile properties.
✅ Use lazy-loading for large profile requests.
✅ Combine with Microsoft Graph for richer org data.
Conclusion
With @pnp/sp/profiles,
you can go far beyond basic profile property reads/updates. From social insights (followers, colleagues, trending docs) to personalized recommendations, these APIs enable rich, user-centered SPFx solutions that drive collaboration.