1

Is there any way to update user profile of another user from SPFx webpart. Current logged in user is tenant admin and/or SharePoint admin.

Access is given to Azure AD app 'SharePoint Online Client Extensibility Web Application Principal' with User.ReadWrite.All

Still it throws 'Access denied. You do not have permission to perform this action or access this resource.' Same code works for current logged in user.

Below is using current site context

updateSingleUPValue() {
    let apiUrl = this.context.pageContext.web.absoluteUrl + "/_api/SP.UserProfiles.PeopleManager/SetSingleValueProfileProperty";

    let userData = {
      'accountName': "i:0#.f|membership|" + "anotheruser@mytenant.com",
      'propertyName': this.propertyName, //can also be used to set custom single value profile properties
      'propertyValue': this.value
    }
    let httpClient: SPHttpClient = this.context.spHttpClient;



    let spOpts = {
      headers: {
        'Accept': 'application/json;odata=nometadata',
        'Content-type': 'application/json;odata=verbose',
        'odata-version': '',
      },
      body: JSON.stringify(userData)
    };

    httpClient.post(apiUrl, SPHttpClient.configurations.v1, spOpts).then(response => {
      alert("Updated");
    });
  }

Read at couple of places that

updateSingleUPValue() {
    apiUrl = "https://mytenant-admin.sharepoint.com" + "/_api/SP.UserProfiles.PeopleManager/SetSingleValueProfileProperty";
    let userData = {
      'accountName': "i:0#.f|membership|" + this.userdetails.loginName,
      'propertyName': this.propertyName, //can also be used to set custom single value profile properties
      'propertyValue': this.value
    }
    let httpClient: SPHttpClient = this.context.spHttpClient;



    let spOpts = {
      headers: {
        'Accept': 'application/json;odata=nometadata',
        'Content-type': 'application/json;odata=verbose',
        'odata-version': '',
      },
      body: JSON.stringify(userData)
    };

    httpClient.post(apiUrl, SPHttpClient.configurations.v1, spOpts).then(response => {
      alert("Updated");
    });
  }

On above code first it is automatically trying to get context info - where itself it is failing and giving 403 forbidden

https://mytenant-admin.sharepoint.com/_api/contextinfo 403

any pointer/ideas - Basic Idea is to update user profile properties of another user, all required access can be given.

  • Can you check if the user profile property's Default privacy setting is set to "Everyone" and not "Only Me"? – Gautam Sheth Jun 23 at 17:20
  • yes..default privacy setting is set to Everyone, for demo purpose trying to update 'Home Phone' property. – Siddharth Vaghasia Jun 23 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.