Namespace: microsoft.graph
Important
APIs under the /beta
version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. To determine whether an API is available in v1.0, use the Version selector.
Use this API to create a new event.
This API is available in the following national cloud deployments.
Global service |
US Government L4 |
US Government L5 (DOD) |
China operated by 21Vianet |
✅ |
✅ |
✅ |
✅ |
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions.
Permission type |
Permissions (from least to most privileged) |
Delegated (work or school account) |
Group.ReadWrite.All |
Delegated (personal Microsoft account) |
Not supported. |
Application |
Not supported. |
HTTP request
POST /groups/{id}/events
POST /groups/{id}/calendar/events
Request body
In the request body, supply a JSON representation of an event object.
Response
If successful, this method returns a 201 Created
response code and an event object in the response body.
Example
Request
The following example shows a request.
POST https://graph.microsoft.com/beta/groups/01d4ee64-15ce-491e-bad1-b91aa3223df4/events
Content-type: application/json
{
"subject": "Let's go for lunch",
"body": {
"contentType": "HTML",
"content": "Does late morning work for you?"
},
"start": {
"dateTime": "2019-06-15T12:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2019-06-15T14:00:00",
"timeZone": "Pacific Standard Time"
},
"___location":{
"displayName":"Harry's Bar"
},
"attendees": [
{
"emailAddress": {
"address":"adelev@contoso.com",
"name": "Adele Vance"
},
"type": "required"
}
]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new Event
{
Subject = "Let's go for lunch",
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "Does late morning work for you?",
},
Start = new DateTimeTimeZone
{
DateTime = "2019-06-15T12:00:00",
TimeZone = "Pacific Standard Time",
},
End = new DateTimeTimeZone
{
DateTime = "2019-06-15T14:00:00",
TimeZone = "Pacific Standard Time",
},
Location = new Location
{
DisplayName = "Harry's Bar",
},
Attendees = new List<Attendee>
{
new Attendee
{
EmailAddress = new EmailAddress
{
Address = "adelev@contoso.com",
Name = "Adele Vance",
},
Type = AttendeeType.Required,
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Groups["{group-id}"].Events.PostAsync(requestBody);
mgc-beta groups events create --group-id {group-id} --body '{\
"subject": "Let's go for lunch",\
"body": {\
"contentType": "HTML",\
"content": "Does late morning work for you?"\
},\
"start": {\
"dateTime": "2019-06-15T12:00:00",\
"timeZone": "Pacific Standard Time"\
},\
"end": {\
"dateTime": "2019-06-15T14:00:00",\
"timeZone": "Pacific Standard Time"\
},\
"___location":{\
"displayName":"Harry's Bar"\
},\
"attendees": [\
{\
"emailAddress": {\
"address":"adelev@contoso.com",\
"name": "Adele Vance"\
},\
"type": "required"\
}\
]\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewEvent()
subject := "Let's go for lunch"
requestBody.SetSubject(&subject)
body := graphmodels.NewItemBody()
contentType := graphmodels.HTML_BODYTYPE
body.SetContentType(&contentType)
content := "Does late morning work for you?"
body.SetContent(&content)
requestBody.SetBody(body)
start := graphmodels.NewDateTimeTimeZone()
dateTime := "2019-06-15T12:00:00"
start.SetDateTime(&dateTime)
timeZone := "Pacific Standard Time"
start.SetTimeZone(&timeZone)
requestBody.SetStart(start)
end := graphmodels.NewDateTimeTimeZone()
dateTime := "2019-06-15T14:00:00"
end.SetDateTime(&dateTime)
timeZone := "Pacific Standard Time"
end.SetTimeZone(&timeZone)
requestBody.SetEnd(end)
___location := graphmodels.NewLocation()
displayName := "Harry's Bar"
___location.SetDisplayName(&displayName)
requestBody.SetLocation(___location)
attendee := graphmodels.NewAttendee()
emailAddress := graphmodels.NewEmailAddress()
address := "adelev@contoso.com"
emailAddress.SetAddress(&address)
name := "Adele Vance"
emailAddress.SetName(&name)
attendee.SetEmailAddress(emailAddress)
type := graphmodels.REQUIRED_ATTENDEETYPE
attendee.SetType(&type)
attendees := []graphmodels.Attendeeable {
attendee,
}
requestBody.SetAttendees(attendees)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
events, err := graphClient.Groups().ByGroupId("group-id").Events().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Event event = new Event();
event.setSubject("Let's go for lunch");
ItemBody body = new ItemBody();
body.setContentType(BodyType.Html);
body.setContent("Does late morning work for you?");
event.setBody(body);
DateTimeTimeZone start = new DateTimeTimeZone();
start.setDateTime("2019-06-15T12:00:00");
start.setTimeZone("Pacific Standard Time");
event.setStart(start);
DateTimeTimeZone end = new DateTimeTimeZone();
end.setDateTime("2019-06-15T14:00:00");
end.setTimeZone("Pacific Standard Time");
event.setEnd(end);
Location ___location = new Location();
___location.setDisplayName("Harry's Bar");
event.setLocation(___location);
LinkedList<Attendee> attendees = new LinkedList<Attendee>();
Attendee attendee = new Attendee();
EmailAddress emailAddress = new EmailAddress();
emailAddress.setAddress("adelev@contoso.com");
emailAddress.setName("Adele Vance");
attendee.setEmailAddress(emailAddress);
attendee.setType(AttendeeType.Required);
attendees.add(attendee);
event.setAttendees(attendees);
Event result = graphClient.groups().byGroupId("{group-id}").events().post(event);
const options = {
authProvider,
};
const client = Client.init(options);
const event = {
subject: 'Let\'s go for lunch',
body: {
contentType: 'HTML',
content: 'Does late morning work for you?'
},
start: {
dateTime: '2019-06-15T12:00:00',
timeZone: 'Pacific Standard Time'
},
end: {
dateTime: '2019-06-15T14:00:00',
timeZone: 'Pacific Standard Time'
},
___location: {
displayName: 'Harry\'s Bar'
},
attendees: [
{
emailAddress: {
address: 'adelev@contoso.com',
name: 'Adele Vance'
},
type: 'required'
}
]
};
await client.api('/groups/01d4ee64-15ce-491e-bad1-b91aa3223df4/events')
.version('beta')
.post(event);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\Event;
use Microsoft\Graph\Beta\Generated\Models\ItemBody;
use Microsoft\Graph\Beta\Generated\Models\BodyType;
use Microsoft\Graph\Beta\Generated\Models\DateTimeTimeZone;
use Microsoft\Graph\Beta\Generated\Models\Location;
use Microsoft\Graph\Beta\Generated\Models\Attendee;
use Microsoft\Graph\Beta\Generated\Models\EmailAddress;
use Microsoft\Graph\Beta\Generated\Models\AttendeeType;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Event();
$requestBody->setSubject('Let\'s go for lunch');
$body = new ItemBody();
$body->setContentType(new BodyType('hTML'));
$body->setContent('Does late morning work for you?');
$requestBody->setBody($body);
$start = new DateTimeTimeZone();
$start->setDateTime('2019-06-15T12:00:00');
$start->setTimeZone('Pacific Standard Time');
$requestBody->setStart($start);
$end = new DateTimeTimeZone();
$end->setDateTime('2019-06-15T14:00:00');
$end->setTimeZone('Pacific Standard Time');
$requestBody->setEnd($end);
$___location = new Location();
$___location->setDisplayName('Harry\'s Bar');
$requestBody->setLocation($___location);
$attendeesAttendee1 = new Attendee();
$attendeesAttendee1EmailAddress = new EmailAddress();
$attendeesAttendee1EmailAddress->setAddress('adelev@contoso.com');
$attendeesAttendee1EmailAddress->setName('Adele Vance');
$attendeesAttendee1->setEmailAddress($attendeesAttendee1EmailAddress);
$attendeesAttendee1->setType(new AttendeeType('required'));
$attendeesArray []= $attendeesAttendee1;
$requestBody->setAttendees($attendeesArray);
$result = $graphServiceClient->groups()->byGroupId('group-id')->events()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Calendar
$params = @{
subject = "Let's go for lunch"
body = @{
contentType = "HTML"
content = "Does late morning work for you?"
}
start = @{
dateTime = "2019-06-15T12:00:00"
timeZone = "Pacific Standard Time"
}
end = @{
dateTime = "2019-06-15T14:00:00"
timeZone = "Pacific Standard Time"
}
___location = @{
displayName = "Harry's Bar"
}
attendees = @(
@{
emailAddress = @{
address = "adelev@contoso.com"
name = "Adele Vance"
}
type = "required"
}
)
}
New-MgBetaGroupEvent -GroupId $groupId -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.event import Event
from msgraph_beta.generated.models.item_body import ItemBody
from msgraph_beta.generated.models.body_type import BodyType
from msgraph_beta.generated.models.date_time_time_zone import DateTimeTimeZone
from msgraph_beta.generated.models.___location import Location
from msgraph_beta.generated.models.attendee import Attendee
from msgraph_beta.generated.models.email_address import EmailAddress
from msgraph_beta.generated.models.attendee_type import AttendeeType
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Event(
subject = "Let's go for lunch",
body = ItemBody(
content_type = BodyType.Html,
content = "Does late morning work for you?",
),
start = DateTimeTimeZone(
date_time = "2019-06-15T12:00:00",
time_zone = "Pacific Standard Time",
),
end = DateTimeTimeZone(
date_time = "2019-06-15T14:00:00",
time_zone = "Pacific Standard Time",
),
___location = Location(
display_name = "Harry's Bar",
),
attendees = [
Attendee(
email_address = EmailAddress(
address = "adelev@contoso.com",
name = "Adele Vance",
),
type = AttendeeType.Required,
),
],
)
result = await graph_client.groups.by_group_id('group-id').events.post(request_body)
Response
The following example shows the response.
Note: The response object shown here might be shortened for readability.
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#groups('01d4ee64-15ce-491e-bad1-b91aa3223df4')/events/$entity",
"@odata.etag": "W/\"Na8DfbsBGUG8JeyvlwNi5wAAHMK0mg==\"",
"id": "AAMkADZ_XA2LnAAAcwiSBAAA=",
"createdDateTime": "2019-05-20T02:14:32.7419058Z",
"lastModifiedDateTime": "2019-05-20T02:14:33.342409Z",
"changeKey": "Na8DfbsBGUG8JeyvlwNi5wAAHMK0mg==",
"categories": [],
"originalStartTimeZone": "Pacific Standard Time",
"originalEndTimeZone": "Pacific Standard Time",
"uid": "040000008200E00074C5B7101A82E00800000000DE7664C3B10ED501000000000000000010000000EC2760BC8BC4AF4BAC1C9730C3E534AC",
"reminderMinutesBeforeStart": 15,
"isReminderOn": true,
"hasAttachments": 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": "singleInstance",
"webLink": "https://outlook.office365.com/owa/?itemid=AAMkADZ%2BXA2LnAAAcwiSBAAA%3D&exvsurl=1&path=/calendar/item",
"onlineMeetingUrl": null,
"recurrence": 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 late morning work for you?\r\n</body>\r\n</html>\r\n"
},
"start": {
"dateTime": "2019-06-15T12:00:00.0000000",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2019-06-15T14: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"
}
],
"attendees": [
{
"type": "required",
"status": {
"response": "none",
"time": "0001-01-01T00:00:00Z"
},
"emailAddress": {
"name": "Adele Vance",
"address": "adelev@contoso.com"
}
}
],
"organizer": {
"emailAddress": {
"name": "Retail",
"address": "Retail@contoso.com"
}
}
}