# Bulk update on-call schedule events

Replace all current and future on-call events in a single on-call schedule:

- Delete all events that start today at 0:00 UTC or later.
- Create new events. All newly created events also must start today at 0:00 UTC or later.

[endpoint]
base_url = "https://uptime.betterstack.com"
path = "/api/v2/on-calls/{schedule_id}/events"
method = "PUT"

[[path_param]]
name = "schedule_id"
description = "The ID of the on-call schedule you want to replace events for. Use `default` to refer to the default on-call schedule for the team."
required = true
type = "string"

[[body_param]]
name = "events"
description = '''List of events to create. These events will replace all existing future events within this schedule. Past events won't be replaced. Use the same event structure as if you were [creating a single event](https://betterstack.com/docs/uptime/api/create-on-call-calendar-event/). See example below.'''
required = true
type = "array"

[[header]]
name = "Authorization"
description = "Bearer `$TOKEN`"
required = true
type = "string"
[/endpoint]

[responses]
[[response]]
status = 200
description = '''The events were saved'''
body = '''{
  "events": [
    {
      "id": 12345,
      "users": ["tomas@betterstack.com"],
      "starts_at": "2024-09-04T22:00:00Z",
      "ends_at": "2024-09-05T22:00:00Z",
      "override": false
    },
    {
      "id": 23456,
      "users": ["simon@betterstack.com"],
      "starts_at": "2024-09-05T22:00:00Z",
      "ends_at": "2024-09-06T22:00:00Z",
      "override": false
    },
    {
      "id": 34567,
      "users": ["tomas@betterstack.com"],
      "starts_at": "2024-09-06T22:00:00Z",
      "ends_at": "2024-09-07T22:00:00Z",
      "override": true
    }
  ]
}'''

[[response]]
status = 422
description = '''The events were not saved'''
body='''{
  "errors":"Sorry, these attributes have unsupported values",
  "allowed_values": {
    "event": {
      "starts_at": [
        "must be today at 00:00 UTC or later"
      ]
    }
  }
}'''

[/responses]

#### Example cURL

```shell
[label Example]
curl --request PUT \
  --url "https://uptime.betterstack.com/api/v2/on-calls/default/events" \
  --header "Authorization: Bearer $TOKEN"
  --header "Content-Type: application/json"
  --data '{
    "events": [
      {
        "users": ["tomas@betterstack.com"],
        "starts_at": "2024-09-04T22:00:00Z",
        "ends_at": "2024-09-05T22:00:00Z"
      },
      {
        "users": ["simon@betterstack.com"],
        "starts_at": "2024-09-05T22:00:00Z",
        "ends_at": "2024-09-06T22:00:00Z"
      },
      {
        "users": ["tomas@betterstack.com"],
        "starts_at": "2024-09-06T22:00:00Z",
        "ends_at": "2024-09-07T22:00:00Z",
        "override": true
      }
    ]
  }'
```
