Namespace: microsoft.graph
Importante
As APIs na versão /beta no Microsoft Graph estão sujeitas a alterações. Não há suporte para o uso dessas APIs em aplicativos de produção. Para determinar se uma API está disponível na v1.0, use o seletor Versão.
Adicione um contato na pasta de contatos raiz ou no ponto de extremidade do contacts de outra pasta de contatos.
Esta API está disponível nas seguintes implementações de cloud nacionais.
| Serviço global |
US Government L4 |
US Government L5 (DOD) |
China operada pela 21Vianet |
| ✅ |
✅ |
✅ |
✅ |
Permissões
Uma das seguintes permissões é necessária para chamar esta API. Para saber mais, incluindo como escolher permissões, confira Permissões.
| Tipo de permissão |
Permissões (da com menos para a com mais privilégios) |
| Delegado (conta corporativa ou de estudante) |
Contacts.ReadWrite |
| Delegado (conta pessoal da Microsoft) |
Contacts.ReadWrite |
| Aplicativo |
Contacts.ReadWrite |
Solicitação HTTP
POST /me/contacts
POST /users/{id | userPrincipalName}/contacts
POST /me/contactFolders/{id}/contacts
POST /users/{id | userPrincipalName}/contactFolders/{id}/contacts
| Cabeçalho |
Valor |
| Autorização |
{token} de portador. Obrigatório. Saiba mais sobre autenticação e autorização. |
| Content-Type |
application/json. Obrigatório. |
Corpo da solicitação
No corpo da solicitação, forneça uma representação JSON do objeto Contact.
Resposta
Se bem-sucedido, este método retorna um código de resposta 201 Created e um objeto Contact no corpo da resposta.
Exemplo
Solicitação
O exemplo a seguir mostra uma solicitação.
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)
No corpo da solicitação, forneça uma representação JSON do objeto contact.
Resposta
O exemplo a seguir mostra a resposta. Observação: o objeto de resposta mostrado aqui pode ser encurtado para legibilidade.
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"
}