Namespace: microsoft.graph
Use this API to create a new calendar in a calendar group for a user.
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) |
Calendars.ReadWrite |
Delegated (personal Microsoft account) |
Calendars.ReadWrite |
Application |
Calendars.ReadWrite |
HTTP request
A user's default calendarGroup.
POST /me/calendars
POST /users/{id | userPrincipalName}/calendars
Any calendarGroup of a user.
POST /me/calendarGroups/{id}/calendars
POST /users/{id | userPrincipalName}/calendarGroups/{id}/calendars
Request body
In the request body, supply a JSON representation of calendar object.
Response
If successful, this method returns 201 Created
response code and calendar object in the response body.
Example
Request
The following example shows a request.
POST https://graph.microsoft.com/v1.0/me/calendarGroups/AAMkADYAAAR9NR5AAA=/calendars
Content-type: application/json
{
"name": "Marketing calendar"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new Calendar
{
Name = "Marketing calendar",
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Me.CalendarGroups["{calendarGroup-id}"].Calendars.PostAsync(requestBody);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation.
mgc users calendar-groups calendars create --user-id {user-id} --calendar-group-id {calendarGroup-id} --body '{\
"name": "Marketing calendar"\
}\
'
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation.
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewCalendar()
name := "Marketing calendar"
requestBody.SetName(&name)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
calendars, err := graphClient.Me().CalendarGroups().ByCalendarGroupId("calendarGroup-id").Calendars().Post(context.Background(), requestBody, nil)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation.
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Calendar calendar = new Calendar();
calendar.setName("Marketing calendar");
Calendar result = graphClient.me().calendarGroups().byCalendarGroupId("{calendarGroup-id}").calendars().post(calendar);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation.
const options = {
authProvider,
};
const client = Client.init(options);
const calendar = {
name: 'Marketing calendar'
};
await client.api('/me/calendarGroups/AAMkADYAAAR9NR5AAA=/calendars')
.post(calendar);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation.
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Models\Calendar;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Calendar();
$requestBody->setName('Marketing calendar');
$result = $graphServiceClient->me()->calendarGroups()->byCalendarGroupId('calendarGroup-id')->calendars()->post($requestBody)->wait();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation.
Import-Module Microsoft.Graph.Calendar
$params = @{
name = "Marketing calendar"
}
# A UPN can also be used as -UserId.
New-MgUserCalendarGroupCalendar -UserId $userId -CalendarGroupId $calendarGroupId -BodyParameter $params
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation.
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.models.calendar import Calendar
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Calendar(
name = "Marketing calendar",
)
result = await graph_client.me.calendar_groups.by_calendar_group_id('calendarGroup-id').calendars.post(request_body)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation.
In the request body, supply a JSON representation of calendar object.
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/v1.0/$metadata#users('68ca8ec0-11f8-456b-a785-70d9936650d5')/calendarGroups('AAMkADYAAAR9NR5AAA%3D')/calendars/$entity",
"id": "AAMkADYCQM0GfRAAAcrRD-AAA=",
"name": "Marketing calendar",
"color": "auto",
"changeKey": "4xTfgHLeDkOqYVAkDNBn0QAAHKl46A==",
"canShare": true,
"canViewPrivateItems": true,
"canEdit": true,
"owner": {
"name": "Adele Vance",
"address": "adelev@contoso.com"
}
}