> ## Documentation Index
> Fetch the complete documentation index at: https://developers.leadwaycrm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create user availability schedule

> Create new schedule with specified rules, timezone, account, user and calendar associations.

Create new schedule with specified rules, timezone, account, user and calendar associations.

```http theme={null}
POST https://services.leadconnectorhq.com/calendars/schedules
```

## Autorización

<ParamField header="Authorization" type="string" required>
  Bearer token generado desde el portal Leadway. Ver [Autenticación](/authentication).
</ParamField>

<ParamField header="Version" type="string" required default="2021-07-28">
  Versión de la API.
</ParamField>

## Body

<ParamField body="rules" type="object[]">
  Schedule rules defining when the schedule is active

  <Expandable title="cada item">
    <ParamField body="type" type="string" required default="wday">
      Type of schedule rule - weekday (recurring) or date (specific date) Posibles valores: 'wday', 'date'
    </ParamField>

    <ParamField body="intervals" type="object[]" required>
      Time intervals for the rule (e.g., 9 AM to 5 PM)

      <Expandable title="cada item">
        <ParamField body="from" type="string" required default="09:00">
          Start time in HH:MM format (24-hour format)
        </ParamField>

        <ParamField body="to" type="string" required default="17:00">
          End time in HH:MM format (24-hour format)
        </ParamField>
      </Expandable>
    </ParamField>

    <ParamField body="date" type="string" default="2023-04-15">
      Specific date in YYYY-MM-DD format (only for date-type rules)
    </ParamField>

    <ParamField body="day" type="string" default="monday">
      Day of week (only for weekday-type rules) Posibles valores: 'sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="timezone" type="string" required default="America/New_York">
  Timezone for the schedule (IANA timezone identifier)
</ParamField>

<ParamField body="locationId" type="string" required default="IkqiJlXJ7o9h61tCHHod">
  Account ID where this schedule applies
</ParamField>

<ParamField body="name" type="string" required default="Business Hours Schedule">
  Human-readable name for the schedule
</ParamField>

<ParamField body="userId" type="string" required default="IkqiJlXJ7o9h61tCHHod">
  User ID associated with the schedule
</ParamField>

<ParamField body="calendarIds" type="string[]">
  Calendar IDs associated with the schedule
</ParamField>

## Respuestas

<Accordion title="201 - Schedule created successfully">
  <ResponseField name="schedule" type="object" required>
    Schedule
  </ResponseField>

  ```json theme={null}
  {}
  ```
</Accordion>

<Accordion title="400 - Invalid request parameters">
  ```json theme={null}
  {}
  ```
</Accordion>

<Accordion title="401 - User not authenticated">
  ```json theme={null}
  {}
  ```
</Accordion>

<Accordion title="422 - Validation errors in schedule rules or conflicting data">
  ```json theme={null}
  {}
  ```
</Accordion>

## Ejemplo

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST 'https://services.leadconnectorhq.com/calendars/schedules' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Version: 2021-07-28' \
    -H 'Content-Type: application/json' \
    -d '{
    "rules": [
      {
        "type": "wday",
        "day": "monday",
        "intervals": [
          {
            "from": "09:00",
            "to": "17:00"
          }
        ]
      }
    ],
    "timezone": "America/New_York",
    "locationId": "IkqiJlXJ7o9h61tCHHod",
    "name": "Business Hours Schedule",
    "userId": "IkqiJlXJ7o9h61tCHHod",
    "calendarIds": [
      "WvVX9LpvlBO6K506xLbp",
      "XyZ8MnQrStUvWxYzAbCdEf"
    ]
  }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://services.leadconnectorhq.com/calendars/schedules', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.LEADWAY_TOKEN}`,
      Version: '2021-07-28',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({"rules": [{"type": "wday", "day": "monday", "intervals": [{"from": "09:00", "to": "17:00"}]}], "timezone": "America/New_York", "locationId": "IkqiJlXJ7o9h61tCHHod", "name": "Business Hours Schedule", "userId": "IkqiJlXJ7o9h61tCHHod", "calendarIds": ["WvVX9LpvlBO6K506xLbp", "XyZ8MnQrStUvWxYzAbCdEf"]}),
  });
  const data = await response.json();
  ```

  ```python Python theme={null}
  import os, requests
  response = requests.request(
      'POST',
      'https://services.leadconnectorhq.com/calendars/schedules',
      headers={
          'Authorization': f"Bearer {os.environ['LEADWAY_TOKEN']}",
          'Version': '2021-07-28',
          'Content-Type': 'application/json',
      },
      json={"rules": [{"type": "wday", "day": "monday", "intervals": [{"from": "09:00", "to": "17:00"}]}], "timezone": "America/New_York", "locationId": "IkqiJlXJ7o9h61tCHHod", "name": "Business Hours Schedule", "userId": "IkqiJlXJ7o9h61tCHHod", "calendarIds": ["WvVX9LpvlBO6K506xLbp", "XyZ8MnQrStUvWxYzAbCdEf"]},
  )
  data = response.json()
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init('https://services.leadconnectorhq.com/calendars/schedules');
  curl_setopt_array($ch, [
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_CUSTOMREQUEST => 'POST',
      CURLOPT_HTTPHEADER => [
          'Authorization: Bearer ' . getenv('LEADWAY_TOKEN'),
          'Version: 2021-07-28',
          'Content-Type: application/json',
      ],
      CURLOPT_POSTFIELDS => json_encode({'rules': [{'type': 'wday', 'day': 'monday', 'intervals': [{'from': '09:00', 'to': '17:00'}]}], 'timezone': 'America/New_York', 'locationId': 'IkqiJlXJ7o9h61tCHHod', 'name': 'Business Hours Schedule', 'userId': 'IkqiJlXJ7o9h61tCHHod', 'calendarIds': ['WvVX9LpvlBO6K506xLbp', 'XyZ8MnQrStUvWxYzAbCdEf']}),
  ]);
  $data = json_decode(curl_exec($ch), true);
  ```
</CodeGroup>
