Trev
Trev

Reputation: 63

Update Contact using Microsoft Graph Client Library

How do you update a Contact using the Microsoft Graph Client Library (v1.5)? I cannot find any documentation on the project page or via Google.

In the sample code below I want to set the SpouseName for all Contacts to "Single". I have no idea how to commit the change.

_graphClient = new GraphServiceClient(_Authenticator);

            var request = _graphClient.Me.Contacts.Request();
            var contacts = await request.GetAsync();

            while (contacts.Count > 0)
            {
                foreach (var ct in contacts)
                {
                    ct.SpouseName = "Single"; 
                    //
                    // how do you commit this change?
                    //
                }
                if (contacts.NextPageRequest != null)
                {
                    contacts = await contacts.NextPageRequest.GetAsync();
                }
                else
                {
                    break;
                }

            }

Upvotes: 2

Views: 231

Answers (1)

Marc LaFleur
Marc LaFleur

Reputation: 33094

You use the UpdateAsync() method:

await graphClient.Me.Contacts["id"].Request().UpdateAsync(new Contact()
{
    SpouseName = "Single"
});

Note that you only pass in the property you want to change. Do not pass the entire Contact object you previously retrieved.

Upvotes: 2

Related Questions