Reputation: 63
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
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