命名空间:microsoft.graph
更新 contact 对象的属性。
此 API 可用于以下国家级云部署。
全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
✅ |
✅ |
✅ |
✅ |
权限
要调用此 API,需要以下权限之一。 若要了解详细信息,包括如何选择权限的信息,请参阅权限。
权限类型 |
权限(从最低特权到最高特权) |
委派(工作或学校帐户) |
Contacts.ReadWrite |
委派(个人 Microsoft 帐户) |
Contacts.ReadWrite |
应用程序 |
Contacts.ReadWrite |
HTTP 请求
来自用户的默认 contactFolder 中的 联系人。
PATCH /me/contacts/{id}
PATCH /users/{id | userPrincipalName}/contacts/{id}
来自用户的顶级 contactFolder 中的 联系人。
PATCH /me/contactFolders/{id}/contacts/{id}
PATCH /users/{id | userPrincipalName}/contactFolders/{id}/contacts/{id}
contactFolder 的子文件夹中包含的 联系人。 下面的示例显示了一个嵌套级别,但联系人可能位于子级的子级中,诸如此类。
PATCH /me/contactFolders/{id}/childFolders/{id}/.../contacts/{id}
PATCH /users/{id | userPrincipalName}/contactFolders/{id}/childFolders/{id}/contacts/{id}
标头 |
值 |
Authorization |
持有者 {token}。 必填。 详细了解 身份验证和授权。 |
Content-Type |
application/json. 必需。 |
请求正文
在请求正文中,提供应更新的相关字段的值。 请求正文中未包含的现有属性会保留其以前的值,或者根据对其他属性值的更改重新计算。 为了获得最佳性能,请勿加入尚未更改的现有值。
更新结构化属性(如 homeAddress)时,必须传递完整的属性集。
属性 |
类型 |
说明 |
assistantName |
String |
联系人助理的姓名。 |
birthday |
DateTimeOffset |
联系人的生日。 |
businessAddress |
PhysicalAddress |
联系人的公司地址。 |
businessHomePage |
String |
联系人的公司主页。 |
businessPhones |
String |
联系人的公司电话号码。 |
categories |
String |
与联系人关联的类别。 |
children |
String |
联系人子女的姓名。 |
CompanyName |
String |
联系人所在公司的名称。 |
department |
String |
联系人所在的部门。 |
displayName |
String |
联系人的显示名称。 请注意,对其他属性的后续更新可能会导致自动生成的值覆盖你指定的 displayName 值。 若要保留预先存在的值,请始终在更新操作中将其作为 displayName。 |
emailAddresses |
EmailAddress 集合 |
联系人的电子邮件地址。 |
fileAs |
String |
联系人备案的姓名。 |
generation |
String |
联系人所属的代。 |
givenName |
String |
联系人的名。 |
homeAddress |
PhysicalAddress |
联系人的住宅地址。 |
homePhones |
String collection |
联系人的住宅电话号码。 |
imAddresses |
String |
联系人的即时消息 (IM) 地址。 |
initials |
String |
联系人的姓名缩写。 |
jobTitle |
String |
联系人的职务。 |
manager |
String |
联系人经理的姓名。 |
middleName |
String |
联系人的中间名。 |
mobilePhone |
String |
联系人的移动电话号码。 |
nickName |
String |
联系人的昵称。 |
officeLocation |
String |
联系人的办公室位置。 |
otherAddress |
PhysicalAddress |
联系人的其他地址。 |
parentFolderId |
String |
联系人的父文件夹 ID。 |
personalNotes |
String |
有关联系人的用户备注。 |
profession |
String |
联系人的职业。 |
spouseName |
String |
联系人配偶/伴侣的姓名。 |
surname |
String |
联系人的姓氏。 |
title |
String |
联系人的职位。 |
yomiCompanyName |
String |
联系人的注音日文公司名称。 此属性是可选的。 |
yomiGivenName |
String |
联系人的注音日文名字。 此属性是可选的。 |
yomiSurname |
String |
日语拼音姓氏 (联系人) 。 此属性可选。 |
响应
如果成功,此方法在响应正文中返回 200 OK
响应代码和更新的 contact 对象。
示例
请求
以下示例显示了一个请求。
PATCH https://graph.microsoft.com/v1.0/me/contacts/{id}
Content-type: application/json
{
"homeAddress": {
"street": "123 Some street",
"city": "Seattle",
"state": "WA",
"postalCode": "98121"
},
"birthday": "1974-07-22"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new Contact
{
HomeAddress = new PhysicalAddress
{
Street = "123 Some street",
City = "Seattle",
State = "WA",
PostalCode = "98121",
},
Birthday = DateTimeOffset.Parse("1974-07-22"),
};
// 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["{contact-id}"].PatchAsync(requestBody);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
mgc users contacts patch --user-id {user-id} --contact-id {contact-id} --body '{\
"homeAddress": {\
"street": "123 Some street",\
"city": "Seattle",\
"state": "WA",\
"postalCode": "98121"\
},\
"birthday": "1974-07-22"\
}\
'
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
"time"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewContact()
homeAddress := graphmodels.NewPhysicalAddress()
street := "123 Some street"
homeAddress.SetStreet(&street)
city := "Seattle"
homeAddress.SetCity(&city)
state := "WA"
homeAddress.SetState(&state)
postalCode := "98121"
homeAddress.SetPostalCode(&postalCode)
requestBody.SetHomeAddress(homeAddress)
birthday , err := time.Parse(time.RFC3339, "1974-07-22")
requestBody.SetBirthday(&birthday)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
contacts, err := graphClient.Me().Contacts().ByContactId("contact-id").Patch(context.Background(), requestBody, nil)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Contact contact = new Contact();
PhysicalAddress homeAddress = new PhysicalAddress();
homeAddress.setStreet("123 Some street");
homeAddress.setCity("Seattle");
homeAddress.setState("WA");
homeAddress.setPostalCode("98121");
contact.setHomeAddress(homeAddress);
OffsetDateTime birthday = OffsetDateTime.parse("1974-07-22");
contact.setBirthday(birthday);
Contact result = graphClient.me().contacts().byContactId("{contact-id}").patch(contact);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
const options = {
authProvider,
};
const client = Client.init(options);
const contact = {
homeAddress: {
street: '123 Some street',
city: 'Seattle',
state: 'WA',
postalCode: '98121'
},
birthday: '1974-07-22'
};
await client.api('/me/contacts/{id}')
.update(contact);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Models\Contact;
use Microsoft\Graph\Generated\Models\PhysicalAddress;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Contact();
$homeAddress = new PhysicalAddress();
$homeAddress->setStreet('123 Some street');
$homeAddress->setCity('Seattle');
$homeAddress->setState('WA');
$homeAddress->setPostalCode('98121');
$requestBody->setHomeAddress($homeAddress);
$requestBody->setBirthday(new \DateTime('1974-07-22'));
$result = $graphServiceClient->me()->contacts()->byContactId('contact-id')->patch($requestBody)->wait();
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
Import-Module Microsoft.Graph.PersonalContacts
$params = @{
homeAddress = @{
street = "123 Some street"
city = "Seattle"
state = "WA"
postalCode = "98121"
}
birthday = [System.DateTime]::Parse("1974-07-22")
}
# A UPN can also be used as -UserId.
Update-MgUserContact -UserId $userId -ContactId $contactId -BodyParameter $params
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
# 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
from msgraph.generated.models.physical_address import PhysicalAddress
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Contact(
home_address = PhysicalAddress(
street = "123 Some street",
city = "Seattle",
state = "WA",
postal_code = "98121",
),
birthday = "1974-07-22",
)
result = await graph_client.me.contacts.by_contact_id('contact-id').patch(request_body)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
响应
以下示例显示了相应的响应。
注意:为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Content-type: application/json
{
"id": "AAMkAGI2THk0AAA=",
"createdDateTime": "2014-10-19T23:08:24Z",
"lastModifiedDateTime": "2014-10-19T23:08:24Z",
"changeKey": "EQAAABYAAACd9nJ/tVysQos2hTfspaWRAAADTIa4",
"categories": [],
"parentFolderId": "AAMkAGI2AAEOAAA=",
"birthday": "1974-07-22",
"fileAs": "Fort, Garth",
"displayName": "Garth Fort",
"givenName": "Garth",
"initials": "G.F.",
"middleName": null,
"nickName": "Garth",
"surname": "Fort",
"title": null,
"yomiGivenName": null,
"yomiSurname": null,
"yomiCompanyName": null,
"generation": null,
"emailAddresses": [
{
"name": "Garth",
"address": "garth@contoso.com"
}
],
"imAddresses": [
"sip:garthf@contoso.com"
],
"jobTitle": "Web Marketing Manager",
"companyName": "Contoso, Inc.",
"department": "Sales & Marketing",
"officeLocation": "20/1101",
"profession": null,
"businessHomePage": "https://www.contoso.com",
"assistantName": null,
"manager": null,
"homePhones": [],
"mobilePhone": null,
"businessPhones": [
"+1 918 555 0101"
],
"homeAddress": {
"street": "123 Some street",
"city": "Seattle",
"state": "WA",
"postalCode": "98121"
},
"businessAddress": {
"street": "10 Contoso Way",
"city": "Redmond",
"state": "WA",
"countryOrRegion": "USA",
"postalCode": "98075"
},
"otherAddress": {},
"spouseName": null,
"personalNotes": null,
"children": []
}