L’une des autorisations suivantes est nécessaire pour appeler cette API. Pour plus d’informations, notamment sur la façon de choisir les autorisations, voir Autorisations.
Type d’autorisation
Autorisations (de celle qui offre le plus de privilèges à celle qui en offre le moins)
Déléguée (compte professionnel ou scolaire)
Contacts.ReadWrite
Déléguée (compte Microsoft personnel)
Contacts.ReadWrite
Application
Contacts.ReadWrite
Requête HTTP
POST /me/contacts
POST /users/{id | userPrincipalName}/contacts
POST /me/contactFolders/{id}/contacts
POST /users/{id | userPrincipalName}/contactFolders/{id}/contacts
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new Contact
{
ParentFolderId = "parentFolderId-value",
Birthday = DateTimeOffset.Parse("datetime-value"),
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 version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Contact contact = new Contact();
contact.setParentFolderId("parentFolderId-value");
OffsetDateTime birthday = OffsetDateTime.parse("datetime-value");
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);
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.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 = "datetime-value",
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)