# Get Calendar Events

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

Get Calendar Events

## 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 |
| `userId` | string | No | User Id - Owner of an appointment. Either of userId, groupId or calendarId is required |
| `calendarId` | string | No | Either of calendarId, userId or groupId is required |
| `groupId` | string | No | Either of groupId, calendarId or userId is required |
| `startTime` | string | Yes | Start Time (in millis) |
| `endTime` | string | Yes | End Time (in millis) |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/calendars/events": {
      "get": {
        "summary": "Get Calendar Events",
        "operationId": "getCalendarEvents",
        "description": "Get Calendar Events",
        "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": "userId",
            "required": false,
            "in": "query",
            "description": "User Id - Owner of an appointment. Either of userId, groupId or calendarId is required",
            "schema": {
              "example": "CVokAlI8fgw4WYWoCtQz",
              "type": "string"
            }
          },
          {
            "name": "calendarId",
            "required": false,
            "in": "query",
            "description": "Either of calendarId, userId or groupId is required",
            "schema": {
              "example": "BqTwX8QFwXzpegMve9EQ",
              "type": "string"
            }
          },
          {
            "name": "groupId",
            "required": false,
            "in": "query",
            "description": "Either of groupId, calendarId or userId is required",
            "schema": {
              "example": "ocQHyuzHvysMo5N5VsXc",
              "type": "string"
            }
          },
          {
            "name": "startTime",
            "required": true,
            "in": "query",
            "description": "Start Time (in millis)",
            "schema": {
              "example": "1680373800000",
              "type": "string"
            }
          },
          {
            "name": "endTime",
            "required": true,
            "in": "query",
            "description": "End Time (in millis)",
            "schema": {
              "example": "1680978599999",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetCalendarEventsSuccessfulResponseDTO"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "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": {
      "GetCalendarEventsSuccessfulResponseDTO": {
        "type": "object",
        "properties": {
          "events": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "description": "Event Id or Instance id for a recurring event",
                  "examples": [
                    "ocQHyuzHvysMo5N5VsXc",
                    "ocQHyuzHvysMo5N5VsXc_1729821600000_1800"
                  ],
                  "example": "ocQHyuzHvysMo5N5VsXc"
                },
                "address": {
                  "type": "string",
                  "description": "Calendar Event address",
                  "example": "https://meet.google.com/yqp-gogr-wve"
                },
                "title": {
                  "type": "string",
                  "description": "Calendar Event title",
                  "example": "Appointment with Dev team"
                },
                "calendarId": {
                  "type": "string",
                  "description": "Calendar ID",
                  "example": "BqTwX8QFwXzpegMve9EQ"
                },
                "locationId": {
                  "type": "string",
                  "description": "Location ID",
                  "example": "0007BWpSzSwfiuSl0tR2"
                },
                "contactId": {
                  "type": "string",
                  "description": "Contact ID",
                  "example": "9NkT25Vor1v4aQatFsv2"
                },
                "groupId": {
                  "type": "string",
                  "description": "Group ID",
                  "example": "9NkT25Vor1v4aQatFsv2"
                },
                "appointmentStatus": {
                  "type": "string",
                  "description": "Appointment Status",
                  "example": "confirmed"
                },
                "assignedUserId": {
                  "type": "string",
                  "description": "AssignedUser - the primary owner of an appointment",
                  "example": "YlWd2wuCAZQzh2cH1fVZ"
                },
                "users": {
                  "description": "Users - the secondary owners of an appointment.",
                  "example": [
                    "YlWd2wuCAZQzh2cH1fVZ",
                    "9NkT25Vor1v4aQatFsv2"
                  ],
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "notes": {
                  "type": "string",
                  "description": "Notes",
                  "example": "Some dummy note"
                },
                "description": {
                  "type": "string",
                  "description": "Description",
                  "example": "Some dummy description"
                },
                "isRecurring": {
                  "type": "boolean",
                  "description": "true if the event is recurring otherwise false",
                  "example": "true"
                },
                "rrule": {
                  "type": "string",
                  "description": "RRULE as per the iCalendar (RFC 5545) specification for recurring events. DTSTART is not required, instance ids are calculated on the basis of startTime of the event.",
                  "examples": [
                    "RRULE:FREQ=DAILY;INTERVAL=1;COUNT=5",
                    "RRULE:FREQ=DAILY;INTERVAL=1;UNTIL=20210623T043000Z\nEXDATE:20211105T040000Z,20211105T040000Z"
                  ],
                  "example": "RRULE:FREQ=DAILY;INTERVAL=1;COUNT=5"
                },
                "deleted": {
                  "type": "boolean",
                  "description": "Tells if a calendar event has been deleted",
                  "example": false
                },
                "startTime": {
                  "type": "object",
                  "description": "Start Time",
                  "example": "2023-09-25T16:00:00+05:30"
                },
                "endTime": {
                  "type": "object",
                  "description": "End Time",
                  "example": "2023-09-25T16:00:00+05:30"
                },
                "dateAdded": {
                  "type": "object",
                  "description": "Date Added",
                  "example": "2023-09-25T16:00:00+05:30"
                },
                "dateUpdated": {
                  "type": "object",
                  "description": "Date Updated",
                  "example": "2023-09-25T16:00:00+05:30"
                },
                "assignedResources": {
                  "description": "Ids of associated resources rooms and/or equipments",
                  "type": "array",
                  "items": {
                    "type": "string"
                  },
                  "example": [
                    "YlWd2wuCAZQzh2cH1fVZ",
                    "BqTwX5hA2NLRadBMgR6M"
                  ]
                },
                "createdBy": {
                  "description": "Appointment 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": "YlWd2wuCAZQzh2cH1fVZ",
                    "source": "public_api"
                  }
                },
                "masterEventId": {
                  "type": "string",
                  "description": "Master event id for a recurring instance",
                  "example": "ocWd2wuBGAQzh2cH1fSZ"
                },
                "rescheduledAt": {
                  "type": "string",
                  "description": "Timestamp of when the appointment was last rescheduled. Only present for rescheduled appointments.",
                  "format": "date-time",
                  "example": "2023-09-25T16:00:00+05:30"
                }
              },
              "required": [
                "id",
                "title",
                "calendarId",
                "locationId",
                "contactId",
                "groupId",
                "appointmentStatus",
                "assignedUserId",
                "users",
                "startTime",
                "endTime",
                "dateAdded",
                "dateUpdated"
              ],
              "title": "CalendarEventDTO"
            },
            "description": "List of calendar events",
            "example": [
              {
                "id": "ocQHyuzHvysMo5N5VsXc",
                "calendarId": "CVokAlI8fgw4WjWoC3IS",
                "title": "Appointment with John"
              }
            ]
          }
        },
        "title": "GetCalendarEventsSuccessfulResponseDTO"
      },
      "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/events?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/events?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/events"

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/events?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/events?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/events?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/events?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/events?locationId=<LOCATIONID>&startTime=<STARTTIME>&endTime=<ENDTIME>' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
```
