SharePoint Online – Update User Profile Property via REST API

Scenario – Suppose you wanted to update User Profile property like about me, Skill set or any other default or custom user profile property of SharePoint online user. This possible for via JSOM, CSOM,poweshell and REST API. Below is code snippets for quick reference to update user profile property via REST API for SharePoint Online.

There are 2 different end Point API available for single value property and multi value property

Single value – /_api/SP.UserProfiles.PeopleManager/SetSingleValueProfileProperty

Multi Value -/_api/SP.UserProfiles.PeopleManager/SetMultiValuedProfileProperty

Assumptions-  below example is for classic experience where it is assumed RequestDigest control is available. If you are on modern experience you need to call /_api/contextinfo to get digest token.

function updateSingleValue(){
var Headers = {
        'X-RequestDigest': $("#__REQUESTDIGEST").value,,
        "accept": "application/json; odata=nometadata",
        "content-type": "application/json;odata=nometadata"
    };

    var aboutData = {
        'accountName': "i:0#.f|membership|user@yourtenant.onmicrosoft.com",
        'propertyName': 'AboutMe', //can also be used to set custom single value profile properties
        'propertyValue': 'A tech savvy and computer geek which lives by earning bread on computers, passes time by watching/sitcoms and playing games on computers, also a loving husband, father, brother, son and friend and most importantly trying to be human being :)'
    }

    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/SetSingleValueProfileProperty",
        type: "POST",
        headers: Headers,
        data: JSON.stringify(aboutData),
        success:profileUpdateSuccess ,
        error: profileUpdateFail
    });

function profileUpdateSuccess(response){
    console.log(response);

}
function profileUpdateFail(jqxr, errorCode, errorThrown){
    console.log(jqxr);

}
}
function updateMultiValue(){

var Headers = {
            'X-RequestDigest': $("#__REQUESTDIGEST").value,,
            "accept": "application/json; odata=nometadata",
            "content-type": "application/json;odata=nometadata"
        };

        var aboutData = {
            'accountName': "i:0#.f|membership|user@yourtenant.onmicrosoft.com",
            'propertyName': 'SPS-Skills', //can also be used to set custom single value profile properties
            'propertyValue': ["SharePoint", "Office 365", "Node JS", "Ionic", "Gsuite"]
        }

        $.ajax({
            url: _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/SetMultiValuedProfileProperty",
            type: "POST",
            headers: Headers,
            data: JSON.stringify(aboutData),
            success:profileUpdateMultiSuccess ,
            error: profileUpdateMultiFail
        });



}

function profileUpdateMultiSuccess(response){
        console.log(response);

    }
    function profileUpdateMultiFail(jqxr, errorCode, errorThrown){
        console.log(jqxr);

    }

Hope this helps…Happy Coding..!!!

(Visited 1,548 times, 1 visits today)