Update User Profile Property Using PnP JS In SharePoint Online

In this article, I have explained how to update the user profile property using a PnP JS library. It works only on SharePoint Online, not for SharePoint on-premises.
 
First, I am going to retrieve all the properties of my Office 365 account.
  1. import pnp from "@pnp/pnpjs";   
  2.   
  3. //For demo purpose hard-coded the login name of the user  
  4.   
  5. let loginName = "i:0#.f|membership|[email protected]";  
  6.   
  7. pnp.sp.profiles.getPropertiesFor(loginName).then(resp => {  
  8.         let props = {}  
  9.         resp.UserProfileProperties.map(function(val){  
  10.             props[val.Key] = val.Value  
  11.         })  
  12.   
  13.         console.log("props", props)  
  14. });  
It will return all the properties of the supplied user,
 
Update User Profile Property Using PnP JS In SharePoint Online
 
SET “SETSINGLEVALUEPROFILEPROPERTY” for the user.
 
So now, “AboutMe” property is returned as empty. I am going to update this using the “setSingleValueProfileProperty” method.
 
Update User Profile Property Using PnP JS In SharePoint Online 
  1. let loginName = "i:0#.f|membership|[email protected]";  
  2.   
  3. //Pass the login name, property, and property value as strings  
  4.   
  5. // Hard-coded the property value 'techie'  
  6.   
  7. pnp.sp.profiles.setSingleValueProfileProperty(loginName, 'AboutMe''Techie').then(res => {  
  8.     console.log("Update success")  
  9. })  
It’s updated successfully. See the response below.
 
Update User Profile Property Using PnP JS In SharePoint Online
 
SET “SETMULTIVALUEPROFILEPROPERTY” for the user.
 
So now, “SPS-Skills” property is returned as empty. I am going to update this using the “setMultiValuedProfileProperty” method.
  1. let skill = ["sharepoint""flow""powerapps"];  
  2.   
  3. //Pass the login name, property, and property value as strings  
  4.   
  5. pnp.sp.profiles.setMultiValuedProfileProperty(loginName, 'SPS-Skills', skill).then(res => {  
  6.     console.log("Update success")  
  7. })  
It’s updated successfully. See the response below.
 
Update User Profile Property Using PnP JS In SharePoint Online
 
So now, you are able to update the user profile properties of the user. You can also do the same for multiple user accounts.
 
Happy SharePointing!