Namespace: microsoft.graph
Important
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.
This API is available in the following national cloud deployments.
Global service |
US Government L4 |
US Government L5 (DOD) |
China operated by 21Vianet |
✅ |
✅ |
✅ |
✅ |
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/{id}/contacts
POST /users/{id | userPrincipalName}/contactFolders/{id}/contacts
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.
Example
Request
The following example shows a request.
POST https://graph.microsoft.com/beta/me/contactFolders/{id}/contacts
Content-type: application/json
{
"parentFolderId": "parentFolderId-value",
"birthday": "2016-10-19T10:37:00Z",
"fileAs": "fileAs-value",
"displayName": "displayName-value",
"givenName": "givenName-value",
"initials": "initials-value"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new Contact
{
ParentFolderId = "parentFolderId-value",
Birthday = DateTimeOffset.Parse("2016-10-19T10:37:00Z"),
FileAs = "fileAs-value",
DisplayName = "displayName-value",
GivenName = "givenName-value",
Initials = "initials-value",
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Me.ContactFolders["{contactFolder-id}"].Contacts.PostAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
"time"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewContact()
parentFolderId := "parentFolderId-value"
requestBody.SetParentFolderId(&parentFolderId)
birthday , err := time.Parse(time.RFC3339, "2016-10-19T10:37:00Z")
requestBody.SetBirthday(&birthday)
fileAs := "fileAs-value"
requestBody.SetFileAs(&fileAs)
displayName := "displayName-value"
requestBody.SetDisplayName(&displayName)
givenName := "givenName-value"
requestBody.SetGivenName(&givenName)
initials := "initials-value"
requestBody.SetInitials(&initials)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
contacts, err := graphClient.Me().ContactFolders().ByContactFolderId("contactFolder-id").Contacts().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Contact contact = new Contact();
contact.setParentFolderId("parentFolderId-value");
OffsetDateTime birthday = OffsetDateTime.parse("2016-10-19T10:37:00Z");
contact.setBirthday(birthday);
contact.setFileAs("fileAs-value");
contact.setDisplayName("displayName-value");
contact.setGivenName("givenName-value");
contact.setInitials("initials-value");
Contact result = graphClient.me().contactFolders().byContactFolderId("{contactFolder-id}").contacts().post(contact);
const options = {
authProvider,
};
const client = Client.init(options);
const contact = {
parentFolderId: 'parentFolderId-value',
birthday: '2016-10-19T10:37:00Z',
fileAs: 'fileAs-value',
displayName: 'displayName-value',
givenName: 'givenName-value',
initials: 'initials-value'
};
await client.api('/me/contactFolders/{id}/contacts')
.version('beta')
.post(contact);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\Contact;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Contact();
$requestBody->setParentFolderId('parentFolderId-value');
$requestBody->setBirthday(new \DateTime('2016-10-19T10:37:00Z'));
$requestBody->setFileAs('fileAs-value');
$requestBody->setDisplayName('displayName-value');
$requestBody->setGivenName('givenName-value');
$requestBody->setInitials('initials-value');
$result = $graphServiceClient->me()->contactFolders()->byContactFolderId('contactFolder-id')->contacts()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.PersonalContacts
$params = @{
parentFolderId = "parentFolderId-value"
birthday = [System.DateTime]::Parse("2016-10-19T10:37:00Z")
fileAs = "fileAs-value"
displayName = "displayName-value"
givenName = "givenName-value"
initials = "initials-value"
}
# A UPN can also be used as -UserId.
New-MgBetaUserContactFolderContact -UserId $userId -ContactFolderId $contactFolderId -BodyParameter $params
# 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
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Contact(
parent_folder_id = "parentFolderId-value",
birthday = "2016-10-19T10:37:00Z",
file_as = "fileAs-value",
display_name = "displayName-value",
given_name = "givenName-value",
initials = "initials-value",
)
result = await graph_client.me.contact_folders.by_contact_folder_id('contactFolder-id').contacts.post(request_body)
In the request body, supply a JSON representation of contact object.
Response
The following example shows the response. Note: The response object shown here might be shortened for readability.
HTTP/1.1 200 OK
Content-type: application/json
{
"parentFolderId": "parentFolderId-value",
"birthday": "2016-10-19T10:37:00Z",
"fileAs": "fileAs-value",
"displayName": "displayName-value",
"givenName": "givenName-value",
"initials": "initials-value"
}