POST /me/contacts
POST /users/{id | userPrincipalName}/contacts
POST /me/contactFolders/{contactFolderId}/contacts
POST /users/{id | userPrincipalName}/contactFolders/{contactFolderId}/contacts
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new Contact
{
GivenName = "Pavel",
Surname = "Bansky",
EmailAddresses = new List<TypedEmailAddress>
{
new TypedEmailAddress
{
Address = "pavelb@contoso.com",
Name = "Pavel Bansky",
Type = EmailType.Personal,
},
new TypedEmailAddress
{
Address = "pavelb@contoso.com",
Name = "Pavel Bansky",
Type = EmailType.Other,
OtherLabel = "Volunteer work",
},
},
Phones = new List<Phone>
{
new Phone
{
Number = "+1 732 555 0102",
Type = PhoneType.Business,
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Me.Contacts.PostAsync(requestBody);
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Contact contact = new Contact();
contact.setGivenName("Pavel");
contact.setSurname("Bansky");
LinkedList<TypedEmailAddress> emailAddresses = new LinkedList<TypedEmailAddress>();
TypedEmailAddress typedEmailAddress = new TypedEmailAddress();
typedEmailAddress.setAddress("pavelb@contoso.com");
typedEmailAddress.setName("Pavel Bansky");
typedEmailAddress.setType(EmailType.Personal);
emailAddresses.add(typedEmailAddress);
TypedEmailAddress typedEmailAddress1 = new TypedEmailAddress();
typedEmailAddress1.setAddress("pavelb@contoso.com");
typedEmailAddress1.setName("Pavel Bansky");
typedEmailAddress1.setType(EmailType.Other);
typedEmailAddress1.setOtherLabel("Volunteer work");
emailAddresses.add(typedEmailAddress1);
contact.setEmailAddresses(emailAddresses);
LinkedList<Phone> phones = new LinkedList<Phone>();
Phone phone = new Phone();
phone.setNumber("+1 732 555 0102");
phone.setType(PhoneType.Business);
phones.add(phone);
contact.setPhones(phones);
Contact result = graphClient.me().contacts().post(contact);
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.contact import Contact
from msgraph_beta.generated.models.typed_email_address import TypedEmailAddress
from msgraph_beta.generated.models.email_type import EmailType
from msgraph_beta.generated.models.phone import Phone
from msgraph_beta.generated.models.phone_type import PhoneType
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Contact(
given_name = "Pavel",
surname = "Bansky",
email_addresses = [
TypedEmailAddress(
address = "pavelb@contoso.com",
name = "Pavel Bansky",
type = EmailType.Personal,
),
TypedEmailAddress(
address = "pavelb@contoso.com",
name = "Pavel Bansky",
type = EmailType.Other,
other_label = "Volunteer work",
),
],
phones = [
Phone(
number = "+1 732 555 0102",
type = PhoneType.Business,
),
],
)
result = await graph_client.me.contacts.post(request_body)