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.