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.
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
// 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);
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.
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewContact()
givenName := "Pavel"
requestBody.SetGivenName(&givenName)
surname := "Bansky"
requestBody.SetSurname(&surname)
typedEmailAddress := graphmodels.NewTypedEmailAddress()
address := "pavelb@contoso.com"
typedEmailAddress.SetAddress(&address)
name := "Pavel Bansky"
typedEmailAddress.SetName(&name)
type := graphmodels.PERSONAL_EMAILTYPE
typedEmailAddress.SetType(&type)
typedEmailAddress1 := graphmodels.NewTypedEmailAddress()
address := "pavelb@contoso.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.TypedEmailAddressable {
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)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
contacts, err := graphClient.Me().Contacts().Post(context.Background(), requestBody, nil)
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.
// 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);
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.
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\Contact;
use Microsoft\Graph\Beta\Generated\Models\TypedEmailAddress;
use Microsoft\Graph\Beta\Generated\Models\EmailType;
use Microsoft\Graph\Beta\Generated\Models\Phone;
use Microsoft\Graph\Beta\Generated\Models\PhoneType;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Contact();
$requestBody->setGivenName('Pavel');
$requestBody->setSurname('Bansky');
$emailAddressesTypedEmailAddress1 = new TypedEmailAddress();
$emailAddressesTypedEmailAddress1->setAddress('pavelb@contoso.com');
$emailAddressesTypedEmailAddress1->setName('Pavel Bansky');
$emailAddressesTypedEmailAddress1->setType(new EmailType('personal'));
$emailAddressesArray []= $emailAddressesTypedEmailAddress1;
$emailAddressesTypedEmailAddress2 = new TypedEmailAddress();
$emailAddressesTypedEmailAddress2->setAddress('pavelb@contoso.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);
$result = $graphServiceClient->me()->contacts()->post($requestBody)->wait();
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.Beta.PersonalContacts
$params = @{
givenName = "Pavel"
surname = "Bansky"
emailAddresses = @(
@{
address = "pavelb@contoso.com"
name = "Pavel Bansky"
type = "personal"
}
@{
address = "pavelb@contoso.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-MgBetaUserContact -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.
# 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)
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.