创建地址
命名空间:microsoft.graph
在用户配置文件 中创建新的 itemAddress 对象。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限。
| 权限类型 |
权限(从最低特权到最高特权) |
| 委派(工作或学校帐户) |
User.ReadWrite、User.ReadWrite.All |
| 委派(个人 Microsoft 帐户) |
User.ReadWrite、User.ReadWrite.All |
| 应用程序 |
User.ReadWrite.All |
HTTP 请求
POST /me/profile/addresses
POST /users/{id | userPrincipalName}/profile/addresses
| 名称 |
说明 |
| Authorization |
Bearer {token}。必需。 |
| Content-Type |
application/json. Required. |
请求正文
在请求正文中,提供 itemAddress 对象的 JSON 表示形式。
下表显示了在用户配置文件中创建新的 itemAddress 对象时可以设置 的属性。
响应
如果成功,此方法在响应正文中返回 响应代码和 201 Created itemAddress 对象。
示例
POST https://graph.microsoft.com/beta/me/profile/addresses
Content-Type: application/json
{
"displayName": "Home",
"detail": {
"type": "home",
"postOfficeBox": null,
"street": "221B Baker Street",
"city": "London",
"state": null,
"countryOrRegion": "United Kingdom",
"postalCode": "E14 3TD"
}
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var itemAddress = new ItemAddress
{
DisplayName = "Home",
Detail = new PhysicalAddress
{
Type = PhysicalAddressType.Home,
PostOfficeBox = null,
Street = "221B Baker Street",
City = "London",
State = null,
CountryOrRegion = "United Kingdom",
PostalCode = "E14 3TD"
}
};
await graphClient.Me.Profile.Addresses
.Request()
.AddAsync(itemAddress);
const options = {
authProvider,
};
const client = Client.init(options);
const itemAddress = {
displayName: 'Home',
detail: {
type: 'home',
postOfficeBox: null,
street: '221B Baker Street',
city: 'London',
state: null,
countryOrRegion: 'United Kingdom',
postalCode: 'E14 3TD'
}
};
await client.api('/me/profile/addresses')
.version('beta')
.post(itemAddress);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/profile/addresses"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphItemAddress *itemAddress = [[MSGraphItemAddress alloc] init];
[itemAddress setDisplayName:@"Home"];
MSGraphPhysicalAddress *detail = [[MSGraphPhysicalAddress alloc] init];
[detail setType: [MSGraphPhysicalAddressType home]];
[detail setPostOfficeBox: null];
[detail setStreet:@"221B Baker Street"];
[detail setCity:@"London"];
[detail setState: null];
[detail setCountryOrRegion:@"United Kingdom"];
[detail setPostalCode:@"E14 3TD"];
[itemAddress setDetail:detail];
NSError *error;
NSData *itemAddressData = [itemAddress getSerializedDataWithError:&error];
[urlRequest setHTTPBody:itemAddressData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
ItemAddress itemAddress = new ItemAddress();
itemAddress.displayName = "Home";
PhysicalAddress detail = new PhysicalAddress();
detail.type = PhysicalAddressType.HOME;
detail.postOfficeBox = null;
detail.street = "221B Baker Street";
detail.city = "London";
detail.state = null;
detail.countryOrRegion = "United Kingdom";
detail.postalCode = "E14 3TD";
itemAddress.detail = detail;
graphClient.me().profile().addresses()
.buildRequest()
.post(itemAddress);
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewItemAddress()
displayName := "Home"
requestBody.SetDisplayName(&displayName)
detail := msgraphsdk.NewPhysicalAddress()
requestBody.SetDetail(detail)
type := "home"
detail.SetType(&type)
detail.SetPostOfficeBox(nil)
street := "221B Baker Street"
detail.SetStreet(&street)
city := "London"
detail.SetCity(&city)
detail.SetState(nil)
countryOrRegion := "United Kingdom"
detail.SetCountryOrRegion(&countryOrRegion)
postalCode := "E14 3TD"
detail.SetPostalCode(&postalCode)
result, err := graphClient.Me().Profile().Addresses().Post(requestBody)
Import-Module Microsoft.Graph.People
$params = @{
DisplayName = "Home"
Detail = @{
Type = "home"
PostOfficeBox = $null
Street = "221B Baker Street"
City = "London"
State = $null
CountryOrRegion = "United Kingdom"
PostalCode = "E14 3TD"
}
}
# A UPN can also be used as -UserId.
New-MgUserProfileAddress -UserId $userId -BodyParameter $params
响应
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-Type: application/json
{
"id": "0fb4c1e3-c1e3-0fb4-e3c1-b40fe3c1b40f",
"allowedAudiences": "organization",
"inference": null,
"createdDateTime": "2020-07-06T06:34:12.2294868Z",
"createdBy": {
"application": null,
"device": null,
"user": {
"displayName": "Innocenty Popov",
"id": "db789417-4ccb-41d1-a0a9-47b01a09ea49"
}
},
"lastModifiedDateTime": "2020-07-06T06:34:12.2294868Z",
"lastModifiedBy": {
"application": null,
"device": null,
"user": {
"displayName": "Innocenty Popov",
"id": "db789417-4ccb-41d1-a0a9-47b01a09ea49"
}
},
"source": null,
"displayName": "Home",
"detail": {
"type": "home",
"postOfficeBox": null,
"street": "221B Baker Street",
"city": "London",
"state": null,
"countryOrRegion": "United Kingdom",
"postalCode": "E14 3TD"
},
"geoCoordinates": null
}