# Update event calendar availability schedule

PUT https://services.leadconnectorhq.com/calendars/schedules/event-calendar/{calendarId}

Update the availability schedule for a specific event calendar. Only provided fields will be updated. The calendar ID is provided in the path.

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `calendars.write`

## Parameters

### Header Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Version` | string | Yes | API Version |

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `calendarId` | string | Yes | Unique identifier of the event calendar |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/calendars/schedules/event-calendar/{calendarId}": {
      "put": {
        "summary": "Update event calendar availability schedule",
        "operationId": "updateEventCalendarAvailabilitySchedule",
        "description": "Update the availability schedule for a specific event calendar. Only provided fields will be updated. The calendar ID is provided in the path.",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          },
          {
            "name": "calendarId",
            "required": true,
            "in": "path",
            "description": "Unique identifier of the event calendar",
            "schema": {
              "example": "WvVX9LpvlBO6K506xLbp",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateEventCalendarScheduleDTO"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Schedule updated successfully for the event calendar",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EventCalendarScheduleWrapperDTO"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request parameters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                }
              }
            }
          },
          "401": {
            "description": "User not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedDTO"
                }
              }
            }
          },
          "404": {
            "description": "Event calendar or schedule with the specified ID was not found"
          },
          "422": {
            "description": "Validation errors in schedule rules or conflicting data",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnprocessableDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": [
              "calendars.write"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account.",
        "type": "http"
      },
      "Agency-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency (OR) Private Integration Token of Agency.",
        "type": "http"
      },
      "Agency-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency.",
        "type": "http"
      }
    },
    "schemas": {
      "UpdateEventCalendarScheduleDTO": {
        "type": "object",
        "properties": {
          "rules": {
            "description": "Updated schedule rules defining when the schedule is active",
            "example": [
              {
                "type": "wday",
                "day": "monday",
                "intervals": [
                  {
                    "from": "08:00",
                    "to": "18:00"
                  }
                ]
              }
            ],
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "wday",
                    "date"
                  ],
                  "description": "Type of schedule rule - weekday (recurring) or date (specific date)",
                  "example": "wday"
                },
                "intervals": {
                  "description": "Time intervals for the rule (e.g., 9 AM to 5 PM)",
                  "example": [
                    {
                      "from": "09:00",
                      "to": "17:00"
                    }
                  ],
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "from": {
                        "type": "string",
                        "description": "Start time in HH:MM format (24-hour format)",
                        "example": "09:00",
                        "pattern": "^([01]?[0-9]|2[0-3]):[0-5][0-9]$"
                      },
                      "to": {
                        "type": "string",
                        "description": "End time in HH:MM format (24-hour format)",
                        "example": "17:00",
                        "pattern": "^([01]?[0-9]|2[0-3]):[0-5][0-9]$"
                      }
                    },
                    "required": [
                      "from",
                      "to"
                    ],
                    "title": "ScheduleIntervalDTO"
                  }
                },
                "date": {
                  "type": "string",
                  "description": "Specific date in YYYY-MM-DD format (only for date-type rules)",
                  "example": "2023-04-15",
                  "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                },
                "day": {
                  "type": "string",
                  "enum": [
                    "sunday",
                    "monday",
                    "tuesday",
                    "wednesday",
                    "thursday",
                    "friday",
                    "saturday"
                  ],
                  "description": "Day of week (only for weekday-type rules)",
                  "example": "monday"
                }
              },
              "required": [
                "type",
                "intervals"
              ],
              "title": "ScheduleRuleDTO"
            }
          },
          "timezone": {
            "type": "string",
            "description": "Updated timezone for the schedule (IANA timezone identifier)",
            "example": "America/Los_Angeles",
            "pattern": "^[A-Za-z_]+/[A-Za-z_]+$"
          }
        },
        "title": "UpdateEventCalendarScheduleDTO"
      },
      "EventCalendarScheduleWrapperDTO": {
        "type": "object",
        "properties": {
          "schedule": {
            "description": "The event calendar schedule",
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "timezone": {
                    "type": "string",
                    "description": "Timezone for the schedule (IANA timezone identifier)",
                    "example": "America/New_York"
                  },
                  "rules": {
                    "description": "Schedule rules defining when the schedule is active",
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "enum": [
                            "wday",
                            "date"
                          ],
                          "description": "Type of schedule rule - weekday (recurring) or date (specific date)",
                          "example": "wday"
                        },
                        "intervals": {
                          "description": "Time intervals for the rule (e.g., 9 AM to 5 PM)",
                          "example": [
                            {
                              "from": "09:00",
                              "to": "17:00"
                            }
                          ],
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "from": {
                                "type": "string",
                                "description": "Start time in HH:MM format (24-hour format)",
                                "example": "09:00",
                                "pattern": "^([01]?[0-9]|2[0-3]):[0-5][0-9]$"
                              },
                              "to": {
                                "type": "string",
                                "description": "End time in HH:MM format (24-hour format)",
                                "example": "17:00",
                                "pattern": "^([01]?[0-9]|2[0-3]):[0-5][0-9]$"
                              }
                            },
                            "required": [
                              "from",
                              "to"
                            ],
                            "title": "ScheduleIntervalDTO"
                          }
                        },
                        "date": {
                          "type": "string",
                          "description": "Specific date in YYYY-MM-DD format (only for date-type rules)",
                          "example": "2023-04-15",
                          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                        },
                        "day": {
                          "type": "string",
                          "enum": [
                            "sunday",
                            "monday",
                            "tuesday",
                            "wednesday",
                            "thursday",
                            "friday",
                            "saturday"
                          ],
                          "description": "Day of week (only for weekday-type rules)",
                          "example": "monday"
                        }
                      },
                      "required": [
                        "type",
                        "intervals"
                      ],
                      "title": "ScheduleRuleDTO"
                    },
                    "example": [
                      {
                        "type": "weekday",
                        "day": "monday",
                        "intervals": [
                          {
                            "from": "09:00",
                            "to": "17:00"
                          }
                        ]
                      }
                    ]
                  },
                  "calendarId": {
                    "type": "string",
                    "description": "Calendar ID associated with the schedule",
                    "example": "WvVX9LpvlBO6K506xLbp"
                  },
                  "dateAdded": {
                    "type": "string",
                    "description": "Information about who created the schedule",
                    "example": "2023-01-15T10:30:00.000Z"
                  },
                  "dateUpdated": {
                    "type": "string",
                    "description": "Information about who last updated the schedule",
                    "example": "2023-01-20T14:45:00.000Z"
                  }
                },
                "required": [
                  "timezone",
                  "rules",
                  "calendarId"
                ],
                "title": "EventCalendarScheduleResponseDTO"
              }
            ],
            "example": {
              "timezone": "America/New_York",
              "rules": [
                {
                  "type": "weekday",
                  "day": "monday",
                  "intervals": [
                    {
                      "from": "09:00",
                      "to": "17:00"
                    }
                  ]
                }
              ],
              "calendarId": "WvVX9LpvlBO6K506xLbp"
            }
          }
        },
        "required": [
          "schedule"
        ],
        "title": "EventCalendarScheduleWrapperDTO"
      },
      "BadRequestDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 400
          },
          "message": {
            "type": "string",
            "example": "Bad Request"
          }
        },
        "title": "BadRequestDTO"
      },
      "UnauthorizedDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 401
          },
          "message": {
            "type": "string",
            "example": "Invalid token: access token is invalid"
          },
          "error": {
            "type": "string",
            "example": "Unauthorized"
          }
        },
        "title": "UnauthorizedDTO"
      },
      "UnprocessableDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 422
          },
          "message": {
            "example": [
              "Unprocessable Entity"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "error": {
            "type": "string",
            "example": "Unprocessable Entity"
          }
        },
        "title": "UnprocessableDTO"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X PUT 'https://services.leadconnectorhq.com/calendars/schedules/event-calendar/<calendarId>' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "rules": [
    {
      "type": "wday",
      "day": "monday",
      "intervals": [
        {
          "from": "08:00",
          "to": "18:00"
        }
      ]
    }
  ],
  "timezone": "America/Los_Angeles"
}'
```

**Node.js**

```javascript
const options = {
  method: 'PUT',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "rules": [
        {
          "type": "wday",
          "day": "monday",
          "intervals": [
            {
              "from": "08:00",
              "to": "18:00"
            }
          ]
        }
      ],
      "timezone": "America/Los_Angeles"
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/calendars/schedules/event-calendar/<calendarId>', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/calendars/schedules/event-calendar/{calendarId}"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "v3"
}

payload = {
    "rules": [
        {
            "type": "wday",
            "day": "monday",
            "intervals": [
                {
                    "from": "08:00",
                    "to": "18:00"
                }
            ]
        }
    ],
    "timezone": "America/Los_Angeles"
}

response = requests.put(url, json=payload, headers=headers)
print(response.json())
```

**PHP**

```php
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/calendars/schedules/event-calendar/<calendarId>',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'PUT',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "rules": [
    {
      "type": "wday",
      "day": "monday",
      "intervals": [
        {
          "from": "08:00",
          "to": "18:00"
        }
      ]
    }
  ],
  "timezone": "America/Los_Angeles"
}',
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

**Java**

```java
HttpResponse<String> response = Unirest
  .put("https://services.leadconnectorhq.com/calendars/schedules/event-calendar/<calendarId>")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"rules\":[{\"type\":\"wday\",\"day\":\"monday\",\"intervals\":[{\"from\":\"08:00\",\"to\":\"18:00\"}]}],\"timezone\":\"America/Los_Angeles\"}")
  .asString();
```

**Go**

```go
package main

import (
  "fmt"
  "net/http"
  "io"
  "strings"
)

func main() {
  url := "https://services.leadconnectorhq.com/calendars/schedules/event-calendar/<calendarId>"
  payload := strings.NewReader(`{
  "rules": [
    {
      "type": "wday",
      "day": "monday",
      "intervals": [
        {
          "from": "08:00",
          "to": "18:00"
        }
      ]
    }
  ],
  "timezone": "America/Los_Angeles"
}`)
  req, _ := http.NewRequest("PUT", url, payload)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "v3")

  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)
  fmt.Println(string(body))
}
```

**Ruby**

```ruby
require 'uri'
require 'net/http'

url = URI("https://services.leadconnectorhq.com/calendars/schedules/event-calendar/<calendarId>")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Put.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"
request["Content-Type"] = "application/json"
request.body = '{
  "rules": [
    {
      "type": "wday",
      "day": "monday",
      "intervals": [
        {
          "from": "08:00",
          "to": "18:00"
        }
      ]
    }
  ],
  "timezone": "America/Los_Angeles"
}'

response = http.request(request)
puts response.read_body
```

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "v3"
}

$body = '{
  "rules": [
    {
      "type": "wday",
      "day": "monday",
      "intervals": [
        {
          "from": "08:00",
          "to": "18:00"
        }
      ]
    }
  ],
  "timezone": "America/Los_Angeles"
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/calendars/schedules/event-calendar/<calendarId>' -Method 'PUT' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
