# Get Service Bookings

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

Retrieve service bookings for a location within a given date range, with an optional service location filter.

## Authentication

Send `Authorization: Bearer <token>` using:

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

## Parameters

### Header Parameters

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

### Query Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `locationId` | string | Yes | Location ID |
| `startTime` | string | Yes | Start Time (timestamp in milliseconds as string) |
| `endTime` | string | Yes | End Time (timestamp in milliseconds as string) |
| `timezone` | string | No | Timezone |
| `serviceLocationId` | string | No | Service Location ID |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/calendars/services/bookings": {
      "get": {
        "summary": "Get Service Bookings",
        "operationId": "getServiceBookings",
        "description": "Retrieve service bookings for a location within a given date range, with an optional service location filter.",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          },
          {
            "name": "locationId",
            "required": true,
            "in": "query",
            "description": "Location ID",
            "schema": {
              "example": "0007BWpSzSwfiuSl0tR2",
              "type": "string"
            }
          },
          {
            "name": "startTime",
            "required": true,
            "in": "query",
            "description": "Start Time (timestamp in milliseconds as string)",
            "schema": {
              "example": "1704110400000",
              "type": "string"
            }
          },
          {
            "name": "endTime",
            "required": true,
            "in": "query",
            "description": "End Time (timestamp in milliseconds as string)",
            "schema": {
              "example": "1704114000000",
              "type": "string"
            }
          },
          {
            "name": "timezone",
            "required": false,
            "in": "query",
            "description": "Timezone",
            "schema": {
              "example": "America/New_York",
              "type": "string"
            }
          },
          {
            "name": "serviceLocationId",
            "required": false,
            "in": "query",
            "description": "Service Location ID",
            "schema": {
              "example": "65e5f6dfacf123513228d384",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceBookingsListResponseDTO"
                }
              }
            }
          },
          "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.readonly"
            ]
          }
        ]
      }
    }
  },
  "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": {
      "ServiceBookingsListResponseDTO": {
        "type": "object",
        "properties": {
          "bookings": {
            "description": "Service Bookings",
            "type": "array",
            "items": {
              "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"
                }
              },
              "required": [
                "bookingId",
                "locationId",
                "contactId",
                "serviceLocationId",
                "title",
                "startTime",
                "endTime",
                "services",
                "timezone",
                "status",
                "deleted",
                "dateAdded",
                "dateUpdated",
                "createdBy"
              ],
              "title": "ServiceBookingResponseDTO"
            },
            "example": [
              {
                "bookingId": "7NkT25Vor1v4aQatFsv2",
                "locationId": "0007BWpSzSwfiuSl0tR2",
                "contactId": "9NkT25Vor1v4aQatFsv2",
                "serviceLocationId": "65e5f6dfacf123513228d384",
                "title": "John Doe - Hair Styling",
                "startTime": "2023-09-25T16:00:00+05:30",
                "endTime": "2023-09-25T16:30:00+05:30",
                "timezone": "America/New_York",
                "status": "confirmed",
                "deleted": false
              }
            ]
          }
        },
        "required": [
          "bookings"
        ],
        "title": "ServiceBookingsListResponseDTO"
      },
      "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 GET 'https://services.leadconnectorhq.com/calendars/services/bookings?locationId=<LOCATIONID>&startTime=<STARTTIME>&endTime=<ENDTIME>' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3'
```

**Node.js**

```javascript
const options = {
  method: 'GET',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3'
  }
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/calendars/services/bookings?locationId=<LOCATIONID>&startTime=<STARTTIME>&endTime=<ENDTIME>', 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"
}

params = {
    "locationId": "<LOCATIONID>",
    "startTime": "<STARTTIME>",
    "endTime": "<ENDTIME>"
}

response = requests.get(url, params=params, headers=headers)
print(response.json())
```

**PHP**

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

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/calendars/services/bookings?locationId=<LOCATIONID>&startTime=<STARTTIME>&endTime=<ENDTIME>',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
  ],
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .get("https://services.leadconnectorhq.com/calendars/services/bookings?locationId=<LOCATIONID>&startTime=<STARTTIME>&endTime=<ENDTIME>")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/calendars/services/bookings?locationId=<LOCATIONID>&startTime=<STARTTIME>&endTime=<ENDTIME>"
  req, _ := http.NewRequest("GET", url, nil)
  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?locationId=<LOCATIONID>&startTime=<STARTTIME>&endTime=<ENDTIME>")

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

request = Net::HTTP::Get.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"

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

**PowerShell**

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

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/calendars/services/bookings?locationId=<LOCATIONID>&startTime=<STARTTIME>&endTime=<ENDTIME>' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
```
