# Create Service Booking

POST https://services.leadconnectorhq.com/calendars/services/bookings

Create a new service booking

## Authentication

Send `Authorization: Bearer <token>` using:

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

## Parameters

### Header Parameters

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

### Query Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `overrideAvailability` | boolean | No | If true the time slot validation would be avoided for any booking creation/update (even the skipSchedulingNotice) |
| `skipSchedulingNotice` | boolean | No | If set to true, the minimum scheduling notice and date range would be ignored |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/calendars/services/bookings": {
      "post": {
        "summary": "Create Service Booking",
        "operationId": "createServiceBooking",
        "description": "Create a new service booking",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          },
          {
            "name": "overrideAvailability",
            "required": false,
            "in": "query",
            "description": "If true the time slot validation would be avoided for any booking creation/update (even the skipSchedulingNotice)",
            "schema": {
              "default": false,
              "example": false,
              "type": "boolean"
            }
          },
          {
            "name": "skipSchedulingNotice",
            "required": false,
            "in": "query",
            "description": "If set to true, the minimum scheduling notice and date range would be ignored",
            "schema": {
              "default": false,
              "example": false,
              "type": "boolean"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreatePublicServiceBookingDTO"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Booking created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateOrUpdateServiceBookingResponseDTO"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                }
              }
            }
          },
          "401": {
            "description": "User not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": [
              "calendars/events.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": {
      "CreatePublicServiceBookingDTO": {
        "type": "object",
        "properties": {
          "locationId": {
            "type": "string",
            "description": "Location ID",
            "example": "0007BWpSzSwfiuSl0tR2"
          },
          "contactId": {
            "type": "string",
            "description": "Contact ID",
            "example": "9NkT25Vor1v4aQatFsv2"
          },
          "startTime": {
            "type": "string",
            "description": "Start Time",
            "example": "2021-06-23T03:30:00+05:30"
          },
          "endTime": {
            "type": "string",
            "description": "End Time",
            "example": "2023-09-25T16:30:00+05:30"
          },
          "timezone": {
            "type": "string",
            "description": "Timezone",
            "example": "America/New_York"
          },
          "services": {
            "description": "Services",
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "description": "Service ID",
                  "example": "a3b4c5d6e7f8901234567890"
                },
                "staffId": {
                  "type": "string",
                  "description": "Staff ID",
                  "example": "8MkU36Wps2w5bRbuGtw3"
                },
                "position": {
                  "type": "number",
                  "description": "Position",
                  "example": 0
                },
                "addOns": {
                  "description": "Add-ons",
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "description": "Add-on ID",
                        "example": "6985f6dfacf123513228d384"
                      },
                      "quantity": {
                        "type": "number",
                        "description": "Add-on quantity",
                        "example": 2
                      },
                      "duration": {
                        "type": "number",
                        "description": "Add-on duration (in minutes)",
                        "example": 30
                      }
                    },
                    "required": [
                      "id"
                    ],
                    "title": "ServiceAddOnDTO"
                  },
                  "example": [
                    {
                      "id": "6985f6dfacf123513228d384"
                    }
                  ]
                }
              },
              "required": [
                "id"
              ],
              "title": "CreateBookingServiceDTO"
            },
            "example": [
              {
                "id": "a3b4c5d6e7f8901234567890",
                "staffId": "8MkU36Wps2w5bRbuGtw3"
              }
            ]
          },
          "serviceLocationId": {
            "type": "string",
            "description": "Service Location ID (If not provided, then the default service location will be used)",
            "example": "65e5f6dfacf123513228d384"
          },
          "meetingLocation": {
            "type": "string",
            "description": "Meeting Location (If service location is an ask the booker, then the meeting location is required)",
            "example": "123 Main St, Anytown, USA"
          },
          "title": {
            "type": "string",
            "description": "Service Booking Title",
            "example": "Service Appointment"
          },
          "status": {
            "type": "string",
            "description": "Status. (If not provided, the status configured in Service Global Settings will be used.)",
            "example": "confirmed",
            "enum": [
              "confirmed",
              "new"
            ]
          }
        },
        "required": [
          "locationId",
          "contactId",
          "startTime",
          "endTime",
          "timezone",
          "services"
        ],
        "title": "CreatePublicServiceBookingDTO"
      },
      "CreateOrUpdateServiceBookingResponseDTO": {
        "type": "object",
        "properties": {
          "bookingId": {
            "type": "string",
            "description": "Booking ID",
            "example": "7NkT25Vor1v4aQatFsv2"
          },
          "locationId": {
            "type": "string",
            "description": "Location ID",
            "example": "0007BWpSzSwfiuSl0tR2"
          },
          "contactId": {
            "type": "string",
            "description": "Contact ID",
            "example": "9NkT25Vor1v4aQatFsv2"
          },
          "serviceLocationId": {
            "type": "string",
            "description": "Service Location ID",
            "example": "65e5f6dfacf123513228d384"
          },
          "title": {
            "type": "string",
            "description": "Service Booking Title",
            "example": "John Doe - Hair Styling"
          },
          "startTime": {
            "type": "string",
            "description": "Start Time",
            "example": "2023-09-25T16:00:00+05:30"
          },
          "endTime": {
            "type": "string",
            "description": "End Time",
            "example": "2023-09-25T16:30:00+05:30"
          },
          "services": {
            "description": "Services",
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "description": "Service ID",
                  "example": "68e5f6dfacf123513228d384"
                },
                "serviceCategoryId": {
                  "type": "string",
                  "description": "Service Category ID",
                  "example": "3c4d5e6f7890123456789abc"
                },
                "serviceStaffId": {
                  "type": "string",
                  "description": "Service Staff ID",
                  "example": "7NkT25Vor1v4aQatFsv2"
                },
                "serviceStartTime": {
                  "type": "string",
                  "description": "Service Start Time",
                  "example": "2023-09-25T16:00:00+05:30"
                },
                "serviceEndTime": {
                  "type": "string",
                  "description": "Service End Time",
                  "example": "2023-09-25T16:30:00+05:30"
                },
                "serviceResources": {
                  "description": "Service Resources",
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "description": "Resource ID",
                        "example": "6985f6dfacf123513228d384"
                      }
                    },
                    "required": [
                      "id"
                    ],
                    "title": "ServiceResourceDTO"
                  },
                  "example": [
                    {
                      "id": "6985f6dfacf123513228d384"
                    }
                  ]
                },
                "serviceAddOns": {
                  "description": "Service Add-ons",
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "description": "Add-on ID",
                        "example": "6985f6dfacf123513228d384"
                      },
                      "quantity": {
                        "type": "number",
                        "description": "Add-on quantity",
                        "example": 2
                      }
                    },
                    "required": [
                      "id"
                    ],
                    "title": "ServiceAddOnResponseDTO"
                  },
                  "example": [
                    {
                      "id": "6985f6dfacf123513228d384"
                    }
                  ]
                }
              },
              "required": [
                "id",
                "serviceCategoryId",
                "serviceStaffId",
                "serviceStartTime",
                "serviceEndTime"
              ],
              "title": "ServiceDTO"
            },
            "example": [
              {
                "id": "68e5f6dfacf123513228d384",
                "serviceCategoryId": "3c4d5e6f7890123456789abc",
                "serviceStaffId": "7NkT25Vor1v4aQatFsv2",
                "serviceStartTime": "2023-09-25T16:00:00+05:30",
                "serviceEndTime": "2023-09-25T16:30:00+05:30"
              }
            ]
          },
          "timezone": {
            "type": "string",
            "description": "Timezone",
            "example": "America/New_York"
          },
          "status": {
            "type": "string",
            "description": "Status",
            "example": "confirmed"
          },
          "deleted": {
            "type": "boolean",
            "description": "Tells if the booking is deleted",
            "example": false
          },
          "dateAdded": {
            "type": "string",
            "description": "Date Added",
            "example": "2023-09-25T16:00:00+05:30"
          },
          "dateUpdated": {
            "type": "string",
            "description": "Date Updated",
            "example": "2023-09-25T16:00:00+05:30"
          },
          "createdBy": {
            "description": "Booking booked by metadata",
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "userId": {
                    "type": "string",
                    "description": "The ID of the user who created or updated the appointment",
                    "example": "7NkT25Vor1v4aQatFsv2"
                  },
                  "source": {
                    "type": "string",
                    "description": "The source of the appointment",
                    "example": "public_api"
                  }
                },
                "required": [
                  "source"
                ],
                "title": "CreatedOrUpdatedBy"
              }
            ],
            "example": {
              "userId": "7NkT25Vor1v4aQatFsv2",
              "source": "public_api"
            }
          },
          "meetingLocation": {
            "type": "string",
            "description": "Meeting Location (If service location is an ask the booker, then the meeting location is used for the booking)",
            "example": "123 Main St, Anytown, USA"
          },
          "messages": {
            "description": "Optional informative or warning messages (e.g. meeting location ignored for non-ask-booker locations)",
            "example": [
              "Meeting location is not supported for the selected service location and has been ignored."
            ],
            "items": {
              "type": "array"
            },
            "type": "array"
          }
        },
        "required": [
          "bookingId",
          "locationId",
          "contactId",
          "serviceLocationId",
          "title",
          "startTime",
          "endTime",
          "services",
          "timezone",
          "status",
          "deleted",
          "dateAdded",
          "dateUpdated",
          "createdBy"
        ],
        "title": "CreateOrUpdateServiceBookingResponseDTO"
      },
      "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"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X POST 'https://services.leadconnectorhq.com/calendars/services/bookings' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "locationId": "0007BWpSzSwfiuSl0tR2",
  "contactId": "9NkT25Vor1v4aQatFsv2",
  "startTime": "2021-06-23T03:30:00+05:30",
  "endTime": "2023-09-25T16:30:00+05:30",
  "timezone": "America/New_York",
  "services": [
    {
      "id": "a3b4c5d6e7f8901234567890",
      "staffId": "8MkU36Wps2w5bRbuGtw3"
    }
  ],
  "serviceLocationId": "65e5f6dfacf123513228d384",
  "meetingLocation": "123 Main St, Anytown, USA",
  "title": "Service Appointment",
  "status": "confirmed"
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "locationId": "0007BWpSzSwfiuSl0tR2",
      "contactId": "9NkT25Vor1v4aQatFsv2",
      "startTime": "2021-06-23T03:30:00+05:30",
      "endTime": "2023-09-25T16:30:00+05:30",
      "timezone": "America/New_York",
      "services": [
        {
          "id": "a3b4c5d6e7f8901234567890",
          "staffId": "8MkU36Wps2w5bRbuGtw3"
        }
      ],
      "serviceLocationId": "65e5f6dfacf123513228d384",
      "meetingLocation": "123 Main St, Anytown, USA",
      "title": "Service Appointment",
      "status": "confirmed"
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/calendars/services/bookings', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/calendars/services/bookings"

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

payload = {
    "locationId": "0007BWpSzSwfiuSl0tR2",
    "contactId": "9NkT25Vor1v4aQatFsv2",
    "startTime": "2021-06-23T03:30:00+05:30",
    "endTime": "2023-09-25T16:30:00+05:30",
    "timezone": "America/New_York",
    "services": [
        {
            "id": "a3b4c5d6e7f8901234567890",
            "staffId": "8MkU36Wps2w5bRbuGtw3"
        }
    ],
    "serviceLocationId": "65e5f6dfacf123513228d384",
    "meetingLocation": "123 Main St, Anytown, USA",
    "title": "Service Appointment",
    "status": "confirmed"
}

response = requests.post(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/services/bookings',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "locationId": "0007BWpSzSwfiuSl0tR2",
  "contactId": "9NkT25Vor1v4aQatFsv2",
  "startTime": "2021-06-23T03:30:00+05:30",
  "endTime": "2023-09-25T16:30:00+05:30",
  "timezone": "America/New_York",
  "services": [
    {
      "id": "a3b4c5d6e7f8901234567890",
      "staffId": "8MkU36Wps2w5bRbuGtw3"
    }
  ],
  "serviceLocationId": "65e5f6dfacf123513228d384",
  "meetingLocation": "123 Main St, Anytown, USA",
  "title": "Service Appointment",
  "status": "confirmed"
}',
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .post("https://services.leadconnectorhq.com/calendars/services/bookings")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"locationId\":\"0007BWpSzSwfiuSl0tR2\",\"contactId\":\"9NkT25Vor1v4aQatFsv2\",\"startTime\":\"2021-06-23T03:30:00+05:30\",\"endTime\":\"2023-09-25T16:30:00+05:30\",\"timezone\":\"America/New_York\",\"services\":[{\"id\":\"a3b4c5d6e7f8901234567890\",\"staffId\":\"8MkU36Wps2w5bRbuGtw3\"}],\"serviceLocationId\":\"65e5f6dfacf123513228d384\",\"meetingLocation\":\"123 Main St, Anytown, USA\",\"title\":\"Service Appointment\",\"status\":\"confirmed\"}")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/calendars/services/bookings"
  payload := strings.NewReader(`{
  "locationId": "0007BWpSzSwfiuSl0tR2",
  "contactId": "9NkT25Vor1v4aQatFsv2",
  "startTime": "2021-06-23T03:30:00+05:30",
  "endTime": "2023-09-25T16:30:00+05:30",
  "timezone": "America/New_York",
  "services": [
    {
      "id": "a3b4c5d6e7f8901234567890",
      "staffId": "8MkU36Wps2w5bRbuGtw3"
    }
  ],
  "serviceLocationId": "65e5f6dfacf123513228d384",
  "meetingLocation": "123 Main St, Anytown, USA",
  "title": "Service Appointment",
  "status": "confirmed"
}`)
  req, _ := http.NewRequest("POST", 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/services/bookings")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"
request["Content-Type"] = "application/json"
request.body = '{
  "locationId": "0007BWpSzSwfiuSl0tR2",
  "contactId": "9NkT25Vor1v4aQatFsv2",
  "startTime": "2021-06-23T03:30:00+05:30",
  "endTime": "2023-09-25T16:30:00+05:30",
  "timezone": "America/New_York",
  "services": [
    {
      "id": "a3b4c5d6e7f8901234567890",
      "staffId": "8MkU36Wps2w5bRbuGtw3"
    }
  ],
  "serviceLocationId": "65e5f6dfacf123513228d384",
  "meetingLocation": "123 Main St, Anytown, USA",
  "title": "Service Appointment",
  "status": "confirmed"
}'

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

**PowerShell**

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

$body = '{
  "locationId": "0007BWpSzSwfiuSl0tR2",
  "contactId": "9NkT25Vor1v4aQatFsv2",
  "startTime": "2021-06-23T03:30:00+05:30",
  "endTime": "2023-09-25T16:30:00+05:30",
  "timezone": "America/New_York",
  "services": [
    {
      "id": "a3b4c5d6e7f8901234567890",
      "staffId": "8MkU36Wps2w5bRbuGtw3"
    }
  ],
  "serviceLocationId": "65e5f6dfacf123513228d384",
  "meetingLocation": "123 Main St, Anytown, USA",
  "title": "Service Appointment",
  "status": "confirmed"
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/calendars/services/bookings' -Method 'POST' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
