2

I was unable to update any of the following user properties(SharePoint Online): aboutMe, birthday, hireDate, interests, mySite, pastProjects, preferredName, responsibilities, schools, skills. With other user properties in one request. Following the documentation.

https://learn.microsoft.com/en-us/graph/api/user-update?view=graph-rest-1.0&tabs=http

For example:

    public async Task UpdateUserTask(string userId)
    {
        User user = new User
        {
            AboutMe = "Im dev",
            GivenName = "Some One"
        };

        var _graphClient = GetGraphServiceClient();

        await _graphClient.Users[userId].Request().UpdateAsync(user);
    }

Implementation of GetGraphServiceClient:

https://learn.microsoft.com/en-us/graph/sdks/choose-authentication-providers?tabs=CS#client-credentials-provider

private GraphServiceClient GetGraphServiceClient()
    {
        string tenantId = "{myTenantId}";
        string clientId = "{myClientId}";
        string clientSecret = "{myClientSecret}";

        string[] scopes = new[]
        {
            "https://graph.microsoft.com/.default",
        };

        TokenCredentialOptions options = new TokenCredentialOptions
        {
            AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
        };

        ClientSecretCredential clientSecretCredential = new ClientSecretCredential(
            tenantId, clientId, clientSecret, options);

        return new GraphServiceClient(clientSecretCredential, scopes);
    }

Response:

Code: BadRequest.
Message: The request is currently not supported on the targeted entity set

Although if you update these properties separately, they are successful updated (AboutMe and GivenName)

What I have:

API permissions for writing and changing data:

  • Directory.ReadWrite.All,
  • Sites.ReadWrite.All (for set SharePoint Online props),
  • User.ReadWrite.All.
  • Full premissions enter image description here

And global admin rule.

Is there a way to update these properties using a single request?

I will be grateful for any answer :)

If you make the same query in Microsoft Graph Explorer, the result will not change

https://graph.microsoft.com/v1.0/users/{userId}
{
    "aboutMe": "Im dev",
    "givenName": "Someone"
}

enter image description here

DimaBond
  • 61
  • 6
  • What you've got looks good to me... To confirm, the only change between the failed test and the working ones is you've replace `new User{AboutMe = "Im dev",GivenName = "Some One"};` with `new User{AboutMe = "Im dev"};` and in a second test `new User{GivenName = "Some One"};`? I.e. all the rest of the code, and the test values used are the same? – JohnLBevan Feb 03 '22 at 10:51
  • 1
    @JohnLBevan Yes it is. But also make 2 separate user update requests **var user1 = new User{AboutMe = "Im dev"};** , **var user2 = new User{GivenName = "Some One"};** and **await _graphClient.Users[userId].Request().UpdateAsync(user1);** , **await _graphClient.Users[userId].Request().UpdateAsync(user2);** – DimaBond Feb 03 '22 at 11:08
  • Just guessing now, but are both properties new values different to their existing values? i.e. Maybe if aboutMe is different to what's stored, but givenName is the same, the API doesn't try to update givenName because it sees there's no change; but when called with both properties it sees there's an overall difference so updates both anyway? Not sure why it should fail - but trying to work out what's going on in the background to cause the two commands to behave differently. That's pure poking-around guesswork though / I don't have a good argument for why it should be an issue. – JohnLBevan Feb 03 '22 at 11:21
  • 1
    @JohnLBevan Both of these properties are **null** before the update – DimaBond Feb 03 '22 at 11:23

1 Answers1

3

There is a note in the documentation that the following properties cannot be updated by an app with only application permissions:

aboutMe, birthday, employeeHireDate, interests, mySite, pastProjects, preferredName, responsibilities, schools, and skills.

Which is exactly your case because you've added only application permissions to your app in Azure.

Update

Another limitation can be that User is a composite type and some properties are covered by different services and Graph API doesn't support updates across multiple services.

According this User object in Azure AD has the following properties:

accountEnabled, ageGroup, assignedLicenses, assignedPlans, assignedPlans, assignedPlans, businessPhones, city, companyName, consentProvidedForMinor, country, createdDateTime, createdObjects, creationType, department, displayName, employeeHireDate, employeeId, employeeOrgData, employeeOrgData, employeeType, externalUserState, faxNumber, givenName, identities, imAddresses, isResourceAccount, jobTitle, mail, mailNickname, manager, mobilePhone, officeLocation, onPremisesExtensionAttributes, onPremisesImmutableId, onPremisesLastSyncDateTime, onPremisesProvisioningErrors, onPremisesProvisioningErrors, onPremisesSamAccountName, onPremisesSecurityIdentifier, onPremisesSyncEnabled, otherMails, passwordPolicies, passwordProfile, postalCode, preferredLanguage, provisionedPlans, ,provisionedPlans proxyAddresses, showInAddressList, state, streetAddress, surname, usageLocation, userPrincipalName, userType

When updating User, those properties cannot be updated together with Sharepoint Online properties.

aboutMe, birthday, hireDate, interests, mySite, pastProjects, preferredName, responsibilities, schools, skills

user2250152
  • 14,658
  • 4
  • 33
  • 57
  • This can be done with User.ReadWrite.All, Sites.ReadWrite.All application permissions. I think the documentation is missing a lot of nuances – DimaBond Feb 03 '22 at 10:55
  • 2
    @DimaBond Looks like the doc is not up to date or it can be bug. – user2250152 Feb 03 '22 at 11:01
  • It's a docs issue. Because behind graph those attributes live in SharePoint you need the Sites permission in order to be able to update them. This is undocumented and annoying. – Chris Johnson Feb 05 '22 at 22:26
  • Perhaps you `re right. Since I never found out whether this is true or not and why it works this way, your answer is the closest to the truth. Thanks for the help ) – DimaBond Feb 07 '22 at 12:44