创建事件
本文内容
命名空间:microsoft.graph
重要
Microsoft Graph版本下的 /beta API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
在用户的默认日历或指定日历中创建事件 。
默认情况下,创建事件时,allowNewTimeProposals 的属性设置为 true,这意味着被邀请者可以为事件建议不同的日期/时间。 有关如何建议时间的详细信息,以及如何接收和接受新的时间建议,请参阅 建议新的会议时间 。
可以将事件的各开始和结束时间的时区指定为其值的一部分,因为 开始 和 结束 属性为 dateTimeTimeZone 类型。 首先找到支持的时区 ,以确保仅设置针对用户的邮箱服务器配置的时区。
发送事件时,服务器会向所有与会者发送邀请。
在事件中设置地点
Exchange 管理员可以为资源(如会议室)或设备(如投影仪)设置邮箱和电子邮件地址。 然后,用户可以邀请资源作为会议与会者。 服务器代表资源根据资源的忙/闲计划接受或拒绝会议请求。
如果服务器接受资源的会议,则会在资源的日历中为会议创建一个事件。 如果重新安排会议,则服务器会自动更新资源日历中的事件。
为资源设置邮箱的另一个优点是可以控制资源调度,例如,仅主管或其代理人可以预订私人会议室。
如果要组织涉及会议地点的事件:
相应地设置 事件 的 location 属性。
如果会议地点具有电子邮件地址,请设置可选 locationEmailAddress 属性。
此外,如果会议地点已设置为资源,或者如果事件涉及某些已设置为资源的设备:
邀请该资源作为与会者 。
将与会者 type 属性设置为 resource。
将与会者 emailAddress 设置为资源电子邮件地址。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限 。
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
Calendars.ReadWrite
委派(个人 Microsoft 帐户)
Calendars.ReadWrite
应用程序
Calendars.ReadWrite
HTTP 请求
POST /me/events
POST /users/{id | userPrincipalName}/events
POST /me/calendar/events
POST /users/{id | userPrincipalName}/calendar/events
POST /me/calendars/{id}/events
POST /users/{id | userPrincipalName}/calendars/{id}/events
标头
值
Authorization
Bearer {token}。必需。
Content-Type
application/json. Required.
请求正文
在请求正文中,提供 event 对象的 JSON 表示形式。
由于 事件 资源支持 扩展 因此可以使用 POST 操作,并在创建事件时向其添加含有自己的数据的自定义属性。
响应
如果成功,此方法在响应正文中返回 201 Created 响应代码和 event 对象。
示例
示例 1:在指定的时区创建事件,然后为事件分配可选的 transactionId 值
请求
下面是一个请求示例。 它使用 Prefer: outlook.timezone 请求头指定响应中开始时间和结束时间的时区。 它还设置 transactionId 属性,以减少服务器上不必要的重试。
POST https://graph.microsoft.com/beta/me/events
Prefer: outlook.timezone="Pacific Standard Time"
Content-type: application/json
{
"subject": "Let's go for lunch",
"body": {
"contentType": "HTML",
"content": "Does noon work for you?"
},
"start": {
"dateTime": "2017-04-15T12:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2017-04-15T14:00:00",
"timeZone": "Pacific Standard Time"
},
"location":{
"displayName":"Harry's Bar"
},
"attendees": [
{
"emailAddress": {
"address":"samanthab@contoso.onmicrosoft.com",
"name": "Samantha Booth"
},
"type": "required"
}
],
"allowNewTimeProposals": true,
"transactionId":"7E163156-7762-4BEB-A1C6-729EA81755A7"
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var @event = new Event
{
Subject = "Let's go for lunch",
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "Does noon work for you?"
},
Start = new DateTimeTimeZone
{
DateTime = "2017-04-15T12:00:00",
TimeZone = "Pacific Standard Time"
},
End = new DateTimeTimeZone
{
DateTime = "2017-04-15T14:00:00",
TimeZone = "Pacific Standard Time"
},
Location = new Location
{
DisplayName = "Harry's Bar"
},
Attendees = new List<Attendee>()
{
new Attendee
{
EmailAddress = new EmailAddress
{
Address = "samanthab@contoso.onmicrosoft.com",
Name = "Samantha Booth"
},
Type = AttendeeType.Required
}
},
AllowNewTimeProposals = true,
TransactionId = "7E163156-7762-4BEB-A1C6-729EA81755A7"
};
await graphClient.Me.Events
.Request()
.Header("Prefer","outlook.timezone=\"Pacific Standard Time\"")
.AddAsync(@event);
const options = {
authProvider,
};
const client = Client.init(options);
const event = {
subject: 'Let\'s go for lunch',
body: {
contentType: 'HTML',
content: 'Does noon work for you?'
},
start: {
dateTime: '2017-04-15T12:00:00',
timeZone: 'Pacific Standard Time'
},
end: {
dateTime: '2017-04-15T14:00:00',
timeZone: 'Pacific Standard Time'
},
location: {
displayName: 'Harry\'s Bar'
},
attendees: [
{
emailAddress: {
address: 'samanthab@contoso.onmicrosoft.com',
name: 'Samantha Booth'
},
type: 'required'
}
],
allowNewTimeProposals: true,
transactionId: '7E163156-7762-4BEB-A1C6-729EA81755A7'
};
await client.api('/me/events')
.version('beta')
.post(event);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/events"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"outlook.timezone=\"Pacific Standard Time\"" forHTTPHeaderField:@"Prefer"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphEvent *event = [[MSGraphEvent alloc] init];
[event setSubject:@"Let's go for lunch"];
MSGraphItemBody *body = [[MSGraphItemBody alloc] init];
[body setContentType: [MSGraphBodyType html]];
[body setContent:@"Does noon work for you?"];
[event setBody:body];
MSGraphDateTimeTimeZone *start = [[MSGraphDateTimeTimeZone alloc] init];
[start setDateTime: "2017-04-15T12:00:00"];
[start setTimeZone:@"Pacific Standard Time"];
[event setStart:start];
MSGraphDateTimeTimeZone *end = [[MSGraphDateTimeTimeZone alloc] init];
[end setDateTime: "2017-04-15T14:00:00"];
[end setTimeZone:@"Pacific Standard Time"];
[event setEnd:end];
MSGraphLocation *location = [[MSGraphLocation alloc] init];
[location setDisplayName:@"Harry's Bar"];
[event setLocation:location];
NSMutableArray *attendeesList = [[NSMutableArray alloc] init];
MSGraphAttendee *attendees = [[MSGraphAttendee alloc] init];
MSGraphEmailAddress *emailAddress = [[MSGraphEmailAddress alloc] init];
[emailAddress setAddress:@"samanthab@contoso.onmicrosoft.com"];
[emailAddress setName:@"Samantha Booth"];
[attendees setEmailAddress:emailAddress];
[attendees setType: [MSGraphAttendeeType required]];
[attendeesList addObject: attendees];
[event setAttendees:attendeesList];
[event setAllowNewTimeProposals: true];
[event setTransactionId:@"7E163156-7762-4BEB-A1C6-729EA81755A7"];
NSError *error;
NSData *eventData = [event getSerializedDataWithError:&error];
[urlRequest setHTTPBody:eventData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new HeaderOption("Prefer", "outlook.timezone=\"Pacific Standard Time\""));
Event event = new Event();
event.subject = "Let's go for lunch";
ItemBody body = new ItemBody();
body.contentType = BodyType.HTML;
body.content = "Does noon work for you?";
event.body = body;
DateTimeTimeZone start = new DateTimeTimeZone();
start.dateTime = "2017-04-15T12:00:00";
start.timeZone = "Pacific Standard Time";
event.start = start;
DateTimeTimeZone end = new DateTimeTimeZone();
end.dateTime = "2017-04-15T14:00:00";
end.timeZone = "Pacific Standard Time";
event.end = end;
Location location = new Location();
location.displayName = "Harry's Bar";
event.location = location;
LinkedList<Attendee> attendeesList = new LinkedList<Attendee>();
Attendee attendees = new Attendee();
EmailAddress emailAddress = new EmailAddress();
emailAddress.address = "samanthab@contoso.onmicrosoft.com";
emailAddress.name = "Samantha Booth";
attendees.emailAddress = emailAddress;
attendees.type = AttendeeType.REQUIRED;
attendeesList.add(attendees);
event.attendees = attendeesList;
event.allowNewTimeProposals = true;
event.transactionId = "7E163156-7762-4BEB-A1C6-729EA81755A7";
graphClient.me().events()
.buildRequest( requestOptions )
.post(event);
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewEvent()
subject := "Let's go for lunch"
requestBody.SetSubject(&subject)
body := msgraphsdk.NewItemBody()
requestBody.SetBody(body)
contentType := "HTML"
body.SetContentType(&contentType)
content := "Does noon work for you?"
body.SetContent(&content)
start := msgraphsdk.NewDateTimeTimeZone()
requestBody.SetStart(start)
dateTime := "2017-04-15T12:00:00"
start.SetDateTime(&dateTime)
timeZone := "Pacific Standard Time"
start.SetTimeZone(&timeZone)
end := msgraphsdk.NewDateTimeTimeZone()
requestBody.SetEnd(end)
dateTime := "2017-04-15T14:00:00"
end.SetDateTime(&dateTime)
timeZone := "Pacific Standard Time"
end.SetTimeZone(&timeZone)
location := msgraphsdk.NewLocation()
requestBody.SetLocation(location)
displayName := "Harry's Bar"
location.SetDisplayName(&displayName)
requestBody.SetAttendees( []Attendee {
msgraphsdk.NewAttendee(),
SetAdditionalData(map[string]interface{}{
"type": "required",
}
}
allowNewTimeProposals := true
requestBody.SetAllowNewTimeProposals(&allowNewTimeProposals)
transactionId := "7E163156-7762-4BEB-A1C6-729EA81755A7"
requestBody.SetTransactionId(&transactionId)
headers := map[string]string{
"Prefer": "outlook.timezone="Pacific Standard Time""
}
options := &msgraphsdk.EventsRequestBuilderPostRequestConfiguration{
Headers: headers,
}
result, err := graphClient.Me().Events().PostWithRequestConfigurationAndResponseHandler(requestBody, options, nil)
Import-Module Microsoft.Graph.Calendar
$params = @{
Subject = "Let's go for lunch"
Body = @{
ContentType = "HTML"
Content = "Does noon work for you?"
}
Start = @{
DateTime = "2017-04-15T12:00:00"
TimeZone = "Pacific Standard Time"
}
End = @{
DateTime = "2017-04-15T14:00:00"
TimeZone = "Pacific Standard Time"
}
Location = @{
DisplayName = "Harry's Bar"
}
Attendees = @(
@{
EmailAddress = @{
Address = "samanthab@contoso.onmicrosoft.com"
Name = "Samantha Booth"
}
Type = "required"
}
)
AllowNewTimeProposals = $true
TransactionId = "7E163156-7762-4BEB-A1C6-729EA81755A7"
}
# A UPN can also be used as -UserId.
New-MgUserEvent -UserId $userId -BodyParameter $params
在请求正文中,提供 event 对象的 JSON 表示形式。
响应
下面是一个响应示例,显示 start 和 end 属性使用 Prefer: outlook.timezone 标头中指定的时区。
注意:为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context":"https://graph.microsoft.com/beta/$metadata#users('cd209b0b-3f83-4c35-82d2-d88a61820480')/events/$entity",
"@odata.etag":"W/\"ZlnW4RIAV06KYYwlrfNZvQAALfZeRQ==\"",
"id":"AAMkAGI1AAAt9AHjAAA=",
"createdDateTime":"2017-04-15T03:00:50.7579581Z",
"lastModifiedDateTime":"2017-04-15T03:00:51.245372Z",
"changeKey":"ZlnW4RIAV06KYYwlrfNZvQAALfZeRQ==",
"categories":[
],
"originalStartTimeZone":"Pacific Standard Time",
"originalEndTimeZone":"Pacific Standard Time",
"uid":"040000008200E00074C5B7101A82E00800000000DA2B357D94B5D201000000000000000010000000EC4597557F0CB34EA4CC2887EA7B17C3",
"reminderMinutesBeforeStart":15,
"isReminderOn":true,
"hasAttachments":false,
"hideAttendees": false,
"subject":"Let's go brunch",
"bodyPreview":"Does noon work for you?",
"importance":"normal",
"sensitivity":"normal",
"isAllDay":false,
"isCancelled":false,
"isDraft": false,
"isOrganizer":true,
"responseRequested":true,
"seriesMasterId":null,
"transactionId":"7E163156-7762-4BEB-A1C6-729EA81755A7",
"showAs":"busy",
"type":"singleInstance",
"webLink":"https://outlook.office365.com/owa/?itemid=AAMkAGI1AAAt9AHjAAA%3D&exvsurl=1&path=/calendar/item",
"onlineMeetingUrl":null,
"isOnlineMeeting": false,
"onlineMeetingProvider":"unknown",
"onlineMeeting":null,
"allowNewTimeProposals": true,
"responseStatus":{
"response":"organizer",
"time":"0001-01-01T00:00:00Z"
},
"body":{
"contentType":"html",
"content":"<html><head></head><body>Does late morning work for you?</body></html>"
},
"start":{
"dateTime":"2017-04-15T11:00:00.0000000",
"timeZone":"Pacific Standard Time"
},
"end":{
"dateTime":"2017-04-15T12:00:00.0000000",
"timeZone":"Pacific Standard Time"
},
"location": {
"displayName": "Harry's Bar",
"locationType": "default",
"uniqueId": "Harry's Bar",
"uniqueIdType": "private"
},
"locations": [
{
"displayName": "Harry's Bar",
"locationType": "default",
"uniqueIdType": "unknown"
}
],
"recurrence":null,
"attendees":[
{
"type":"required",
"status":{
"response":"none",
"time":"0001-01-01T00:00:00Z"
},
"emailAddress":{
"name":"Samantha Booth",
"address":"samanthab@contoso.onmicrosoft.com"
}
}
],
"organizer":{
"emailAddress":{
"name":"Dana Swope",
"address":"danas@contoso.onmicrosoft.com"
}
}
}
示例 2:创建发生在多个位置的事件
请求
下一个示例请求指定组织者和与会者可参加会议的 3 个地点。
在请求正文中,提供 event 对象的 JSON 表示形式。
POST https://graph.microsoft.com/beta/me/events
Prefer: outlook.timezone="Pacific Standard Time"
Content-type: application/json
{
"subject": "Plan summer company picnic",
"body": {
"contentType": "HTML",
"content": "Let's kick-start this event planning!"
},
"start": {
"dateTime": "2017-08-30T11:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2017-08-30T12:00:00",
"timeZone": "Pacific Standard Time"
},
"attendees": [
{
"emailAddress": {
"address": "DanaS@contoso.onmicrosoft.com",
"name": "Dana Swope"
},
"type": "Required"
},
{
"emailAddress": {
"address": "AlexW@contoso.onmicrosoft.com",
"name": "Alex Wilber"
},
"type": "Required"
}
],
"location": {
"displayName": "Conf Room 3; Fourth Coffee; Home Office",
"locationType": "Default"
},
"locations": [
{
"displayName": "Conf Room 3"
},
{
"displayName": "Fourth Coffee",
"address": {
"street": "4567 Main St",
"city": "Redmond",
"state": "WA",
"countryOrRegion": "US",
"postalCode": "32008"
},
"coordinates": {
"latitude": 47.672,
"longitude": -102.103
}
},
{
"displayName": "Home Office"
}
],
"allowNewTimeProposals": true
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var @event = new Event
{
Subject = "Plan summer company picnic",
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "Let's kick-start this event planning!"
},
Start = new DateTimeTimeZone
{
DateTime = "2017-08-30T11:00:00",
TimeZone = "Pacific Standard Time"
},
End = new DateTimeTimeZone
{
DateTime = "2017-08-30T12:00:00",
TimeZone = "Pacific Standard Time"
},
Attendees = new List<Attendee>()
{
new Attendee
{
EmailAddress = new EmailAddress
{
Address = "DanaS@contoso.onmicrosoft.com",
Name = "Dana Swope"
},
Type = AttendeeType.Required
},
new Attendee
{
EmailAddress = new EmailAddress
{
Address = "AlexW@contoso.onmicrosoft.com",
Name = "Alex Wilber"
},
Type = AttendeeType.Required
}
},
Location = new Location
{
DisplayName = "Conf Room 3; Fourth Coffee; Home Office",
LocationType = LocationType.Default
},
Locations = new List<Location>()
{
new Location
{
DisplayName = "Conf Room 3"
},
new Location
{
DisplayName = "Fourth Coffee",
Address = new PhysicalAddress
{
Street = "4567 Main St",
City = "Redmond",
State = "WA",
CountryOrRegion = "US",
PostalCode = "32008"
},
Coordinates = new OutlookGeoCoordinates
{
Latitude = 47.672,
Longitude = -102.103
}
},
new Location
{
DisplayName = "Home Office"
}
},
AllowNewTimeProposals = true
};
await graphClient.Me.Events
.Request()
.Header("Prefer","outlook.timezone=\"Pacific Standard Time\"")
.AddAsync(@event);
const options = {
authProvider,
};
const client = Client.init(options);
const event = {
subject: 'Plan summer company picnic',
body: {
contentType: 'HTML',
content: 'Let\'s kick-start this event planning!'
},
start: {
dateTime: '2017-08-30T11:00:00',
timeZone: 'Pacific Standard Time'
},
end: {
dateTime: '2017-08-30T12:00:00',
timeZone: 'Pacific Standard Time'
},
attendees: [
{
emailAddress: {
address: 'DanaS@contoso.onmicrosoft.com',
name: 'Dana Swope'
},
type: 'Required'
},
{
emailAddress: {
address: 'AlexW@contoso.onmicrosoft.com',
name: 'Alex Wilber'
},
type: 'Required'
}
],
location: {
displayName: 'Conf Room 3; Fourth Coffee; Home Office',
locationType: 'Default'
},
locations: [
{
displayName: 'Conf Room 3'
},
{
displayName: 'Fourth Coffee',
address: {
street: '4567 Main St',
city: 'Redmond',
state: 'WA',
countryOrRegion: 'US',
postalCode: '32008'
},
coordinates: {
latitude: 47.672,
longitude: -102.103
}
},
{
displayName: 'Home Office'
}
],
allowNewTimeProposals: true
};
await client.api('/me/events')
.version('beta')
.post(event);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/events"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"outlook.timezone=\"Pacific Standard Time\"" forHTTPHeaderField:@"Prefer"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphEvent *event = [[MSGraphEvent alloc] init];
[event setSubject:@"Plan summer company picnic"];
MSGraphItemBody *body = [[MSGraphItemBody alloc] init];
[body setContentType: [MSGraphBodyType html]];
[body setContent:@"Let's kick-start this event planning!"];
[event setBody:body];
MSGraphDateTimeTimeZone *start = [[MSGraphDateTimeTimeZone alloc] init];
[start setDateTime: "2017-08-30T11:00:00"];
[start setTimeZone:@"Pacific Standard Time"];
[event setStart:start];
MSGraphDateTimeTimeZone *end = [[MSGraphDateTimeTimeZone alloc] init];
[end setDateTime: "2017-08-30T12:00:00"];
[end setTimeZone:@"Pacific Standard Time"];
[event setEnd:end];
NSMutableArray *attendeesList = [[NSMutableArray alloc] init];
MSGraphAttendee *attendees = [[MSGraphAttendee alloc] init];
MSGraphEmailAddress *emailAddress = [[MSGraphEmailAddress alloc] init];
[emailAddress setAddress:@"DanaS@contoso.onmicrosoft.com"];
[emailAddress setName:@"Dana Swope"];
[attendees setEmailAddress:emailAddress];
[attendees setType: [MSGraphAttendeeType required]];
[attendeesList addObject: attendees];
MSGraphAttendee *attendees = [[MSGraphAttendee alloc] init];
MSGraphEmailAddress *emailAddress = [[MSGraphEmailAddress alloc] init];
[emailAddress setAddress:@"AlexW@contoso.onmicrosoft.com"];
[emailAddress setName:@"Alex Wilber"];
[attendees setEmailAddress:emailAddress];
[attendees setType: [MSGraphAttendeeType required]];
[attendeesList addObject: attendees];
[event setAttendees:attendeesList];
MSGraphLocation *location = [[MSGraphLocation alloc] init];
[location setDisplayName:@"Conf Room 3; Fourth Coffee; Home Office"];
[location setLocationType: [MSGraphLocationType default]];
[event setLocation:location];
NSMutableArray *locationsList = [[NSMutableArray alloc] init];
MSGraphLocation *locations = [[MSGraphLocation alloc] init];
[locations setDisplayName:@"Conf Room 3"];
[locationsList addObject: locations];
MSGraphLocation *locations = [[MSGraphLocation alloc] init];
[locations setDisplayName:@"Fourth Coffee"];
MSGraphPhysicalAddress *address = [[MSGraphPhysicalAddress alloc] init];
[address setStreet:@"4567 Main St"];
[address setCity:@"Redmond"];
[address setState:@"WA"];
[address setCountryOrRegion:@"US"];
[address setPostalCode:@"32008"];
[locations setAddress:address];
MSGraphOutlookGeoCoordinates *coordinates = [[MSGraphOutlookGeoCoordinates alloc] init];
[coordinates setLatitude: 47.672];
[coordinates setLongitude: -102.103];
[locations setCoordinates:coordinates];
[locationsList addObject: locations];
MSGraphLocation *locations = [[MSGraphLocation alloc] init];
[locations setDisplayName:@"Home Office"];
[locationsList addObject: locations];
[event setLocations:locationsList];
[event setAllowNewTimeProposals: true];
NSError *error;
NSData *eventData = [event getSerializedDataWithError:&error];
[urlRequest setHTTPBody:eventData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new HeaderOption("Prefer", "outlook.timezone=\"Pacific Standard Time\""));
Event event = new Event();
event.subject = "Plan summer company picnic";
ItemBody body = new ItemBody();
body.contentType = BodyType.HTML;
body.content = "Let's kick-start this event planning!";
event.body = body;
DateTimeTimeZone start = new DateTimeTimeZone();
start.dateTime = "2017-08-30T11:00:00";
start.timeZone = "Pacific Standard Time";
event.start = start;
DateTimeTimeZone end = new DateTimeTimeZone();
end.dateTime = "2017-08-30T12:00:00";
end.timeZone = "Pacific Standard Time";
event.end = end;
LinkedList<Attendee> attendeesList = new LinkedList<Attendee>();
Attendee attendees = new Attendee();
EmailAddress emailAddress = new EmailAddress();
emailAddress.address = "DanaS@contoso.onmicrosoft.com";
emailAddress.name = "Dana Swope";
attendees.emailAddress = emailAddress;
attendees.type = AttendeeType.REQUIRED;
attendeesList.add(attendees);
Attendee attendees1 = new Attendee();
EmailAddress emailAddress1 = new EmailAddress();
emailAddress1.address = "AlexW@contoso.onmicrosoft.com";
emailAddress1.name = "Alex Wilber";
attendees1.emailAddress = emailAddress1;
attendees1.type = AttendeeType.REQUIRED;
attendeesList.add(attendees1);
event.attendees = attendeesList;
Location location = new Location();
location.displayName = "Conf Room 3; Fourth Coffee; Home Office";
location.locationType = LocationType.DEFAULT;
event.location = location;
LinkedList<Location> locationsList = new LinkedList<Location>();
Location locations = new Location();
locations.displayName = "Conf Room 3";
locationsList.add(locations);
Location locations1 = new Location();
locations1.displayName = "Fourth Coffee";
PhysicalAddress address2 = new PhysicalAddress();
address2.street = "4567 Main St";
address2.city = "Redmond";
address2.state = "WA";
address2.countryOrRegion = "US";
address2.postalCode = "32008";
locations1.address = address2;
OutlookGeoCoordinates coordinates = new OutlookGeoCoordinates();
coordinates.latitude = 47.672d;
coordinates.longitude = -102.103d;
locations1.coordinates = coordinates;
locationsList.add(locations1);
Location locations2 = new Location();
locations2.displayName = "Home Office";
locationsList.add(locations2);
event.locations = locationsList;
event.allowNewTimeProposals = true;
graphClient.me().events()
.buildRequest( requestOptions )
.post(event);
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewEvent()
subject := "Plan summer company picnic"
requestBody.SetSubject(&subject)
body := msgraphsdk.NewItemBody()
requestBody.SetBody(body)
contentType := "HTML"
body.SetContentType(&contentType)
content := "Let's kick-start this event planning!"
body.SetContent(&content)
start := msgraphsdk.NewDateTimeTimeZone()
requestBody.SetStart(start)
dateTime := "2017-08-30T11:00:00"
start.SetDateTime(&dateTime)
timeZone := "Pacific Standard Time"
start.SetTimeZone(&timeZone)
end := msgraphsdk.NewDateTimeTimeZone()
requestBody.SetEnd(end)
dateTime := "2017-08-30T12:00:00"
end.SetDateTime(&dateTime)
timeZone := "Pacific Standard Time"
end.SetTimeZone(&timeZone)
requestBody.SetAttendees( []Attendee {
msgraphsdk.NewAttendee(),
SetAdditionalData(map[string]interface{}{
"type": "Required",
}
msgraphsdk.NewAttendee(),
SetAdditionalData(map[string]interface{}{
"type": "Required",
}
}
location := msgraphsdk.NewLocation()
requestBody.SetLocation(location)
displayName := "Conf Room 3; Fourth Coffee; Home Office"
location.SetDisplayName(&displayName)
locationType := "Default"
location.SetLocationType(&locationType)
requestBody.SetLocations( []Location {
msgraphsdk.NewLocation(),
displayName := "Conf Room 3"
SetDisplayName(&displayName)
msgraphsdk.NewLocation(),
displayName := "Fourth Coffee"
SetDisplayName(&displayName)
address := msgraphsdk.NewPhysicalAddress()
SetAddress(address)
street := "4567 Main St"
address.SetStreet(&street)
city := "Redmond"
address.SetCity(&city)
state := "WA"
address.SetState(&state)
countryOrRegion := "US"
address.SetCountryOrRegion(&countryOrRegion)
postalCode := "32008"
address.SetPostalCode(&postalCode)
coordinates := msgraphsdk.NewOutlookGeoCoordinates()
SetCoordinates(coordinates)
latitude := float64(47.672)
coordinates.SetLatitude(&latitude)
longitude := float64(-102.103)
coordinates.SetLongitude(&longitude)
msgraphsdk.NewLocation(),
displayName := "Home Office"
SetDisplayName(&displayName)
}
allowNewTimeProposals := true
requestBody.SetAllowNewTimeProposals(&allowNewTimeProposals)
headers := map[string]string{
"Prefer": "outlook.timezone="Pacific Standard Time""
}
options := &msgraphsdk.EventsRequestBuilderPostRequestConfiguration{
Headers: headers,
}
result, err := graphClient.Me().Events().PostWithRequestConfigurationAndResponseHandler(requestBody, options, nil)
Import-Module Microsoft.Graph.Calendar
$params = @{
Subject = "Plan summer company picnic"
Body = @{
ContentType = "HTML"
Content = "Let's kick-start this event planning!"
}
Start = @{
DateTime = "2017-08-30T11:00:00"
TimeZone = "Pacific Standard Time"
}
End = @{
DateTime = "2017-08-30T12:00:00"
TimeZone = "Pacific Standard Time"
}
Attendees = @(
@{
EmailAddress = @{
Address = "DanaS@contoso.onmicrosoft.com"
Name = "Dana Swope"
}
Type = "Required"
}
@{
EmailAddress = @{
Address = "AlexW@contoso.onmicrosoft.com"
Name = "Alex Wilber"
}
Type = "Required"
}
)
Location = @{
DisplayName = "Conf Room 3; Fourth Coffee; Home Office"
LocationType = "Default"
}
Locations = @(
@{
DisplayName = "Conf Room 3"
}
@{
DisplayName = "Fourth Coffee"
Address = @{
Street = "4567 Main St"
City = "Redmond"
State = "WA"
CountryOrRegion = "US"
PostalCode = "32008"
}
Coordinates = @{
Latitude = 47.672
Longitude = -102.103
}
}
@{
DisplayName = "Home Office"
}
)
AllowNewTimeProposals = $true
}
# A UPN can also be used as -UserId.
New-MgUserEvent -UserId $userId -BodyParameter $params
响应
以下示例响应显示指定 3 个会议地点信息的已创建事件。 由于 Prefer: outlook.timezone="Pacific Standard Time" 请求标头,start 和 end 属性以 PST 表示。
注意:为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context":"https://graph.microsoft.com/beta/$metadata#users('d1a2fae9-db66-4cc9-8133-2184c77af1b8')/events/$entity",
"@odata.etag":"W/\"y53lbKh6jkaxHzFwGhgyxgAAw5zhug==\"",
"id":"AAMkADAGAADDdm4NAAA=",
"createdDateTime":"2017-08-30T07:06:33.8673345Z",
"lastModifiedDateTime":"2017-08-30T07:06:34.5079772Z",
"changeKey":"y53lbKh6jkaxHzFwGhgyxgAAz3IKMA==",
"categories":[
],
"originalStartTimeZone":"Pacific Standard Time",
"originalEndTimeZone":"Pacific Standard Time",
"uid":"04000000820089190544",
"reminderMinutesBeforeStart":15,
"isReminderOn":true,
"hasAttachments":false,
"hideAttendees": false,
"subject":"Plan summer company picnic",
"bodyPreview":"Let's kick-start this event planning!",
"importance":"normal",
"sensitivity":"normal",
"isAllDay":false,
"isCancelled":false,
"isDraft": false,
"isOrganizer":true,
"responseRequested":true,
"seriesMasterId":null,
"showAs":"busy",
"type":"singleInstance",
"webLink":"https://outlook.office365.com/owa/?itemid=AAMkADAGAADDdm4NAAA%3D&exvsurl=1&path=/calendar/item",
"onlineMeetingUrl":null,
"isOnlineMeeting":true,
"onlineMeetingProvider":"unknown",
"onlineMeeting":null,
"allowNewTimeProposals": true,
"responseStatus":{
"response":"organizer",
"time":"0001-01-01T00:00:00Z"
},
"body":{
"contentType":"html",
"content":"<html>\r\n<head>\r\n</head>\r\n<body>\r\nLet's kick-start this event planning!\r\n</body>\r\n</html>\r\n"
},
"start":{
"dateTime":"2017-08-30T11:00:00.0000000",
"timeZone":"Pacific Standard Time"
},
"end":{
"dateTime":"2017-08-30T12:00:00.0000000",
"timeZone":"Pacific Standard Time"
},
"location":{
"displayName":"Conf Room 3; Fourth Coffee; Home Office",
"locationType":"default",
"uniqueId":"Conf Room 3; Fourth Coffee; Home Office",
"uniqueIdType":"private"
},
"locations":[
{
"displayName":"Conf Room 3",
"locationType":"default",
"uniqueIdType":"unknown"
},
{
"displayName":"Fourth Coffee",
"locationType":"default",
"uniqueId":"Fourth Coffee",
"uniqueIdType":"private",
"address":{
"type":"unknown",
"street":"4567 Main St",
"city":"Redmond",
"state":"WA",
"countryOrRegion":"US",
"postalCode":"32008"
},
"coordinates":{
"latitude":47.672,
"longitude":-102.103
}
},
{
"displayName":"Home Office",
"locationType":"default",
"uniqueIdType":"unknown"
}
],
"recurrence":null,
"attendees":[
{
"type":"required",
"status":{
"response":"none",
"time":"0001-01-01T00:00:00Z"
},
"emailAddress":{
"name":"Dana Swope",
"address":"DanaS@contoso.onmicrosoft.com"
}
},
{
"type":"required",
"status":{
"response":"none",
"time":"0001-01-01T00:00:00Z"
},
"emailAddress":{
"name":"Alex Wilber",
"address":"AlexW@contoso.onmicrosoft.com"
}
}
],
"organizer":{
"emailAddress":{
"name":"Adele Vance",
"address":"AdeleV@contoso.onmicrosoft.com"
}
}
}
示例 3:创建每周定期事件
请求
第三个示例展示了如何创建每周发生一次的定期事件。 事件在 2017 年 9 月 4 日至年底期间每星期一的中午 12:00 点到下午 2:00 点之间发生。
POST https://graph.microsoft.com/beta/me/events
Content-type: application/json
{
"subject": "Let's go for lunch",
"body": {
"contentType": "HTML",
"content": "Does noon time work for you?"
},
"start": {
"dateTime": "2017-09-04T12:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2017-09-04T14:00:00",
"timeZone": "Pacific Standard Time"
},
"recurrence": {
"pattern": {
"type": "weekly",
"interval": 1,
"daysOfWeek": [ "Monday" ]
},
"range": {
"type": "endDate",
"startDate": "2017-09-04",
"endDate": "2017-12-31"
}
},
"location":{
"displayName":"Harry's Bar"
},
"attendees": [
{
"emailAddress": {
"address":"AdeleV@contoso.onmicrosoft.com",
"name": "Adele Vance"
},
"type": "required"
}
]
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var @event = new Event
{
Subject = "Let's go for lunch",
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "Does noon time work for you?"
},
Start = new DateTimeTimeZone
{
DateTime = "2017-09-04T12:00:00",
TimeZone = "Pacific Standard Time"
},
End = new DateTimeTimeZone
{
DateTime = "2017-09-04T14:00:00",
TimeZone = "Pacific Standard Time"
},
Recurrence = new PatternedRecurrence
{
Pattern = new RecurrencePattern
{
Type = RecurrencePatternType.Weekly,
Interval = 1,
DaysOfWeek = new List<DayOfWeek>()
{
DayOfWeek.Monday
}
},
Range = new RecurrenceRange
{
Type = RecurrenceRangeType.EndDate,
StartDate = new Date(2017,9,4),
EndDate = new Date(2017,12,31)
}
},
Location = new Location
{
DisplayName = "Harry's Bar"
},
Attendees = new List<Attendee>()
{
new Attendee
{
EmailAddress = new EmailAddress
{
Address = "AdeleV@contoso.onmicrosoft.com",
Name = "Adele Vance"
},
Type = AttendeeType.Required
}
}
};
await graphClient.Me.Events
.Request()
.AddAsync(@event);
const options = {
authProvider,
};
const client = Client.init(options);
const event = {
subject: 'Let\'s go for lunch',
body: {
contentType: 'HTML',
content: 'Does noon time work for you?'
},
start: {
dateTime: '2017-09-04T12:00:00',
timeZone: 'Pacific Standard Time'
},
end: {
dateTime: '2017-09-04T14:00:00',
timeZone: 'Pacific Standard Time'
},
recurrence: {
pattern: {
type: 'weekly',
interval: 1,
daysOfWeek: [ 'Monday' ]
},
range: {
type: 'endDate',
startDate: '2017-09-04',
endDate: '2017-12-31'
}
},
location: {
displayName: 'Harry\'s Bar'
},
attendees: [
{
emailAddress: {
address: 'AdeleV@contoso.onmicrosoft.com',
name: 'Adele Vance'
},
type: 'required'
}
]
};
await client.api('/me/events')
.version('beta')
.post(event);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/events"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphEvent *event = [[MSGraphEvent alloc] init];
[event setSubject:@"Let's go for lunch"];
MSGraphItemBody *body = [[MSGraphItemBody alloc] init];
[body setContentType: [MSGraphBodyType html]];
[body setContent:@"Does noon time work for you?"];
[event setBody:body];
MSGraphDateTimeTimeZone *start = [[MSGraphDateTimeTimeZone alloc] init];
[start setDateTime: "2017-09-04T12:00:00"];
[start setTimeZone:@"Pacific Standard Time"];
[event setStart:start];
MSGraphDateTimeTimeZone *end = [[MSGraphDateTimeTimeZone alloc] init];
[end setDateTime: "2017-09-04T14:00:00"];
[end setTimeZone:@"Pacific Standard Time"];
[event setEnd:end];
MSGraphPatternedRecurrence *recurrence = [[MSGraphPatternedRecurrence alloc] init];
MSGraphRecurrencePattern *pattern = [[MSGraphRecurrencePattern alloc] init];
[pattern setType: [MSGraphRecurrencePatternType weekly]];
[pattern setInterval: 1];
NSMutableArray *daysOfWeekList = [[NSMutableArray alloc] init];
[daysOfWeekList addObject: @"Monday"];
[pattern setDaysOfWeek:daysOfWeekList];
[recurrence setPattern:pattern];
MSGraphRecurrenceRange *range = [[MSGraphRecurrenceRange alloc] init];
[range setType: [MSGraphRecurrenceRangeType endDate]];
[range setStartDate:@"2017-09-04"];
[range setEndDate:@"2017-12-31"];
[recurrence setRange:range];
[event setRecurrence:recurrence];
MSGraphLocation *location = [[MSGraphLocation alloc] init];
[location setDisplayName:@"Harry's Bar"];
[event setLocation:location];
NSMutableArray *attendeesList = [[NSMutableArray alloc] init];
MSGraphAttendee *attendees = [[MSGraphAttendee alloc] init];
MSGraphEmailAddress *emailAddress = [[MSGraphEmailAddress alloc] init];
[emailAddress setAddress:@"AdeleV@contoso.onmicrosoft.com"];
[emailAddress setName:@"Adele Vance"];
[attendees setEmailAddress:emailAddress];
[attendees setType: [MSGraphAttendeeType required]];
[attendeesList addObject: attendees];
[event setAttendees:attendeesList];
NSError *error;
NSData *eventData = [event getSerializedDataWithError:&error];
[urlRequest setHTTPBody:eventData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Event event = new Event();
event.subject = "Let's go for lunch";
ItemBody body = new ItemBody();
body.contentType = BodyType.HTML;
body.content = "Does noon time work for you?";
event.body = body;
DateTimeTimeZone start = new DateTimeTimeZone();
start.dateTime = "2017-09-04T12:00:00";
start.timeZone = "Pacific Standard Time";
event.start = start;
DateTimeTimeZone end = new DateTimeTimeZone();
end.dateTime = "2017-09-04T14:00:00";
end.timeZone = "Pacific Standard Time";
event.end = end;
PatternedRecurrence recurrence = new PatternedRecurrence();
RecurrencePattern pattern = new RecurrencePattern();
pattern.type = RecurrencePatternType.WEEKLY;
pattern.interval = 1;
LinkedList<DayOfWeek> daysOfWeekList = new LinkedList<DayOfWeek>();
daysOfWeekList.add(DayOfWeek.MONDAY);
pattern.daysOfWeek = daysOfWeekList;
recurrence.pattern = pattern;
RecurrenceRange range = new RecurrenceRange();
range.type = RecurrenceRangeType.END_DATE;
range.startDate = new DateOnly(1900,1,1);
range.endDate = new DateOnly(1900,1,1);
recurrence.range = range;
event.recurrence = recurrence;
Location location = new Location();
location.displayName = "Harry's Bar";
event.location = location;
LinkedList<Attendee> attendeesList = new LinkedList<Attendee>();
Attendee attendees = new Attendee();
EmailAddress emailAddress = new EmailAddress();
emailAddress.address = "AdeleV@contoso.onmicrosoft.com";
emailAddress.name = "Adele Vance";
attendees.emailAddress = emailAddress;
attendees.type = AttendeeType.REQUIRED;
attendeesList.add(attendees);
event.attendees = attendeesList;
graphClient.me().events()
.buildRequest()
.post(event);
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewEvent()
subject := "Let's go for lunch"
requestBody.SetSubject(&subject)
body := msgraphsdk.NewItemBody()
requestBody.SetBody(body)
contentType := "HTML"
body.SetContentType(&contentType)
content := "Does noon time work for you?"
body.SetContent(&content)
start := msgraphsdk.NewDateTimeTimeZone()
requestBody.SetStart(start)
dateTime := "2017-09-04T12:00:00"
start.SetDateTime(&dateTime)
timeZone := "Pacific Standard Time"
start.SetTimeZone(&timeZone)
end := msgraphsdk.NewDateTimeTimeZone()
requestBody.SetEnd(end)
dateTime := "2017-09-04T14:00:00"
end.SetDateTime(&dateTime)
timeZone := "Pacific Standard Time"
end.SetTimeZone(&timeZone)
recurrence := msgraphsdk.NewPatternedRecurrence()
requestBody.SetRecurrence(recurrence)
pattern := msgraphsdk.NewRecurrencePattern()
recurrence.SetPattern(pattern)
type := "weekly"
pattern.SetType(&type)
interval := int32(1)
pattern.SetInterval(&interval)
pattern.SetDaysOfWeek( []DayOfWeek {
"Monday",
}
range := msgraphsdk.NewRecurrenceRange()
recurrence.SetRange(range)
type := "endDate"
range.SetType(&type)
startDate := "2017-09-04"
range.SetStartDate(&startDate)
endDate := "2017-12-31"
range.SetEndDate(&endDate)
location := msgraphsdk.NewLocation()
requestBody.SetLocation(location)
displayName := "Harry's Bar"
location.SetDisplayName(&displayName)
requestBody.SetAttendees( []Attendee {
msgraphsdk.NewAttendee(),
SetAdditionalData(map[string]interface{}{
"type": "required",
}
}
result, err := graphClient.Me().Events().Post(requestBody)
Import-Module Microsoft.Graph.Calendar
$params = @{
Subject = "Let's go for lunch"
Body = @{
ContentType = "HTML"
Content = "Does noon time work for you?"
}
Start = @{
DateTime = "2017-09-04T12:00:00"
TimeZone = "Pacific Standard Time"
}
End = @{
DateTime = "2017-09-04T14:00:00"
TimeZone = "Pacific Standard Time"
}
Recurrence = @{
Pattern = @{
Type = "weekly"
Interval = 1
DaysOfWeek = @(
"Monday"
)
}
Range = @{
Type = "endDate"
StartDate = "2017-09-04"
EndDate = "2017-12-31"
}
}
Location = @{
DisplayName = "Harry's Bar"
}
Attendees = @(
@{
EmailAddress = @{
Address = "AdeleV@contoso.onmicrosoft.com"
Name = "Adele Vance"
}
Type = "required"
}
)
}
# A UPN can also be used as -UserId.
New-MgUserEvent -UserId $userId -BodyParameter $params
在请求正文中,提供 event 对象的 JSON 表示形式。
响应
这是一个示例响应。注意:为提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context":"https://graph.microsoft.com/beta/$metadata#users('919717da-0460-4cca-a6be-d25382429896')/events/$entity",
"@odata.etag":"W/\"+T8RDneHMkKe2BGYEaQZ4wAA5a9Acw==\"",
"id":"AAMkADQwMD",
"createdDateTime":"2017-10-07T04:59:12.9698856Z",
"lastModifiedDateTime":"2017-10-07T04:59:13.8136423Z",
"changeKey":"+T8RDneHMkKe2BGYEaQZ4wAA5a9Acw==",
"categories":[
],
"originalStartTimeZone":"Pacific Standard Time",
"originalEndTimeZone":"Pacific Standard Time",
"uid":"040000008200E00074C5B7101A82E0080000000028CEBE04293FD3010000000000000000100000009F85AB8AF8ED4D4FAC777FA89954BDB7",
"reminderMinutesBeforeStart":15,
"isReminderOn":true,
"hasAttachments":false,
"hideAttendees": false,
"subject":"Let's go for lunch",
"bodyPreview":"Does late morning work for you?",
"importance":"normal",
"sensitivity":"normal",
"isAllDay":false,
"isCancelled":false,
"isDraft": false,
"isOrganizer":true,
"responseRequested":true,
"seriesMasterId":null,
"showAs":"busy",
"type":"seriesMaster",
"webLink":"https://outlook.office365.com/owa/?itemid=AAMkADQwMD&exvsurl=1&path=/calendar/item",
"onlineMeetingUrl":null,
"isOnlineMeeting":true,
"onlineMeetingProvider":"unknown",
"onlineMeeting":null,
"allowNewTimeProposals": true,
"responseStatus":{
"response":"organizer",
"time":"0001-01-01T00:00:00Z"
},
"body":{
"contentType":"html",
"content":"<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta content=\"text/html; charset=us-ascii\">\r\n</head>\r\n<body>\r\nDoes late morning work for you?\r\n</body>\r\n</html>\r\n"
},
"start":{
"dateTime":"2017-09-04T12:00:00.0000000",
"timeZone":"Pacific Standard Time"
},
"end":{
"dateTime":"2017-09-04T14:00:00.0000000",
"timeZone":"Pacific Standard Time"
},
"location":{
"displayName":"Harry's Bar",
"locationType":"default",
"uniqueId":"Harry's Bar",
"uniqueIdType":"private"
},
"locations":[
{
"displayName":"Harry's Bar",
"locationType":"default",
"uniqueIdType":"unknown"
}
],
"recurrence":{
"pattern":{
"type":"weekly",
"interval":1,
"month":0,
"dayOfMonth":0,
"daysOfWeek":[
"monday"
],
"firstDayOfWeek":"sunday",
"index":"first"
},
"range":{
"type":"endDate",
"startDate":"2017-09-04",
"endDate":"2017-12-31",
"recurrenceTimeZone":"Pacific Standard Time",
"numberOfOccurrences":0
}
},
"attendees":[
{
"type":"required",
"status":{
"response":"none",
"time":"0001-01-01T00:00:00Z"
},
"emailAddress":{
"name":"Adele Vance",
"address":"AdeleV@contoso.onmicrosoft.com"
}
}
],
"organizer":{
"emailAddress":{
"name":"Alex Wilber",
"address":"AlexW@contoso.onmicrosoft.com"
}
},
"OnlineMeeting":null
}
示例 4:创建每日定期事件
请求
第四个示例展示了如何创建每日定期事件。 从 2020 年 2 月 25 日起,事件每天从下午 12:00 到下午 2:00 发生两次。
POST https://graph.microsoft.com/beta/me/events
Prefer: outlook.timezone="Pacific Standard Time"
Content-type: application/json
{
"subject": "Let's go for lunch",
"body": {
"contentType": "HTML",
"content": "Does noon work for you?"
},
"start": {
"dateTime": "2020-02-25T12:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2020-02-25T14:00:00",
"timeZone": "Pacific Standard Time"
},
"location":{
"displayName":"Harry's Bar"
},
"attendees": [
{
"emailAddress": {
"address":"AlexW@contoso.OnMicrosoft.com",
"name": "Alex Wilbur"
},
"type": "required"
}
],
"recurrence": {
"pattern": {
"type": "daily",
"interval": 1
},
"range": {
"type": "numbered",
"startDate": "2020-02-25",
"numberOfOccurrences": 2
}
}
}
在请求正文中,提供 event 对象的 JSON 表示形式。
响应
这是一个示例响应。注意:为提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#users('d3b9214b-dd8b-441d-b7dc-c446c9fa0e69')/calendar/events/$entity",
"@odata.etag": "W/\"NDznl+Uh50WkanaCOKHkaQAAhrvLSg==\"",
"id": "AAMkADU5NWAAA=",
"createdDateTime": "2020-02-18T22:13:47.2967773Z",
"lastModifiedDateTime": "2020-02-18T22:13:47.7398267Z",
"changeKey": "NDznl+Uh50WkanaCOKHkaQAAhrvLSg==",
"categories": [],
"originalStartTimeZone": "Pacific Standard Time",
"originalEndTimeZone": "Pacific Standard Time",
"uid": "040000008200E00074C5B7101A82E0080000000027B6D5B0A8E6D50100000000000000001000000065CD4D206C79D44CBF53D42B6E79CE55",
"reminderMinutesBeforeStart": 15,
"isReminderOn": true,
"hasAttachments": false,
"hideAttendees": false,
"subject": "Let's go for lunch",
"bodyPreview": "Does noon work for you?",
"importance": "normal",
"sensitivity": "normal",
"isAllDay": false,
"isCancelled": false,
"isDraft": false,
"isOrganizer": true,
"responseRequested": true,
"seriesMasterId": null,
"showAs": "busy",
"type": "seriesMaster",
"webLink": "https://outlook.office365.com/owa/?itemid=AAMkADU5NWAAA%3D&exvsurl=1&path=/calendar/item",
"onlineMeetingUrl": null,
"isOnlineMeeting": false,
"onlineMeetingProvider": "unknown",
"allowNewTimeProposals": true,
"onlineMeeting": null,
"responseStatus": {
"response": "organizer",
"time": "0001-01-01T00:00:00Z"
},
"body": {
"contentType": "html",
"content": "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta content=\"text/html; charset=us-ascii\">\r\n</head>\r\n<body>\r\nDoes noon work for you?\r\n</body>\r\n</html>\r\n"
},
"start": {
"dateTime": "2020-02-25T12:00:00.0000000",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2020-02-25T14:00:00.0000000",
"timeZone": "Pacific Standard Time"
},
"location": {
"displayName": "Harry's Bar",
"locationType": "default",
"uniqueId": "Harry's Bar",
"uniqueIdType": "private"
},
"locations": [
{
"displayName": "Harry's Bar",
"locationType": "default",
"uniqueId": "Harry's Bar",
"uniqueIdType": "private"
}
],
"recurrence": {
"pattern": {
"type": "daily",
"interval": 1,
"month": 0,
"dayOfMonth": 0,
"firstDayOfWeek": "sunday",
"index": "first"
},
"range": {
"type": "numbered",
"startDate": "2020-02-25",
"endDate": "0001-01-01",
"recurrenceTimeZone": "Pacific Standard Time",
"numberOfOccurrences": 2
}
},
"attendees": [
{
"type": "required",
"status": {
"response": "none",
"time": "0001-01-01T00:00:00Z"
},
"emailAddress": {
"name": "Alex Wilber",
"address": "AlexW@contoso.OnMicrosoft.com"
}
}
],
"organizer": {
"emailAddress": {
"name": "Adele Vance",
"address": "AdeleV@contoso.OnMicrosoft.com"
}
}
}
示例 5:创建事件并启用为联机会议
请求
下面是创建事件并将其启用为联机会议的请求示例。 它使用 Prefer: outlook.timezone 请求头指定响应中 开始 时间和 结束 时间的时区。
POST https://graph.microsoft.com/beta/me/events
Prefer: outlook.timezone="Pacific Standard Time"
Content-type: application/json
{
"subject": "Let's go for lunch",
"body": {
"contentType": "HTML",
"content": "Does noon work for you?"
},
"start": {
"dateTime": "2017-04-15T12:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2017-04-15T14:00:00",
"timeZone": "Pacific Standard Time"
},
"location":{
"displayName":"Harry's Bar"
},
"attendees": [
{
"emailAddress": {
"address":"samanthab@contoso.onmicrosoft.com",
"name": "Samantha Booth"
},
"type": "required"
}
],
"allowNewTimeProposals": true,
"isOnlineMeeting": true,
"onlineMeetingProvider": "teamsForBusiness"
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var @event = new Event
{
Subject = "Let's go for lunch",
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "Does noon work for you?"
},
Start = new DateTimeTimeZone
{
DateTime = "2017-04-15T12:00:00",
TimeZone = "Pacific Standard Time"
},
End = new DateTimeTimeZone
{
DateTime = "2017-04-15T14:00:00",
TimeZone = "Pacific Standard Time"
},
Location = new Location
{
DisplayName = "Harry's Bar"
},
Attendees = new List<Attendee>()
{
new Attendee
{
EmailAddress = new EmailAddress
{
Address = "samanthab@contoso.onmicrosoft.com",
Name = "Samantha Booth"
},
Type = AttendeeType.Required
}
},
AllowNewTimeProposals = true,
IsOnlineMeeting = true,
OnlineMeetingProvider = OnlineMeetingProviderType.TeamsForBusiness
};
await graphClient.Me.Events
.Request()
.Header("Prefer","outlook.timezone=\"Pacific Standard Time\"")
.AddAsync(@event);
const options = {
authProvider,
};
const client = Client.init(options);
const event = {
subject: 'Let\'s go for lunch',
body: {
contentType: 'HTML',
content: 'Does noon work for you?'
},
start: {
dateTime: '2017-04-15T12:00:00',
timeZone: 'Pacific Standard Time'
},
end: {
dateTime: '2017-04-15T14:00:00',
timeZone: 'Pacific Standard Time'
},
location: {
displayName: 'Harry\'s Bar'
},
attendees: [
{
emailAddress: {
address: 'samanthab@contoso.onmicrosoft.com',
name: 'Samantha Booth'
},
type: 'required'
}
],
allowNewTimeProposals: true,
isOnlineMeeting: true,
onlineMeetingProvider: 'teamsForBusiness'
};
await client.api('/me/events')
.version('beta')
.post(event);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/events"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"outlook.timezone=\"Pacific Standard Time\"" forHTTPHeaderField:@"Prefer"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphEvent *event = [[MSGraphEvent alloc] init];
[event setSubject:@"Let's go for lunch"];
MSGraphItemBody *body = [[MSGraphItemBody alloc] init];
[body setContentType: [MSGraphBodyType html]];
[body setContent:@"Does noon work for you?"];
[event setBody:body];
MSGraphDateTimeTimeZone *start = [[MSGraphDateTimeTimeZone alloc] init];
[start setDateTime: "2017-04-15T12:00:00"];
[start setTimeZone:@"Pacific Standard Time"];
[event setStart:start];
MSGraphDateTimeTimeZone *end = [[MSGraphDateTimeTimeZone alloc] init];
[end setDateTime: "2017-04-15T14:00:00"];
[end setTimeZone:@"Pacific Standard Time"];
[event setEnd:end];
MSGraphLocation *location = [[MSGraphLocation alloc] init];
[location setDisplayName:@"Harry's Bar"];
[event setLocation:location];
NSMutableArray *attendeesList = [[NSMutableArray alloc] init];
MSGraphAttendee *attendees = [[MSGraphAttendee alloc] init];
MSGraphEmailAddress *emailAddress = [[MSGraphEmailAddress alloc] init];
[emailAddress setAddress:@"samanthab@contoso.onmicrosoft.com"];
[emailAddress setName:@"Samantha Booth"];
[attendees setEmailAddress:emailAddress];
[attendees setType: [MSGraphAttendeeType required]];
[attendeesList addObject: attendees];
[event setAttendees:attendeesList];
[event setAllowNewTimeProposals: true];
[event setIsOnlineMeeting: true];
[event setOnlineMeetingProvider: [MSGraphOnlineMeetingProviderType teamsForBusiness]];
NSError *error;
NSData *eventData = [event getSerializedDataWithError:&error];
[urlRequest setHTTPBody:eventData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new HeaderOption("Prefer", "outlook.timezone=\"Pacific Standard Time\""));
Event event = new Event();
event.subject = "Let's go for lunch";
ItemBody body = new ItemBody();
body.contentType = BodyType.HTML;
body.content = "Does noon work for you?";
event.body = body;
DateTimeTimeZone start = new DateTimeTimeZone();
start.dateTime = "2017-04-15T12:00:00";
start.timeZone = "Pacific Standard Time";
event.start = start;
DateTimeTimeZone end = new DateTimeTimeZone();
end.dateTime = "2017-04-15T14:00:00";
end.timeZone = "Pacific Standard Time";
event.end = end;
Location location = new Location();
location.displayName = "Harry's Bar";
event.location = location;
LinkedList<Attendee> attendeesList = new LinkedList<Attendee>();
Attendee attendees = new Attendee();
EmailAddress emailAddress = new EmailAddress();
emailAddress.address = "samanthab@contoso.onmicrosoft.com";
emailAddress.name = "Samantha Booth";
attendees.emailAddress = emailAddress;
attendees.type = AttendeeType.REQUIRED;
attendeesList.add(attendees);
event.attendees = attendeesList;
event.allowNewTimeProposals = true;
event.isOnlineMeeting = true;
event.onlineMeetingProvider = OnlineMeetingProviderType.TEAMS_FOR_BUSINESS;
graphClient.me().events()
.buildRequest( requestOptions )
.post(event);
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewEvent()
subject := "Let's go for lunch"
requestBody.SetSubject(&subject)
body := msgraphsdk.NewItemBody()
requestBody.SetBody(body)
contentType := "HTML"
body.SetContentType(&contentType)
content := "Does noon work for you?"
body.SetContent(&content)
start := msgraphsdk.NewDateTimeTimeZone()
requestBody.SetStart(start)
dateTime := "2017-04-15T12:00:00"
start.SetDateTime(&dateTime)
timeZone := "Pacific Standard Time"
start.SetTimeZone(&timeZone)
end := msgraphsdk.NewDateTimeTimeZone()
requestBody.SetEnd(end)
dateTime := "2017-04-15T14:00:00"
end.SetDateTime(&dateTime)
timeZone := "Pacific Standard Time"
end.SetTimeZone(&timeZone)
location := msgraphsdk.NewLocation()
requestBody.SetLocation(location)
displayName := "Harry's Bar"
location.SetDisplayName(&displayName)
requestBody.SetAttendees( []Attendee {
msgraphsdk.NewAttendee(),
SetAdditionalData(map[string]interface{}{
"type": "required",
}
}
allowNewTimeProposals := true
requestBody.SetAllowNewTimeProposals(&allowNewTimeProposals)
isOnlineMeeting := true
requestBody.SetIsOnlineMeeting(&isOnlineMeeting)
onlineMeetingProvider := "teamsForBusiness"
requestBody.SetOnlineMeetingProvider(&onlineMeetingProvider)
headers := map[string]string{
"Prefer": "outlook.timezone="Pacific Standard Time""
}
options := &msgraphsdk.EventsRequestBuilderPostRequestConfiguration{
Headers: headers,
}
result, err := graphClient.Me().Events().PostWithRequestConfigurationAndResponseHandler(requestBody, options, nil)
Import-Module Microsoft.Graph.Calendar
$params = @{
Subject = "Let's go for lunch"
Body = @{
ContentType = "HTML"
Content = "Does noon work for you?"
}
Start = @{
DateTime = "2017-04-15T12:00:00"
TimeZone = "Pacific Standard Time"
}
End = @{
DateTime = "2017-04-15T14:00:00"
TimeZone = "Pacific Standard Time"
}
Location = @{
DisplayName = "Harry's Bar"
}
Attendees = @(
@{
EmailAddress = @{
Address = "samanthab@contoso.onmicrosoft.com"
Name = "Samantha Booth"
}
Type = "required"
}
)
AllowNewTimeProposals = $true
IsOnlineMeeting = $true
OnlineMeetingProvider = "teamsForBusiness"
}
# A UPN can also be used as -UserId.
New-MgUserEvent -UserId $userId -BodyParameter $params
在请求正文中,提供 event 对象的 JSON 表示形式。
响应
下面是一个响应示例,显示 start 和 end 属性使用 Prefer: outlook.timezone 标头中指定的时区。
注意:为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context":"https://graph.microsoft.com/beta/$metadata#users('cd209b0b-3f83-4c35-82d2-d88a61820480')/events/$entity",
"@odata.etag":"W/\"ZlnW4RIAV06KYYwlrfNZvQAALfZeRQ==\"",
"id":"AAMkAGI1AAAt8AHjAAA=",
"createdDateTime":"2017-04-15T03:00:50.7579581Z",
"lastModifiedDateTime":"2017-04-15T03:00:51.245372Z",
"changeKey":"ZlnW4RIAV06KYYwlrfNZvQAALfZeRQ==",
"categories":[
],
"originalStartTimeZone":"Pacific Standard Time",
"originalEndTimeZone":"Pacific Standard Time",
"uid":"040000008200E00074C5B7101A82E00800000000DA2B357D94B5D201000000000000000010000000EC4597557F0CB34EA4CC2887EA7B17C3",
"reminderMinutesBeforeStart":15,
"isReminderOn":true,
"hasAttachments":false,
"hideAttendees": false,
"subject":"Let's go brunch",
"bodyPreview":"Does noon work for you?",
"importance":"normal",
"sensitivity":"normal",
"isAllDay":false,
"isCancelled":false,
"isDraft": false,
"isOrganizer":true,
"responseRequested":true,
"seriesMasterId":null,
"showAs":"busy",
"type":"singleInstance",
"webLink":"https://outlook.office365.com/owa/?itemid=AAMkAGI1AAAt9AHjAAA%3D&exvsurl=1&path=/calendar/item",
"onlineMeetingUrl":null,
"isOnlineMeeting": true,
"onlineMeetingProvider": "teamsForBusiness",
"allowNewTimeProposals": true,
"responseStatus":{
"response":"organizer",
"time":"0001-01-01T00:00:00Z"
},
"body":{
"contentType":"html",
"content":"<html><head></head><body>Does late morning work for you?</body></html>"
},
"start":{
"dateTime":"2017-04-15T11:00:00.0000000",
"timeZone":"Pacific Standard Time"
},
"end":{
"dateTime":"2017-04-15T12:00:00.0000000",
"timeZone":"Pacific Standard Time"
},
"location": {
"displayName": "Harry's Bar",
"locationType": "default",
"uniqueId": "Harry's Bar",
"uniqueIdType": "private"
},
"locations": [
{
"displayName": "Harry's Bar",
"locationType": "default",
"uniqueIdType": "unknown"
}
],
"recurrence":null,
"attendees":[
{
"type":"required",
"status":{
"response":"none",
"time":"0001-01-01T00:00:00Z"
},
"emailAddress":{
"name":"Samantha Booth",
"address":"samanthab@contoso.onmicrosoft.com"
}
}
],
"organizer":{
"emailAddress":{
"name":"Dana Swope",
"address":"danas@contoso.onmicrosoft.com"
}
},
"onlineMeeting": {
"joinUrl": "https://teams.microsoft.com/l/meetup-join/19%3ameeting_NzIyNzhlMGEtM2YyZC00ZmY0LTlhNzUtZmZjNWFmZGNlNzE2%40thread.v2/0?context=%7b%22Tid%22%3a%2272f988bf-86f1-41af-91ab-2d7cd011db47%22%2c%22Oid%22%3a%22bc55b173-cff6-457d-b7a1-64bda7d7581a%22%7d",
"conferenceId": "177513992",
"tollNumber": "+1 425 555 0123"
}
}
另请参阅