本文内容
命名空间:microsoft.graph
将联系人添加到联系人根文件夹或其他联系人文件夹的 contacts 终结点中。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限 。
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
Contacts.ReadWrite
委派(个人 Microsoft 帐户)
Contacts.ReadWrite
应用程序
Contacts.ReadWrite
HTTP 请求
POST /me/contacts
POST /users/{id | userPrincipalName}/contacts
POST /me/contactFolders/{id}/contacts
POST /users/{id | userPrincipalName}/contactFolders/{id}/contacts
标头
值
Authorization
Bearer {token}。必需。
Content-Type
application/json. Required.
请求正文
在请求正文中,提供 JSON 表示形式的 Contact 对象。
响应
如果成功,此方法在响应正文中返回 201 Created 响应代码和 Contact 对象。
示例
请求
下面是一个请求示例。
POST https://graph.microsoft.com/v1.0/me/contactFolders/{id}/contacts
Content-type: application/json
{
"parentFolderId": "parentFolderId-value",
"birthday": "datetime-value",
"fileAs": "fileAs-value",
"displayName": "displayName-value",
"givenName": "givenName-value",
"initials": "initials-value"
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var contact = new Contact
{
ParentFolderId = "parentFolderId-value",
Birthday = DateTimeOffset.Parse("datetime-value"),
FileAs = "fileAs-value",
DisplayName = "displayName-value",
GivenName = "givenName-value",
Initials = "initials-value"
};
await graphClient.Me.ContactFolders["{contactFolder-id}"].Contacts
.Request()
.AddAsync(contact);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
const options = {
authProvider,
};
const client = Client.init(options);
const contact = {
parentFolderId: 'parentFolderId-value',
birthday: 'datetime-value',
fileAs: 'fileAs-value',
displayName: 'displayName-value',
givenName: 'givenName-value',
initials: 'initials-value'
};
await client.api('/me/contactFolders/{id}/contacts')
.post(contact);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/contactFolders/{id}/contacts"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphContact *contact = [[MSGraphContact alloc] init];
[contact setParentFolderId:@"parentFolderId-value"];
[contact setBirthday:@"datetime-value"];
[contact setFileAs:@"fileAs-value"];
[contact setDisplayName:@"displayName-value"];
[contact setGivenName:@"givenName-value"];
[contact setInitials:@"initials-value"];
NSError *error;
NSData *contactData = [contact getSerializedDataWithError:&error];
[urlRequest setHTTPBody:contactData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Contact contact = new Contact();
contact.parentFolderId = "parentFolderId-value";
contact.birthday = OffsetDateTimeSerializer.deserialize("datetime-value");
contact.fileAs = "fileAs-value";
contact.displayName = "displayName-value";
contact.givenName = "givenName-value";
contact.initials = "initials-value";
graphClient.me().contactFolders("{id}").contacts()
.buildRequest()
.post(contact);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewContact()
parentFolderId := "parentFolderId-value"
requestBody.SetParentFolderId(&parentFolderId)
birthday, err := time.Parse(time.RFC3339, "datetime-value")
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)
contactFolderId := "contactFolder-id"
result, err := graphClient.Me().ContactFoldersById(&contactFolderId).Contacts().Post(requestBody)
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
Import-Module Microsoft.Graph.PersonalContacts
$params = @{
ParentFolderId = "parentFolderId-value"
Birthday = [System.DateTime]::Parse("datetime-value")
FileAs = "fileAs-value"
DisplayName = "displayName-value"
GivenName = "givenName-value"
Initials = "initials-value"
}
# A UPN can also be used as -UserId.
New-MgUserContactFolderContact -UserId $userId -ContactFolderId $contactFolderId -BodyParameter $params
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
在请求正文中,提供 JSON 表示形式的 Contact 对象。
响应
下面是一个响应示例。
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Content-type: application/json
{
"parentFolderId": "parentFolderId-value",
"birthday": "datetime-value",
"fileAs": "fileAs-value",
"displayName": "displayName-value",
"givenName": "givenName-value",
"initials": "initials-value"
}