APIs under the /beta version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. To determine whether an API is available in v1.0, use the Version selector.
Add a contact to the root Contacts folder or to the contacts endpoint of another contact folder.
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions.
Permission type
Permissions (from least to most privileged)
Delegated (work or school account)
Contacts.ReadWrite
Delegated (personal Microsoft account)
Contacts.ReadWrite
Application
Contacts.ReadWrite
HTTP request
POST /me/contacts
POST /users/{id | userPrincipalName}/contacts
POST /me/contactFolders/{contactFolderId}/contacts
POST /users/{id | userPrincipalName}/contactFolders/{contactFolderId}/contacts
Request headers
Header
Value
Authorization
Bearer {token}. Required.
Content-Type
application/json
Request body
In the request body, supply a JSON representation of contact object.
Response
If successful, this method returns 201 Created response code and contact object in the response body.
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var contact = new Contact
{
GivenName = "Pavel",
Surname = "Bansky",
EmailAddresses = new List<TypedEmailAddress>()
{
new TypedEmailAddress
{
Address = "pavelb@contoso.onmicrosoft.com",
Name = "Pavel Bansky",
Type = EmailType.Personal
},
new TypedEmailAddress
{
Address = "pavelb@fabrikam.onmicrosoft.com",
Name = "Pavel Bansky",
Type = EmailType.Other,
OtherLabel = "Volunteer work"
}
},
Phones = new List<Phone>()
{
new Phone
{
Number = "+1 732 555 0102",
Type = PhoneType.Business
}
}
};
await graphClient.Me.Contacts
.Request()
.AddAsync(contact);
Important
Microsoft Graph SDKs use the v1.0 version of the API by default, and do not support all the types, properties, and APIs available in the beta version. For details about accessing the beta API with the SDK, see Use the Microsoft Graph SDKs with the beta API.
Microsoft Graph SDKs use the v1.0 version of the API by default, and do not support all the types, properties, and APIs available in the beta version. For details about accessing the beta API with the SDK, see Use the Microsoft Graph SDKs with the beta API.
Microsoft Graph SDKs use the v1.0 version of the API by default, and do not support all the types, properties, and APIs available in the beta version. For details about accessing the beta API with the SDK, see Use the Microsoft Graph SDKs with the beta API.
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := graphmodels.NewContact()
givenName := "Pavel"
requestBody.SetGivenName(&givenName)
surname := "Bansky"
requestBody.SetSurname(&surname)
typedEmailAddress := graphmodels.NewTypedEmailAddress()
address := "pavelb@contoso.onmicrosoft.com"
typedEmailAddress.SetAddress(&address)
name := "Pavel Bansky"
typedEmailAddress.SetName(&name)
type := graphmodels.PERSONAL_EMAILTYPE
typedEmailAddress.SetType(&type)
typedEmailAddress1 := graphmodels.NewTypedEmailAddress()
address := "pavelb@fabrikam.onmicrosoft.com"
typedEmailAddress1.SetAddress(&address)
name := "Pavel Bansky"
typedEmailAddress1.SetName(&name)
type := graphmodels.OTHER_EMAILTYPE
typedEmailAddress1.SetType(&type)
otherLabel := "Volunteer work"
typedEmailAddress1.SetOtherLabel(&otherLabel)
emailAddresses := []graphmodels.Objectable {
typedEmailAddress,
typedEmailAddress1,
}
requestBody.SetEmailAddresses(emailAddresses)
phone := graphmodels.NewPhone()
number := "+1 732 555 0102"
phone.SetNumber(&number)
type := graphmodels.BUSINESS_PHONETYPE
phone.SetType(&type)
phones := []graphmodels.Phoneable {
phone,
}
requestBody.SetPhones(phones)
result, err := graphClient.Me().Contacts().Post(requestBody)
Important
Microsoft Graph SDKs use the v1.0 version of the API by default, and do not support all the types, properties, and APIs available in the beta version. For details about accessing the beta API with the SDK, see Use the Microsoft Graph SDKs with the beta API.
Import-Module Microsoft.Graph.PersonalContacts
$params = @{
GivenName = "Pavel"
Surname = "Bansky"
EmailAddresses = @(
@{
Address = "pavelb@contoso.onmicrosoft.com"
Name = "Pavel Bansky"
Type = "personal"
}
@{
Address = "pavelb@fabrikam.onmicrosoft.com"
Name = "Pavel Bansky"
Type = "other"
OtherLabel = "Volunteer work"
}
)
Phones = @(
@{
Number = "+1 732 555 0102"
Type = "business"
}
)
}
# A UPN can also be used as -UserId.
New-MgUserContact -UserId $userId -BodyParameter $params
Important
Microsoft Graph SDKs use the v1.0 version of the API by default, and do not support all the types, properties, and APIs available in the beta version. For details about accessing the beta API with the SDK, see Use the Microsoft Graph SDKs with the beta API.
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new Contact();
$requestBody->setGivenName('Pavel');
$requestBody->setSurname('Bansky');
$emailAddressesTypedEmailAddress1 = new TypedEmailAddress();
$emailAddressesTypedEmailAddress1->setAddress('pavelb@contoso.onmicrosoft.com');
$emailAddressesTypedEmailAddress1->setName('Pavel Bansky');
$emailAddressesTypedEmailAddress1->setType(new EmailType('personal'));
$emailAddressesArray []= $emailAddressesTypedEmailAddress1;
$emailAddressesTypedEmailAddress2 = new TypedEmailAddress();
$emailAddressesTypedEmailAddress2->setAddress('pavelb@fabrikam.onmicrosoft.com');
$emailAddressesTypedEmailAddress2->setName('Pavel Bansky');
$emailAddressesTypedEmailAddress2->setType(new EmailType('other'));
$emailAddressesTypedEmailAddress2->setOtherLabel('Volunteer work');
$emailAddressesArray []= $emailAddressesTypedEmailAddress2;
$requestBody->setEmailAddresses($emailAddressesArray);
$phonesPhone1 = new Phone();
$phonesPhone1->setNumber('+1 732 555 0102');
$phonesPhone1->setType(new PhoneType('business'));
$phonesArray []= $phonesPhone1;
$requestBody->setPhones($phonesArray);
$requestResult = $graphServiceClient->me()->contacts()->post($requestBody);
Important
Microsoft Graph SDKs use the v1.0 version of the API by default, and do not support all the types, properties, and APIs available in the beta version. For details about accessing the beta API with the SDK, see Use the Microsoft Graph SDKs with the beta API.