---
type: api
title: Add scheduled events to the calendar
description: ## Required authorization
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/operation/operation-ml-post-calendar-events
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/operation/operation-ml-post-calendar-events
products:
  - Elasticsearch
---

# Add scheduled events to the calendar

Availability: 6.2+

## Paths

- `POST` `/_ml/calendars/{calendar_id}/events`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/authentication#basicauth)
- [Bearer auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/authentication#bearerauth)

#### Path Parameters

- `calendar_id` (string Id)
  A string that uniquely identifies a calendar.

## Description



## Required authorization

* Cluster privileges: `manage_ml`

## Request Body

`application/json`

- `events` ([] CalendarEvent) — required
  A list of one of more scheduled events. The event’s start and end times can be specified as integer milliseconds since the epoch or as a string in ISO 8601 format.
  - `calendar_id` (string Id) — optional
    A string that uniquely identifies a calendar.
  - `event_id` (string Id) — optional
  - `description` (string) — required
    A description of the scheduled event.
  - `end_time` (DateTime) — required
    The timestamp for the end of the scheduled event in milliseconds since the epoch or ISO 8601 format.
  - `start_time` (DateTime) — required
    The timestamp for the beginning of the scheduled event in milliseconds since the epoch or ISO 8601 format.

## Response

`application/json`

- `events` ([] CalendarEvent)
  - `calendar_id` (string Id)
    A string that uniquely identifies a calendar.
  - `event_id` (string Id)
  - `description` (string)
    A description of the scheduled event.
  - `end_time` (DateTime)
    The timestamp for the end of the scheduled event in milliseconds since the epoch or ISO 8601 format.
  - `start_time` (DateTime)
    The timestamp for the beginning of the scheduled event in milliseconds since the epoch or ISO 8601 format.
## Code Examples

#### Console

```console
POST _ml/calendars/planned-outages/events
{
  "events" : [
    {"description": "event 1", "start_time": 1513641600000, "end_time": 1513728000000},
    {"description": "event 2", "start_time": 1513814400000, "end_time": 1513900800000},
    {"description": "event 3", "start_time": 1514160000000, "end_time": 1514246400000}
  ]
}
```

#### JavaScript

```javascript
const response = await client.ml.postCalendarEvents({
  calendar_id: "planned-outages",
  events: [
    {
      description: "event 1",
      start_time: 1513641600000,
      end_time: 1513728000000,
    },
    {
      description: "event 2",
      start_time: 1513814400000,
      end_time: 1513900800000,
    },
    {
      description: "event 3",
      start_time: 1514160000000,
      end_time: 1514246400000,
    },
  ],
});
```

#### Python

```python
resp = client.ml.post_calendar_events(
    calendar_id="planned-outages",
    events=[
        {
            "description": "event 1",
            "start_time": 1513641600000,
            "end_time": 1513728000000
        },
        {
            "description": "event 2",
            "start_time": 1513814400000,
            "end_time": 1513900800000
        },
        {
            "description": "event 3",
            "start_time": 1514160000000,
            "end_time": 1514246400000
        }
    ],
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_ml/calendars/planned-outages/events" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "events": [
      {
        "description": "event 1",
        "start_time": 1513641600000,
        "end_time": 1513728000000
      },
      {
        "description": "event 2",
        "start_time": 1513814400000,
        "end_time": 1513900800000
      },
      {
        "description": "event 3",
        "start_time": 1514160000000,
        "end_time": 1514246400000
      }
    ]
  }'
```

#### Java

```java
client.ml().postCalendarEvents(p -> p
    .calendarId("planned-outages")
    .events(List.of(CalendarEvent.of(c -> c
            .description("event 1")
            .endTime(DateTime.ofEpochMilli(1513728000000L))
            .startTime(DateTime.ofEpochMilli(1513641600000L))),CalendarEvent.of(c -> c
            .description("event 2")
            .endTime(DateTime.ofEpochMilli(1513900800000L))
            .startTime(DateTime.ofEpochMilli(1513814400000L))),CalendarEvent.of(c -> c
            .description("event 3")
            .endTime(DateTime.ofEpochMilli(1514246400000L))
            .startTime(DateTime.ofEpochMilli(1514160000000L)))))
);
```

#### C#

```c#
var response = await client.MachineLearning
    .PostCalendarEventsAsync(calendarId: "planned-outages", d1 => d1
        .Events(d2 => d2
            .Description("event 1")
            .EndTime(DateTimeOffset.Parse("2017-12-20T00:00:00.0000000+00:00", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind))
            .StartTime(DateTimeOffset.Parse("2017-12-19T00:00:00.0000000+00:00", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind)), d2 => d2
            .Description("event 2")
            .EndTime(DateTimeOffset.Parse("2017-12-22T00:00:00.0000000+00:00", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind))
            .StartTime(DateTimeOffset.Parse("2017-12-21T00:00:00.0000000+00:00", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind)), d2 => d2
            .Description("event 3")
            .EndTime(DateTimeOffset.Parse("2017-12-26T00:00:00.0000000+00:00", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind))
            .StartTime(DateTimeOffset.Parse("2017-12-25T00:00:00.0000000+00:00", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind))
        )
    );
```

#### PHP

```php
$resp = $client->ml()->postCalendarEvents([
    "calendar_id" => "planned-outages",
    "body" => [
        "events" => array(
            [
                "description" => "event 1",
                "start_time" => 1513641600000,
                "end_time" => 1513728000000,
            ],
            [
                "description" => "event 2",
                "start_time" => 1513814400000,
                "end_time" => 1513900800000,
            ],
            [
                "description" => "event 3",
                "start_time" => 1514160000000,
                "end_time" => 1514246400000,
            ],
        ),
    ],
]);
```

#### Ruby

```ruby
response = client.ml.post_calendar_events(
  calendar_id: "planned-outages",
  body: {
    "events": [
      {
        "description": "event 1",
        "start_time": 1513641600000,
        "end_time": 1513728000000
      },
      {
        "description": "event 2",
        "start_time": 1513814400000,
        "end_time": 1513900800000
      },
      {
        "description": "event 3",
        "start_time": 1514160000000,
        "end_time": 1514246400000
      }
    ]
  }
)
```

