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|" + "[email protected]",
      '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.

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

1 Answer 1

0

Enable your user properties only then you can update your user profile. Check your user properties as mentioned below.enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.